]> err.no Git - util-linux/commitdiff
swapon: remove " (deleted)" from filenames from /proc/swaps
authorKarel Zak <kzak@redhat.com>
Wed, 10 Mar 2010 22:08:26 +0000 (23:08 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 10 Mar 2010 22:08:26 +0000 (23:08 +0100)
The filenames in /proc/swaps are generated by seq_path() and this
function uses __d_path() from fs/dcache.c. The filename could
generated with " (deleted)" suffix. We need real filenames without
the suffix.

Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=562403
Signed-off-by: Karel Zak <kzak@redhat.com>
mount/swapon.c

index 5574f7ea63b15f061bcd196873e4e4d483eac6ad..9f702ecb8c3989353ad80b2b2d516436c30b1acd 100644 (file)
@@ -120,11 +120,15 @@ swapoff_usage(FILE *fp, int n) {
 static int numSwaps;
 static char **swapFiles;       /* array of swap file and partition names */
 
+#define DELETED_SUFFIX         "\\040(deleted)"
+#define DELETED_SUFFIX_SZ      (sizeof(DELETED_SUFFIX) - 1)
+
 static void
 read_proc_swaps(void) {
        FILE *swaps;
        char line[1024];
        char *p, **q;
+       size_t sz;
 
        numSwaps = 0;
        swapFiles = NULL;
@@ -152,7 +156,17 @@ read_proc_swaps(void) {
                 * This will fail with names with embedded spaces.
                 */
                for (p = line; *p && *p != ' '; p++);
-               *p = 0;
+               *p = '\0';
+
+               /* the kernel can use " (deleted)" suffix for paths
+                * in /proc/swaps, we have to remove this junk.
+                */
+               sz = strlen(line);
+               if (sz > DELETED_SUFFIX_SZ) {
+                      p = line + (sz - DELETED_SUFFIX_SZ);
+                      if (strcmp(p, DELETED_SUFFIX) == 0)
+                              *p = '\0';
+               }
 
                q = realloc(swapFiles, (numSwaps+1) * sizeof(*swapFiles));
                if (q == NULL)