diff options
author | Karel Zak | 2008-08-19 01:14:14 +0200 |
---|---|---|
committer | Karel Zak | 2008-08-19 01:22:02 +0200 |
commit | 1b414d89359f79b128373a6c39cf44dc1e358306 (patch) | |
tree | 9eba3c72a44bdf19c4309c5280165f7d8301f3e2 /mount | |
parent | hwclock: don't open /dev/rtc repeatedly (diff) | |
download | kernel-qcow2-util-linux-1b414d89359f79b128373a6c39cf44dc1e358306.tar.gz kernel-qcow2-util-linux-1b414d89359f79b128373a6c39cf44dc1e358306.tar.xz kernel-qcow2-util-linux-1b414d89359f79b128373a6c39cf44dc1e358306.zip |
swapon: -a has to complain, fix leaks
The "swapon -a" command (without "-e" option) has to complain always
when LABEL or UUID does not exist.
Test:
# grep foo /etc/fstab
LABEL=foo swap swap defaults 0 0
Old version:
# swapon -a; echo $?
0
Fixed version:
# swapon -a; echo $?
swapon: cannot find the device for LABEL=foo
255
# swapon -a -e; echo $?
0
This version also fix two memory leaks.
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'mount')
-rw-r--r-- | mount/swapon.c | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/mount/swapon.c b/mount/swapon.c index f0c969b61..eb0eb4aba 100644 --- a/mount/swapon.c +++ b/mount/swapon.c @@ -400,29 +400,37 @@ swapon_all(void) { const char *special; int skip = 0; int pri = priority; + char *opt, *opts; if (!streq(fstab->mnt_type, MNTTYPE_SWAP)) continue; + opts = strdup(fstab->mnt_opts); + + for (opt = strtok(opts, ","); opt != NULL; + opt = strtok(NULL, ",")) { + if (strncmp(opt, "pri=", 4) == 0) + pri = atoi(opt+4); + if (strcmp(opt, "noauto") == 0) + skip = 1; + } + free(opts); + + if (skip) + continue; + special = fsprobe_get_devname(fstab->mnt_fsname); - if (!special) + if (!special) { + if (!ifexists) + status |= cannot_find(fstab->mnt_fsname); continue; + } if (!is_in_proc_swaps(special) && - (!ifexists || !access(special, R_OK))) { - /* parse mount options; */ - char *opt, *opts = strdup(fstab->mnt_opts); - - for (opt = strtok(opts, ","); opt != NULL; - opt = strtok(NULL, ",")) { - if (strncmp(opt, "pri=", 4) == 0) - pri = atoi(opt+4); - if (strcmp(opt, "noauto") == 0) - skip = 1; - } - if (!skip) - status |= do_swapon(special, pri, CANONIC); - } + (!ifexists || !access(special, R_OK))) + status |= do_swapon(special, pri, CANONIC); + + free((void *) special); } fclose(fp); |