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/eject.c.orig 2006-02-11 02:54:38.000000000 +0100 +++ eject/eject.c 2006-09-10 11:39:58.826171000 +0200 @@ -974,36 +974,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); } @@ -1086,7 +1063,6 @@ int mountable = 0; /* true if device is in /etc/fstab */ int result = 0; /* store the result of a operation */ char *pattern; /* regex for device if multiple partitions */ - int ld = 6; /* symbolic link max depth */ I18NCODE @@ -1134,21 +1110,13 @@ fullNameOrig = strdup(fullName); linkName = strdup(fullName); /* ensure linkName is initialized */ if (!p_option) { - 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 = NULL; } /* if mount point, get device name */