]>
Commit | Line | Data |
---|---|---|
38fa6f00 MT |
1 | diff --git a/eject.c b/eject.c |
2 | index 79fd01b..d67089c 100644 | |
3 | --- a/eject.c | |
4 | +++ b/eject.c | |
5 | @@ -543,10 +543,11 @@ static void ToggleTray(int fd) | |
6 | ||
7 | #ifdef CDROMCLOSETRAY | |
8 | ||
9 | - /* Try to open the CDROM tray and measure the time therefor | |
10 | - * needed. In my experience the function needs less than 0.05 | |
11 | + /* Try to open the CDROM tray and measure the time needed. | |
12 | + * In my experience the function needs less than 0.05 | |
13 | * seconds if the tray was already open, and at least 1.5 seconds | |
14 | - * if it was closed. */ | |
15 | + * if it was closed. | |
16 | + */ | |
17 | gettimeofday(&time_start, NULL); | |
18 | ||
19 | /* Send the CDROMEJECT command to the device. */ | |
20 | @@ -815,10 +816,17 @@ static void Unmount(const char *fullName) | |
21 | } | |
22 | ||
23 | ||
24 | -/* Open a device file. */ | |
25 | +/* Open a device file. Try opening first read/write, and if that fails then read only. */ | |
26 | static int OpenDevice(const char *fullName) | |
27 | { | |
28 | - int fd = open(fullName, O_RDONLY|O_NONBLOCK); | |
29 | + int fd; | |
30 | + | |
31 | + fd = open(fullName, O_RDWR|O_NONBLOCK); | |
32 | + if (fd != -1) { | |
33 | + return fd; | |
34 | + } | |
35 | + | |
36 | + fd = open(fullName, O_RDONLY|O_NONBLOCK); | |
37 | if (fd == -1) { | |
38 | fprintf(stderr, _("%s: unable to open `%s'\n"), programName, fullName); | |
39 | exit(1); |