[PATCH v2] swapon: Canonicalize swap device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

Signed-off-by: Alexey Gladkov <gladkov.alexey@xxxxxxxxx>
Tested-by: Petr Uzel <petr.uzel@xxxxxxx>
---
 mount/swapon.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/mount/swapon.c b/mount/swapon.c
index a2dd9dc..879d2e9 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,7 +178,11 @@ 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);
 }
@@ -185,10 +190,14 @@ read_proc_swaps(void) {
 static int
 is_in_proc_swaps(const char *fname) {
 	int i;
+	char *p = canonicalize_path(fname);
 
 	for (i = 0; i < numSwaps; i++)
-		if (swapFiles[i] && !strcmp(fname, swapFiles[i]))
+		if (swapFiles[i] && !strcmp(p, swapFiles[i])) {
+			free(p);
 			return 1;
+		}
+	free(p);
 	return 0;
 }
 
-- 
1.7.3.2


--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux