diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2017-07-03 08:29:32 -0400 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2017-07-03 14:29:32 +0200 |
commit | 0004f698df1410ef8b6ab3fb5f4b41a60c91182c (patch) | |
tree | 602a66a4117fe4563c9a489aed4488c6b20000c8 /src | |
parent | 131d5e148e9ed883b3c5a3de7aca9a4f97b2774e (diff) | |
download | systemd-0004f698df1410ef8b6ab3fb5f4b41a60c91182c.tar.gz systemd-0004f698df1410ef8b6ab3fb5f4b41a60c91182c.tar.bz2 systemd-0004f698df1410ef8b6ab3fb5f4b41a60c91182c.zip |
Parse "timeout=0" as infinity in various generators (#6264)
This extends 2d79a0bbb9f651656384a0a86ed814e6306fb5dd to the kernel
command line parsing.
The parsing is changed a bit to only understand "0" as infinity. If units are
specified, parse normally, e.g. "0s" is just 0. This makes it possible to
provide a zero timeout if necessary.
Simple test is added.
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1462378.
Diffstat (limited to 'src')
-rw-r--r-- | src/basic/time-util.c | 10 | ||||
-rw-r--r-- | src/basic/time-util.h | 1 | ||||
-rw-r--r-- | src/core/load-fragment.c | 5 | ||||
-rw-r--r-- | src/cryptsetup/cryptsetup.c | 2 | ||||
-rw-r--r-- | src/fstab-generator/fstab-generator.c | 4 | ||||
-rw-r--r-- | src/shared/generator.c | 5 | ||||
-rw-r--r-- | src/test/test-time.c | 14 |
7 files changed, 32 insertions, 9 deletions
diff --git a/src/basic/time-util.c b/src/basic/time-util.c index b0b181120a..3b44985c69 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -1009,6 +1009,16 @@ int parse_sec(const char *t, usec_t *usec) { return parse_time(t, usec, USEC_PER_SEC); } +int parse_sec_fix_0(const char *t, usec_t *usec) { + t += strspn(t, WHITESPACE); + if (streq(t, "0")) { + *usec = USEC_INFINITY; + return 0; + } + + return parse_sec(t, usec); +} + int parse_nsec(const char *t, nsec_t *nsec) { static const struct { const char *suffix; diff --git a/src/basic/time-util.h b/src/basic/time-util.h index 414995e6af..3b7f0e99c0 100644 --- a/src/basic/time-util.h +++ b/src/basic/time-util.h @@ -133,6 +133,7 @@ int timestamp_deserialize(const char *value, usec_t *timestamp); int parse_timestamp(const char *t, usec_t *usec); int parse_sec(const char *t, usec_t *usec); +int parse_sec_fix_0(const char *t, usec_t *usec); int parse_time(const char *t, usec_t *usec, usec_t default_unit); int parse_nsec(const char *t, nsec_t *nsec); diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 8d7153f1b9..6a6dadda2b 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -1870,15 +1870,12 @@ int config_parse_sec_fix_0( * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a * timeout. */ - r = parse_sec(rvalue, usec); + r = parse_sec_fix_0(rvalue, usec); if (r < 0) { log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse %s= parameter, ignoring: %s", lvalue, rvalue); return 0; } - if (*usec <= 0) - *usec = USEC_INFINITY; - return 0; } diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index 91c653312a..3b4c086162 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -190,7 +190,7 @@ static int parse_one_option(const char *option) { arg_type = CRYPT_PLAIN; else if ((val = startswith(option, "timeout="))) { - r = parse_sec(val, &arg_timeout); + r = parse_sec_fix_0(val, &arg_timeout); if (r < 0) { log_error_errno(r, "Failed to parse %s, ignoring: %m", option); return 0; diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index b6c1a8781b..0bbc6c71bc 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -176,7 +176,7 @@ static bool mount_in_initrd(struct mntent *me) { } static int write_timeout(FILE *f, const char *where, const char *opts, - const char *filter, const char *variable) { + const char *filter, const char *variable) { _cleanup_free_ char *timeout = NULL; char timespan[FORMAT_TIMESPAN_MAX]; usec_t u; @@ -188,7 +188,7 @@ static int write_timeout(FILE *f, const char *where, const char *opts, if (r == 0) return 0; - r = parse_sec(timeout, &u); + r = parse_sec_fix_0(timeout, &u); if (r < 0) { log_warning("Failed to parse timeout for %s, ignoring: %s", where, timeout); return 0; diff --git a/src/shared/generator.c b/src/shared/generator.c index 19ec133772..6a78ebbda7 100644 --- a/src/shared/generator.c +++ b/src/shared/generator.c @@ -167,12 +167,13 @@ int generator_write_timeouts( usec_t u; int r; - r = fstab_filter_options(opts, "comment=systemd.device-timeout\0" "x-systemd.device-timeout\0", + r = fstab_filter_options(opts, "comment=systemd.device-timeout\0" + "x-systemd.device-timeout\0", NULL, &timeout, filtered); if (r <= 0) return r; - r = parse_sec(timeout, &u); + r = parse_sec_fix_0(timeout, &u); if (r < 0) { log_warning("Failed to parse timeout for %s, ignoring: %s", where, timeout); return 0; diff --git a/src/test/test-time.c b/src/test/test-time.c index 601e835f16..b7a06c7b19 100644 --- a/src/test/test-time.c +++ b/src/test/test-time.c @@ -61,6 +61,19 @@ static void test_parse_sec(void) { assert_se(parse_sec(".3 infinity", &u) < 0); } +static void test_parse_sec_fix_0(void) { + usec_t u; + + assert_se(parse_sec_fix_0("5s", &u) >= 0); + assert_se(u == 5 * USEC_PER_SEC); + assert_se(parse_sec_fix_0("0s", &u) >= 0); + assert_se(u == 0 * USEC_PER_SEC); + assert_se(parse_sec_fix_0("0", &u) >= 0); + assert_se(u == USEC_INFINITY); + assert_se(parse_sec_fix_0(" 0", &u) >= 0); + assert_se(u == USEC_INFINITY); +} + static void test_parse_time(void) { usec_t u; @@ -380,6 +393,7 @@ int main(int argc, char *argv[]) { now(clock_boottime_or_monotonic())); test_parse_sec(); + test_parse_sec_fix_0(); test_parse_time(); test_parse_nsec(); test_format_timespan(1); |