From 35f7216f968047be26a922dc09ca588ebca71bb0 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Fri, 26 Feb 2016 12:33:41 +0100 Subject: clock-util: be more tolerant in parsing /etc/adjtime As we default to "hardware clock is in UTC" if /etc/adjtime is not present, it also makes sense to have that default if /etc/adjtime contains only one or two lines. Drop the "gibberish" test case, as this was just EIO because of not containing three lines, which is already contained in other tests. clock_is_localtime() never actually validated the format of the first two lines, and there is little point in doing that. This addresses the reading half of issue #2638. --- src/basic/clock-util.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/basic') diff --git a/src/basic/clock-util.c b/src/basic/clock-util.c index dd6c043af9..7fe8d35ea5 100644 --- a/src/basic/clock-util.c +++ b/src/basic/clock-util.c @@ -91,7 +91,8 @@ int clock_is_localtime(const char* adjtime_path) { fgets(line, sizeof(line), f) && fgets(line, sizeof(line), f); if (!b) - return -EIO; + /* less than three lines -> default to UTC */ + return 0; truncate_nl(line); return streq(line, "LOCAL"); @@ -99,6 +100,7 @@ int clock_is_localtime(const char* adjtime_path) { } else if (errno != ENOENT) return -errno; + /* adjtime not present -> default to UTC */ return 0; } -- cgit v1.2.3-54-g00ecf