summaryrefslogtreecommitdiffstats
path: root/mount/swapon.c
diff options
context:
space:
mode:
authorKarel Zak2007-02-09 17:15:39 +0100
committerKarel Zak2007-02-09 17:15:39 +0100
commit167eaed7836b456b7bedf38be4124a8fa27ccb69 (patch)
treee80c0c51302b97df814bfa42d613a5f12e0f0d82 /mount/swapon.c
parentmkswap: automatically add selinux label to swapfile (diff)
downloadkernel-qcow2-util-linux-167eaed7836b456b7bedf38be4124a8fa27ccb69.tar.gz
kernel-qcow2-util-linux-167eaed7836b456b7bedf38be4124a8fa27ccb69.tar.xz
kernel-qcow2-util-linux-167eaed7836b456b7bedf38be4124a8fa27ccb69.zip
swapon: does not correctly deal with symlinks
From: Marco d'Itri <md@Linux.IT> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'mount/swapon.c')
-rw-r--r--mount/swapon.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/mount/swapon.c b/mount/swapon.c
index 524547a91..ef8dcee90 100644
--- a/mount/swapon.c
+++ b/mount/swapon.c
@@ -17,6 +17,12 @@
#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;
}