From cd383167f9e9205d32f62a8483f413e2795cc8c7 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sat, 1 Jan 2022 22:51:45 +0100 Subject: [PATCH] plugins/rtc: instead of bailing, reset invalid RTC to kernel default Signed-off-by: Joachim Wiberg --- plugins/rtc.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/plugins/rtc.c b/plugins/rtc.c index 90a68326..68777590 100644 --- a/plugins/rtc.c +++ b/plugins/rtc.c @@ -156,8 +156,18 @@ static void rtc_restore(void *arg) logit(LOG_ERR, "RTC has no previously saved (valid) time."); else logit(LOG_ERR, "RTC error code %d: %s", errno, strerror(errno)); + + /* Been here already? */ + if (rc) + goto out; + + /* Attempt to set RTC to a sane value ... */ + tv.tv_sec = RTC_TIMESTAMP_BEGIN_2000; + if (!gmtime_r(&tv.tv_sec, &tm)) + goto out; + + logit(LOG_NOTICE, "Resetting RTC to kernel default, 2000-01-01 00:00."); rc = 2; - goto out; } print_desc(NULL, "Restoring system clock (UTC) from RTC");