From: Michal Luscon Date: Wed, 8 Feb 2012 15:01:51 +0000 (+0100) Subject: eject: use canonicalize_path to treat symbolic links X-Git-Tag: v2.22-rc1~555^2~39 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6d45c65d076ef9c5fc7295c9dcc9051519eb21f9;p=thirdparty%2Futil-linux.git eject: use canonicalize_path to treat symbolic links Signed-off-by: Michal Luscon --- diff --git a/misc-utils/Makefile.am b/misc-utils/Makefile.am index 9ff7a129be..42278143c0 100644 --- a/misc-utils/Makefile.am +++ b/misc-utils/Makefile.am @@ -34,7 +34,8 @@ namei_SOURCES = namei.c $(top_srcdir)/lib/strutils.c usrbin_exec_PROGRAMS += eject -eject_SOURCES = eject.c $(top_srcdir)/lib/strutils.c +eject_SOURCES = eject.c $(top_srcdir)/lib/strutils.c \ + $(top_srcdir)/lib/canonicalize.c dist_man_MANS += eject.1 diff --git a/misc-utils/eject.c b/misc-utils/eject.c index c685c42869..974e566aa2 100644 --- a/misc-utils/eject.c +++ b/misc-utils/eject.c @@ -34,6 +34,7 @@ #include "nls.h" #include "strutils.h" #include "xalloc.h" +#include "canonicalize.h" #define EJECT_DEFAULT_DEVICE "/dev/cdrom" @@ -759,43 +760,6 @@ static void UnmountDevices(const char *pattern) e_fclose(fp); } - -/* 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); - } - } - realpath(result, s4); - return strdup(s4); -} - - /* * Given a name, see if it matches a pattern for a device that can have * multiple partitions. If so, return a regular expression that matches @@ -910,7 +874,7 @@ int main(int argc, char **argv) printf(_("%s: expanded name is `%s'\n"), programName, fullName); /* check for a symbolic link */ - while ((linkName = SymLink(fullName)) && (ld > 0)) { + while ((linkName = canonicalize_path(fullName)) && (ld > 0)) { if (v_option) printf(_("%s: `%s' is a link to `%s'\n"), programName, fullName, linkName); free(fullName);