diff options
-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); |