summaryrefslogtreecommitdiffstats
path: root/mount/swapon.c
diff options
context:
space:
mode:
authorKarel Zak2006-12-07 00:26:30 +0100
committerKarel Zak2006-12-07 00:26:30 +0100
commita47f2e66141271cde40ee5190acf93d7878bc93d (patch)
treef41145d1e432fdb55aabcf600fb9311b7d83d75c /mount/swapon.c
parentImported from util-linux-2.12l tarball. (diff)
downloadkernel-qcow2-util-linux-a47f2e66141271cde40ee5190acf93d7878bc93d.tar.gz
kernel-qcow2-util-linux-a47f2e66141271cde40ee5190acf93d7878bc93d.tar.xz
kernel-qcow2-util-linux-a47f2e66141271cde40ee5190acf93d7878bc93d.zip
Imported from util-linux-2.12m tarball.
Diffstat (limited to 'mount/swapon.c')
-rw-r--r--mount/swapon.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/mount/swapon.c b/mount/swapon.c
index 17c45cbdd..dadfc04ef 100644
--- a/mount/swapon.c
+++ b/mount/swapon.c
@@ -101,7 +101,7 @@ static void
read_proc_swaps(void) {
FILE *swaps;
char line[1024];
- char *p;
+ char *p, **q;
numSwaps = 0;
swapFiles = NULL;
@@ -121,10 +121,12 @@ read_proc_swaps(void) {
for (p = line; *p && *p != ' '; p++);
*p = 0;
- numSwaps++;
- swapFiles = realloc(swapFiles,
- numSwaps * sizeof(*swapFiles));
- swapFiles[numSwaps-1] = strdup(line);
+ q = realloc(swapFiles, (numSwaps+1) * sizeof(*swapFiles));
+ if (q == NULL)
+ break;
+ swapFiles = q;
+
+ swapFiles[numSwaps++] = strdup(line);
}
fclose(swaps);
}
@@ -134,7 +136,7 @@ is_in_proc_swaps(char *fname) {
int i;
for (i = 0; i < numSwaps; i++)
- if (!strcmp(fname, swapFiles[i]))
+ if (swapFiles[i] && !strcmp(fname, swapFiles[i]))
return 1;
return 0;
}
@@ -377,7 +379,7 @@ main_swapoff(int argc, char *argv[]) {
if (all) {
/*
- * In case /proc/swaps exists, unmount stuff listed there.
+ * In case /proc/swaps exists, unswap stuff listed there.
* We are quiet but report errors in status.
* Errors might mean that /proc/swaps
* exists as ordinary file, not in procfs.
@@ -388,7 +390,7 @@ main_swapoff(int argc, char *argv[]) {
status |= do_swapoff(swapFiles[i], QUIET);
/*
- * Unmount stuff mentioned in /etc/fstab.
+ * Unswap stuff mentioned in /etc/fstab.
* Probably it was unmounted already, so errors are not bad.
* Doing swapoff -a twice should not give error messages.
*/