diff options
author | Karel Zak | 2016-09-21 14:47:32 +0200 |
---|---|---|
committer | Karel Zak | 2016-09-21 15:08:50 +0200 |
commit | 07332bfa1ec122a251194a62f91319841121d5aa (patch) | |
tree | 6dcb66f3c8cd81c191fb65ed53900ca84a74fe93 /sys-utils/swapon.c | |
parent | Merge branch 'hotfix' of https://github.com/ignatenkobrain/util-linux (diff) | |
download | kernel-qcow2-util-linux-07332bfa1ec122a251194a62f91319841121d5aa.tar.gz kernel-qcow2-util-linux-07332bfa1ec122a251194a62f91319841121d5aa.tar.xz kernel-qcow2-util-linux-07332bfa1ec122a251194a62f91319841121d5aa.zip |
swapon: fix discard option parsing
The current code does not work as expected if there is an option
behind the discard=<arg>, for example:
swapon /dev/sdc -o discard=once,pri=10
ignores "once" the result is SWAP_FLAG_DISCARD; strace:
Old version:
swapon("/dev/sdc", SWAP_FLAG_PREFER|SWAP_FLAG_DISCARD|10) = 0
Fixed version:
swapon("/dev/sdc", SWAP_FLAG_PREFER|SWAP_FLAG_DISCARD|SWAP_FLAG_DISCARD_ONCE|10) = 0
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/swapon.c')
-rw-r--r-- | sys-utils/swapon.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/sys-utils/swapon.c b/sys-utils/swapon.c index 62a776d40..0ee5caf44 100644 --- a/sys-utils/swapon.c +++ b/sys-utils/swapon.c @@ -688,6 +688,7 @@ static int swapon_by_uuid(struct swapon_ctl *ctl, const char *uuid) static int parse_options(struct swap_prop *props, const char *options) { char *arg = NULL; + size_t argsz = 0; assert(props); assert(options); @@ -695,16 +696,16 @@ static int parse_options(struct swap_prop *props, const char *options) if (mnt_optstr_get_option(options, "nofail", NULL, 0) == 0) props->no_fail = 1; - if (mnt_optstr_get_option(options, "discard", &arg, NULL) == 0) { + if (mnt_optstr_get_option(options, "discard", &arg, &argsz) == 0) { props->discard |= SWAP_FLAG_DISCARD; if (arg) { /* only single-time discards are wanted */ - if (strcmp(arg, "once") == 0) + if (strncmp(arg, "once", argsz) == 0) props->discard |= SWAP_FLAG_DISCARD_ONCE; /* do discard for every released swap page */ - if (strcmp(arg, "pages") == 0) + if (strncmp(arg, "pages", argsz) == 0) props->discard |= SWAP_FLAG_DISCARD_PAGES; } } |