From b1d6dcf5a5c5aa02843c026dede0638f77798cb4 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Mon, 29 Sep 2014 07:31:14 -0500 Subject: Do not format USEC_INFINITY as NULL systemctl would print 'CPUQuotaPerSecUSec=(null)' for no limit. This does not look right. Since USEC_INFINITY is one of the valid values, format_timespan() could return NULL, and we should wrap every use of it in strna() or similar. But most callers didn't do that, and it seems more robust to return a string ("infinity") that makes sense most of the time, even if in some places the result will not be grammatically correct. --- src/test/test-time.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/test/test-time.c') diff --git a/src/test/test-time.c b/src/test/test-time.c index 87e7ae742a..8cfc4cc4fe 100644 --- a/src/test/test-time.c +++ b/src/test/test-time.c @@ -43,12 +43,18 @@ static void test_parse_sec(void) { assert_se(u == 2500 * USEC_PER_MSEC); assert_se(parse_sec(".7", &u) >= 0); assert_se(u == 700 * USEC_PER_MSEC); + assert_se(parse_sec("infinity", &u) >= 0); + assert_se(u == USEC_INFINITY); + assert_se(parse_sec(" infinity ", &u) >= 0); + assert_se(u == USEC_INFINITY); assert_se(parse_sec(" xyz ", &u) < 0); assert_se(parse_sec("", &u) < 0); assert_se(parse_sec(" . ", &u) < 0); assert_se(parse_sec(" 5. ", &u) < 0); assert_se(parse_sec(".s ", &u) < 0); + assert_se(parse_sec(" infinity .7", &u) < 0); + assert_se(parse_sec(".3 infinity", &u) < 0); } static void test_parse_nsec(void) { @@ -125,6 +131,7 @@ static void test_format_timespan(usec_t accuracy) { test_format_timespan_one(986087, accuracy); test_format_timespan_one(500 * USEC_PER_MSEC, accuracy); test_format_timespan_one(9*USEC_PER_YEAR/5 - 23, accuracy); + test_format_timespan_one(USEC_INFINITY, accuracy); } static void test_timezone_is_valid(void) { -- cgit v1.2.3-54-g00ecf