From: Karel Zak Date: Wed, 10 Mar 2010 22:08:26 +0000 (+0100) Subject: swapon: remove " (deleted)" from filenames from /proc/swaps X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dac4cc1dd6b855d781d2ff9689931786ece0acbf;p=util-linux 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 --- diff --git a/mount/swapon.c b/mount/swapon.c index 5574f7ea..9f702ecb 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)