From b98ff23e879826d0b041a18ca1090428748b9ef3 Mon Sep 17 00:00:00 2001 From: Alexey Gladkov Date: Wed, 15 Dec 2010 02:14:18 +0300 Subject: [PATCH] swapon: Canonicalize swap device Swapon checks whether a swap device is active by searching for the device name in /proc/swaps. /proc/swaps always specifies the path to real device file, even if the path to real device file, even if symlink was passed to the swapon() system call. This differs from /proc/mounts semantics where each string contains exactly the same device name as it was passed to the mount*() system call. If a swap partition resides on lvm, libblkid returns a name in form /dev/mapper/*, but now there are symlinks pointing to device files /dev/dm-*, resulting to /proc/swaps containing /dev/dm-*, but swapon still looks for /dev/mapper/* and tries to activate the swap partition again. [kzak@redhat.com: - remove unnecessary changes from is_in_proc_swaps()] Signed-off-by: Alexey Gladkov Tested-by: Petr Uzel Signed-off-by: Karel Zak --- mount/swapon.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mount/swapon.c b/mount/swapon.c index a2dd9dc2..81288471 100644 --- a/mount/swapon.c +++ b/mount/swapon.c @@ -23,6 +23,7 @@ #include "pathnames.h" #include "swapheader.h" #include "mangle.h" +#include "canonicalize.h" #define PATH_MKSWAP "/sbin/mkswap" @@ -177,11 +178,16 @@ read_proc_swaps(void) { break; swapFiles = q; - swapFiles[numSwaps++] = unmangle(line); + if ((p = unmangle(line)) == NULL) + break; + + swapFiles[numSwaps++] = canonicalize_path(p); + free(p); } fclose(swaps); } +/* note that swapFiles are always canonicalized */ static int is_in_proc_swaps(const char *fname) { int i; -- 2.39.5