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;
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);
* 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;
}
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;
}
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;
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;
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;
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;
now(clock_boottime_or_monotonic()));
test_parse_sec();
+ test_parse_sec_fix_0();
test_parse_time();
test_parse_nsec();
test_format_timespan(1);