summaryrefslogtreecommitdiffstats
path: root/mount/swapon.c
diff options
context:
space:
mode:
authorMike Frysinger2009-10-13 12:05:19 +0200
committerKarel Zak2009-10-13 14:03:46 +0200
commitd08cd85fad8b6a3e2aaaeac61afb0e19564ac7d7 (patch)
treeae0c8ac26d444edfce46b1dcae03c1f16a7594aa /mount/swapon.c
parenthwclock: do not access hardware clock when using --systz (diff)
downloadkernel-qcow2-util-linux-d08cd85fad8b6a3e2aaaeac61afb0e19564ac7d7.tar.gz
kernel-qcow2-util-linux-d08cd85fad8b6a3e2aaaeac61afb0e19564ac7d7.tar.xz
kernel-qcow2-util-linux-d08cd85fad8b6a3e2aaaeac61afb0e19564ac7d7.zip
swapon: handle <=linux-2.6.19 bug in /proc/swaps
Linux <=2.6.19 contained a bug in the /proc/swaps code where the header would not be displayed (the first line). Most people report the issue as a sequence of swapon/swapoff calls to trigger, but for some lucky people, it triggers all the time at initial boot. Since this throws up an error, init systems don't actually activate any swap files. First, swapon shouldn't whine about unexpected format if the file is empty (the default at boot). This is easy to do by putting the warning behind a check to ferror(). Second, we can detect that the first line isn't actually the header but instead is a valid swap line and so need to be processed. This assumes that the first line will always be the same format. Looking quickly at older versions shows that this header has retained its exact format since at least Linux 2.2.0 and considering the concern that goes along with proc files and the ABI, it's highly unlikely it will ever change. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'mount/swapon.c')
-rw-r--r--mount/swapon.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/mount/swapon.c b/mount/swapon.c
index 55933b101..d89c6a965 100644
--- a/mount/swapon.c
+++ b/mount/swapon.c
@@ -135,11 +135,18 @@ read_proc_swaps(void) {
/* skip the first line */
if (!fgets(line, sizeof(line), swaps)) {
- warnx(_("%s: unexpected file format"), _PATH_PROC_SWAPS);
+ /* do not whine about an empty file */
+ if (ferror(swaps))
+ warn(_("%s: unexpected file format"), _PATH_PROC_SWAPS);
fclose(swaps);
return;
}
+ /* make sure the first line is the header */
+ if (line[0] != '\0' && strncmp(line, "Filename\t", 9))
+ goto valid_first_line;
+
while (fgets(line, sizeof(line), swaps)) {
+ valid_first_line:
/*
* Cut the line "swap_device ... more info" after device.
* This will fail with names with embedded spaces.