diff options
author | Karel Zak | 2010-03-10 23:08:26 +0100 |
---|---|---|
committer | Karel Zak | 2010-03-10 23:08:26 +0100 |
commit | dac4cc1dd6b855d781d2ff9689931786ece0acbf (patch) | |
tree | ad690cbf5ea2dc89425627afe49274e3691cc444 /mount/swapon.c | |
parent | libblkid: add blkid_probe_get_{offset,fd} functions (diff) | |
download | kernel-qcow2-util-linux-dac4cc1dd6b855d781d2ff9689931786ece0acbf.tar.gz kernel-qcow2-util-linux-dac4cc1dd6b855d781d2ff9689931786ece0acbf.tar.xz kernel-qcow2-util-linux-dac4cc1dd6b855d781d2ff9689931786ece0acbf.zip |
swapon: remove " (deleted)" from filenames from /proc/swaps
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>
Diffstat (limited to 'mount/swapon.c')
-rw-r--r-- | mount/swapon.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/mount/swapon.c b/mount/swapon.c index 5574f7ea6..9f702ecb8 100644 --- a/mount/swapon.c +++ b/mount/swapon.c @@ -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) |