]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
time-util: change parse_sec_fix_0() to accept "0s" for infinity too (#10501)
authorLennart Poettering <lennart@poettering.net>
Wed, 24 Oct 2018 20:21:28 +0000 (22:21 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 24 Oct 2018 20:21:28 +0000 (05:21 +0900)
This function is about compatibility, nothing else, hence we should make
it properly compatible.

Fixes: #9556
src/basic/time-util.c
src/test/test-time-util.c

index 4d297394e2acdf463247686ccc0bb8bfe9e2729d..c192389584f2e63c1953c306f3a3fc30191f8dc5 100644 (file)
@@ -1074,18 +1074,19 @@ 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) {
-        assert(t);
-        assert(usec);
+int parse_sec_fix_0(const char *t, usec_t *ret) {
+        usec_t k;
+        int r;
 
-        t += strspn(t, WHITESPACE);
+        assert(t);
+        assert(ret);
 
-        if (streq(t, "0")) {
-                *usec = USEC_INFINITY;
-                return 0;
-        }
+        r = parse_sec(t, &k);
+        if (r < 0)
+                return r;
 
-        return parse_sec(t, usec);
+        *ret = k == 0 ? USEC_INFINITY : k;
+        return r;
 }
 
 int parse_nsec(const char *t, nsec_t *nsec) {
index 82a71d047886819f8cbc95aa117c42bb60ffd2b5..abb174b7a6ae5beec58a598f4f065d63368ce206 100644 (file)
@@ -65,7 +65,7 @@ static void test_parse_sec_fix_0(void) {
         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(u == USEC_INFINITY);
         assert_se(parse_sec_fix_0("0", &u) >= 0);
         assert_se(u == USEC_INFINITY);
         assert_se(parse_sec_fix_0(" 0", &u) >= 0);