summaryrefslogtreecommitdiffstats
path: root/mount/swapon.c
diff options
context:
space:
mode:
authorAlexey Gladkov2010-12-15 00:14:18 +0100
committerKarel Zak2010-12-17 00:44:40 +0100
commitb98ff23e879826d0b041a18ca1090428748b9ef3 (patch)
treeeffc71019581a1861850b43d1100e023ffcac4d9 /mount/swapon.c
parentlsblk: add --nodeps (diff)
downloadkernel-qcow2-util-linux-b98ff23e879826d0b041a18ca1090428748b9ef3.tar.gz
kernel-qcow2-util-linux-b98ff23e879826d0b041a18ca1090428748b9ef3.tar.xz
kernel-qcow2-util-linux-b98ff23e879826d0b041a18ca1090428748b9ef3.zip
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 <gladkov.alexey@gmail.com> Tested-by: Petr Uzel <petr.uzel@suse.cz> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'mount/swapon.c')
-rw-r--r--mount/swapon.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/mount/swapon.c b/mount/swapon.c
index a2dd9dc26..812884711 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;