From: Alexey Gladkov Date: Tue, 14 Dec 2010 23:14:18 +0000 (+0300) Subject: swapon: Canonicalize swap device X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b98ff23e879826d0b041a18ca1090428748b9ef3;p=util-linux 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 --- 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;