]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
eject: use canonicalize_path to treat symbolic links
authorMichal Luscon <mluscon@redhat.com>
Wed, 8 Feb 2012 15:01:51 +0000 (16:01 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 27 Mar 2012 11:04:58 +0000 (13:04 +0200)
Signed-off-by: Michal Luscon <mluscon@redhat.com>
misc-utils/Makefile.am
misc-utils/eject.c

index 9ff7a129bec1a40df0f47e0471224d01ff6e04fc..42278143c0776551ab045454cdd228b0b163074a 100644 (file)
@@ -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
 
 
index c685c428695f70cc088ea38e08134c1ba0f0884a..974e566aa288d528cc8695ab38d2524c8c282d2f 100644 (file)
@@ -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);