From 730152d980a6ed5a94702b9ed73b4664722773d5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pawe=C5=82=20Sikora?= Date: Sun, 31 Oct 2004 04:11:54 +0000 Subject: [PATCH] - this patch fixes symlink resolver. Changed files: eject-symlink.patch -> 1.1 --- eject-symlink.patch | 119 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 eject-symlink.patch diff --git a/eject-symlink.patch b/eject-symlink.patch new file mode 100644 index 0000000..0c3dc27 --- /dev/null +++ b/eject-symlink.patch @@ -0,0 +1,119 @@ + testcase: + + symlink: /mnt/cdrom -> /media/cdrom/ + ^ this is important ! + +[ without fix ] + +./eject: using default device `cdrom' +./eject: device name is `cdrom' +./eject: expanded name is `/mnt/cdrom' +./eject: `/mnt/cdrom' is a link to `/media/cdrom/' +./eject: `/media/cdrom/' is not mounted +./eject: `/media/cdrom/' is not a mount point +./eject: `/media/cdrom/' is not a multipartition device +./eject: trying to eject `/media/cdrom/' using CD-ROM eject command +./eject: CD-ROM eject command failed +./eject: trying to eject `/media/cdrom/' using SCSI commands +./eject: SCSI eject failed +./eject: trying to eject `/media/cdrom/' using floppy eject command +./eject: floppy eject command failed +./eject: trying to eject `/media/cdrom/' using tape offline command +./eject: tape offline command failed + +./eject: unable to eject, last error: Inappropriate ioctl for device + + +[ with fix ] + +./eject: using default device `cdrom' +./eject: device name is `cdrom' +./eject: expanded name is `/mnt/cdrom' +./eject: `/mnt/cdrom' is a link to `/media/cdrom' +./eject: `/media/cdrom' is not mounted +./eject: `/dev/hdc' can be mounted at `/media/cdrom' +./eject: `/dev/hdc' is a multipartition device +./eject: trying to eject `/dev/hdc' using CD-ROM eject command +./eject: CD-ROM eject command succeeded + + +--- eject-2.0.13/eject.c.orig 2002-12-09 23:28:08.000000000 +0100 ++++ eject-2.0.13/eject.c 2004-10-31 04:56:31.794216376 +0100 +@@ -715,36 +715,13 @@ + /* Check if name is a symbolic link. If so, return what it points to. */ + static char *SymLink(const char *name) + { +- int status; +- char s1[PATH_MAX]; +- char s2[PATH_MAX]; +- char s4[PATH_MAX]; + char result[PATH_MAX]; +- char *s3; +- +- memset(s1, 0, sizeof(s1)); +- memset(s2, 0, sizeof(s2)); +- memset(s4, 0, sizeof(s4)); +- memset(result, 0, sizeof(result)); +- +- status = readlink(name, s1, sizeof(s1) - 1); +- +- if (status == -1) +- return 0; +- +- s1[status] = 0; +- if (s1[0] == '/') { /* absolute link */ +- return strdup(s1); +- } else { /* relative link, add base name */ +- strncpy(s2, name, sizeof(s2)-1); +- s3 = strrchr(s2, '/'); +- if (s3 != 0) { +- s3[1] = 0; +- snprintf(result, sizeof(result)-1, "%s%s", s2, s1); +- } ++ if (realpath(name, result) == NULL) ++ { ++ puts(_(strerror(errno))); ++ exit(1); + } +- realpath(result, s4); +- return strdup(s4); ++ return strdup(result); + } + + +@@ -818,7 +795,6 @@ + int mounted = 0; /* true if device is mounted */ + int mountable = 0; /* true if device is in /etc/fstab */ + char *pattern; /* regex for device if multiple partitions */ +- int ld = 6; /* symbolic link max depth */ + + I18NCODE + +@@ -860,20 +836,13 @@ + printf(_("%s: expanded name is `%s'\n"), programName, fullName); + + /* check for a symbolic link */ +- while ((linkName = SymLink(fullName)) && (ld > 0)) { +- if (v_option) +- printf(_("%s: `%s' is a link to `%s'\n"), programName, fullName, linkName); +- free(fullName); +- fullName = strdup(linkName); +- free(linkName); +- linkName = 0; +- ld--; +- } +- /* handle max depth exceeded option */ +- if (ld <= 0) { +- printf(_("%s: maximum symbolic link depth exceeded: `%s'\n"), programName, fullName); +- exit(1); +- } ++ linkName = SymLink(fullName); ++ if (v_option) ++ printf(_("%s: `%s' is a link to `%s'\n"), programName, fullName, linkName); ++ free(fullName); ++ fullName = strdup(linkName); ++ free(linkName); ++ linkName = 0; + + /* if mount point, get device name */ + mounted = MountedDevice(fullName, &mountName, &deviceName); -- 2.44.0