summaryrefslogtreecommitdiffstats
path: root/sys-apps/util-linux/files/util-linux-2.12p-swapon-check-symlinks.patch
blob: f421458049f1d15044360457d95b88a656400084 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
--- util-linux-2.12b/mount/swapon.c
+++ util-linux-2.12b/mount/swapon.c
@@ -7,2 +7,3 @@
 #include <stdlib.h>
+#include <sys/param.h>
 #include <stdio.h>
@@ -137,10 +138,27 @@
 static int
 is_in_proc_swaps(const char *fname) {
 	int i;
+	struct stat fstatbuf;
 
 	for (i = 0; i < numSwaps; i++)
 		if (swapFiles[i] && !strcmp(fname, swapFiles[i]))
 			return 1;
+
+	/* fallback:
+	 * if the device in /etc/fstab is a symlink, the entry
+	 * in /proc/swaps won't match because the kernel stores
+	 * absolute pathnames.  Here we compare dev_t's.
+	 */
+	if (!lstat(fname, &fstatbuf))
+		if (S_ISLNK(fstatbuf.st_mode)) {
+			struct stat swapstatbuf;
+			stat(fname, &fstatbuf);
+			for (i = 0; i < numSwaps; i++)
+				if (swapFiles[i] && !stat(swapFiles[i], &swapstatbuf) && \
+				    swapstatbuf.st_rdev == fstatbuf.st_rdev)
+					return 1;
+		}
+
 	return 0;
 }