From: Karel Zak Date: Wed, 21 Sep 2016 12:47:32 +0000 (+0200) Subject: swapon: fix discard option parsing X-Git-Tag: v2.29-rc1~40 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=07332bfa1ec122a251194a62f91319841121d5aa;p=thirdparty%2Futil-linux.git 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 --- diff --git a/sys-utils/swapon.c b/sys-utils/swapon.c index 62a776d401..0ee5caf448 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; } }