From 73760c099f5abdd636723d44d108165defc2ed09 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 3 Jul 2017 08:29:32 -0400 Subject: [PATCH] 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. --- src/basic/time-util.c | 10 ++++++++++ src/basic/time-util.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/basic/time-util.c b/src/basic/time-util.c index 7da7ea41c..d8997666e 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -1024,6 +1024,16 @@ int parse_sec(const char *t, usec_t *usec) { } #if 0 /// UNNEEDED by elogind +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 58b8c5300..6bf0f72ef 100644 --- a/src/basic/time-util.h +++ b/src/basic/time-util.h @@ -147,6 +147,9 @@ int parse_timestamp(const char *t, usec_t *usec); #endif // 0 int parse_sec(const char *t, usec_t *usec); +#if 0 /// UNNEEDED by elogind +int parse_sec_fix_0(const char *t, usec_t *usec); +#endif // 0 int parse_time(const char *t, usec_t *usec, usec_t default_unit); #if 0 /// UNNEEDED by elogind int parse_nsec(const char *t, nsec_t *nsec); -- 2.30.2