]> err.no Git - util-linux/commitdiff
swapon: does not correctly deal with symlinks
authorKarel Zak <kzak@redhat.com>
Fri, 9 Feb 2007 16:15:39 +0000 (17:15 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 9 Feb 2007 16:15:39 +0000 (17:15 +0100)
From: Marco d'Itri <md@Linux.IT>
Signed-off-by: Karel Zak <kzak@redhat.com>
mount/Makefile.am
mount/swapon.c

index 951fd40511b6d9b9aa8a959f3c4edc90d1c4c5bd..605c4520c8997754f12ef33ed8216e358343aa52 100644 (file)
@@ -32,7 +32,7 @@ umount_LDADD = $(top_srcdir)/lib/libenv.a
 
 swapon_SOURCES = swapon.c xmalloc.c \
        get_label_uuid.c mount_by_label.c mount_blkid.c \
-       swap_constants.h
+       swap_constants.h realpath.c
 
 losetup_SOURCES = lomount.c loop.h lomount.h
 losetup_CFLAGS = -DMAIN
index 524547a91840a1301c1cc53c7b1a77b24e2d0948..ef8dcee90a146a04aa883547d6d23623ce3b3c99 100644 (file)
 #include "nls.h"
 #include "mount_blkid.h"
 #include "mount_by_label.h"
+#include "realpath.h"
+
+#include <limits.h>             /* for PATH_MAX */
+#ifndef PATH_MAX
+#define PATH_MAX 8192
+#endif
 
 #define streq(s, t)    (strcmp ((s), (t)) == 0)
 
@@ -136,9 +142,17 @@ read_proc_swaps(void) {
 static int
 is_in_proc_swaps(const char *fname) {
        int i;
+       char canonical[PATH_MAX + 2];
+
+       if (!myrealpath(fname, canonical, PATH_MAX + 1)) {
+               fprintf(stderr, _("%s: cannot canonicalize %s: %s\n"),
+                       progname, fname, strerror(errno));
+               strncpy(canonical, fname, PATH_MAX + 1);
+               *(canonical + (PATH_MAX + 1)) = '\0';
+       }
 
        for (i = 0; i < numSwaps; i++)
-               if (swapFiles[i] && !strcmp(fname, swapFiles[i]))
+               if (swapFiles[i] && !strcmp(canonical, swapFiles[i]))
                        return 1;
        return 0;
 }