Whamcloud - gitweb
libext2fs: handle <=linux-2.6.19 bug in /proc/swaps
authorKarel Zak <kzak@redhat.com>
Tue, 13 Oct 2009 13:52:59 +0000 (13:52 +0000)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 13 Nov 2009 13:48:29 +0000 (08:48 -0500)
Linux <= 2.6.19 contained a bug in the /proc/swaps code where the
header would not be displayed (the first line).

This issue has been reported by Mike Frysinger for swapon(8).

Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/ismounted.c

index 5682a8b..d28b6ad 100644 (file)
@@ -253,8 +253,16 @@ static int is_swap_device(const char *file)
        if (!(f = fopen("/proc/swaps", "r")))
                return 0;
        /* Skip the first line */
-       if (fgets(buf, sizeof(buf), f))
+       if (!fgets(buf, sizeof(buf), f))
+               goto leave;
+       if (*buf && strncmp(buf, "Filename\t", 9))
+               /* Linux <=2.6.19 contained a bug in the /proc/swaps
+                * code where the header would not be displayed
+                */
+               goto valid_first_line;
+
        while (fgets(buf, sizeof(buf), f)) {
+valid_first_line:
                if ((cp = strchr(buf, ' ')) != NULL)
                        *cp = 0;
                if ((cp = strchr(buf, '\t')) != NULL)
@@ -272,6 +280,8 @@ static int is_swap_device(const char *file)
                }
 #endif         /* __GNU__ */
        }
+
+leave:
        fclose(f);
        return ret;
 }