]>
Commit | Line | Data |
---|---|---|
730152d9 PS |
1 | testcase: |
2 | ||
3 | symlink: /mnt/cdrom -> /media/cdrom/ | |
4 | ^ this is important ! | |
5 | ||
6 | [ without fix ] | |
7 | ||
8 | ./eject: using default device `cdrom' | |
9 | ./eject: device name is `cdrom' | |
10 | ./eject: expanded name is `/mnt/cdrom' | |
11 | ./eject: `/mnt/cdrom' is a link to `/media/cdrom/' | |
12 | ./eject: `/media/cdrom/' is not mounted | |
13 | ./eject: `/media/cdrom/' is not a mount point | |
14 | ./eject: `/media/cdrom/' is not a multipartition device | |
15 | ./eject: trying to eject `/media/cdrom/' using CD-ROM eject command | |
16 | ./eject: CD-ROM eject command failed | |
17 | ./eject: trying to eject `/media/cdrom/' using SCSI commands | |
18 | ./eject: SCSI eject failed | |
19 | ./eject: trying to eject `/media/cdrom/' using floppy eject command | |
20 | ./eject: floppy eject command failed | |
21 | ./eject: trying to eject `/media/cdrom/' using tape offline command | |
22 | ./eject: tape offline command failed | |
23 | ||
24 | ./eject: unable to eject, last error: Inappropriate ioctl for device | |
25 | ||
26 | ||
27 | [ with fix ] | |
28 | ||
29 | ./eject: using default device `cdrom' | |
30 | ./eject: device name is `cdrom' | |
31 | ./eject: expanded name is `/mnt/cdrom' | |
32 | ./eject: `/mnt/cdrom' is a link to `/media/cdrom' | |
33 | ./eject: `/media/cdrom' is not mounted | |
34 | ./eject: `/dev/hdc' can be mounted at `/media/cdrom' | |
35 | ./eject: `/dev/hdc' is a multipartition device | |
36 | ./eject: trying to eject `/dev/hdc' using CD-ROM eject command | |
37 | ./eject: CD-ROM eject command succeeded | |
38 | ||
39 | ||
40 | --- eject-2.0.13/eject.c.orig 2002-12-09 23:28:08.000000000 +0100 | |
41 | +++ eject-2.0.13/eject.c 2004-10-31 04:56:31.794216376 +0100 | |
42 | @@ -715,36 +715,13 @@ | |
43 | /* Check if name is a symbolic link. If so, return what it points to. */ | |
44 | static char *SymLink(const char *name) | |
45 | { | |
46 | - int status; | |
47 | - char s1[PATH_MAX]; | |
48 | - char s2[PATH_MAX]; | |
49 | - char s4[PATH_MAX]; | |
50 | char result[PATH_MAX]; | |
51 | - char *s3; | |
52 | - | |
53 | - memset(s1, 0, sizeof(s1)); | |
54 | - memset(s2, 0, sizeof(s2)); | |
55 | - memset(s4, 0, sizeof(s4)); | |
56 | - memset(result, 0, sizeof(result)); | |
57 | - | |
58 | - status = readlink(name, s1, sizeof(s1) - 1); | |
59 | - | |
60 | - if (status == -1) | |
61 | - return 0; | |
62 | - | |
63 | - s1[status] = 0; | |
64 | - if (s1[0] == '/') { /* absolute link */ | |
65 | - return strdup(s1); | |
66 | - } else { /* relative link, add base name */ | |
67 | - strncpy(s2, name, sizeof(s2)-1); | |
68 | - s3 = strrchr(s2, '/'); | |
69 | - if (s3 != 0) { | |
70 | - s3[1] = 0; | |
71 | - snprintf(result, sizeof(result)-1, "%s%s", s2, s1); | |
72 | - } | |
73 | + if (realpath(name, result) == NULL) | |
74 | + { | |
75 | + puts(_(strerror(errno))); | |
76 | + exit(1); | |
77 | } | |
78 | - realpath(result, s4); | |
79 | - return strdup(s4); | |
80 | + return strdup(result); | |
81 | } | |
82 | ||
83 | ||
84 | @@ -818,7 +795,6 @@ | |
85 | int mounted = 0; /* true if device is mounted */ | |
86 | int mountable = 0; /* true if device is in /etc/fstab */ | |
87 | char *pattern; /* regex for device if multiple partitions */ | |
88 | - int ld = 6; /* symbolic link max depth */ | |
89 | ||
90 | I18NCODE | |
91 | ||
92 | @@ -860,20 +836,13 @@ | |
93 | printf(_("%s: expanded name is `%s'\n"), programName, fullName); | |
94 | ||
95 | /* check for a symbolic link */ | |
96 | - while ((linkName = SymLink(fullName)) && (ld > 0)) { | |
97 | - if (v_option) | |
98 | - printf(_("%s: `%s' is a link to `%s'\n"), programName, fullName, linkName); | |
99 | - free(fullName); | |
100 | - fullName = strdup(linkName); | |
101 | - free(linkName); | |
102 | - linkName = 0; | |
103 | - ld--; | |
104 | - } | |
105 | - /* handle max depth exceeded option */ | |
106 | - if (ld <= 0) { | |
107 | - printf(_("%s: maximum symbolic link depth exceeded: `%s'\n"), programName, fullName); | |
108 | - exit(1); | |
109 | - } | |
110 | + linkName = SymLink(fullName); | |
111 | + if (v_option) | |
112 | + printf(_("%s: `%s' is a link to `%s'\n"), programName, fullName, linkName); | |
113 | + free(fullName); | |
114 | + fullName = strdup(linkName); | |
115 | + free(linkName); | |
116 | + linkName = 0; | |
117 | ||
118 | /* if mount point, get device name */ | |
119 | mounted = MountedDevice(fullName, &mountName, &deviceName); |