From 07332bfa1ec122a251194a62f91319841121d5aa Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 21 Sep 2016 14:47:32 +0200 Subject: swapon: fix discard option parsing The current code does not work as expected if there is an option behind the discard=, 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 --- sys-utils/swapon.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'sys-utils/swapon.c') 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; } } -- cgit v1.2.3-55-g7522