From 6be16f2f6d093ef495d0fe4313f7b05b4ba3e08f Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 3 Nov 2024 10:38:38 +0100 Subject: [PATCH] Fix buggy --with-rtc-date=DATE, introduced in Finit v4.4 In 42ef3d3c, for v4.4-rc1, support for setting a custom RTC restore date was introduced. Unfortunately the configure script was wrong and caused config.h to contain #define RTC_TIMESTAMP_CUSTOM "$rtc_date" instead of #define RTC_TIMESTAMP_CUSTOM "2023-04-10 14:35:42" Furthermore, the error handling for strptime() was wrong, so the restore date was always reverted to the default. This patch fixes both issues and extends the DATE of --with-rtc-date to also include seconds. Signed-off-by: Joachim Wiberg --- configure.ac | 4 ++-- plugins/rtc.c | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index ae7cd238..58b78ac5 100644 --- a/configure.ac +++ b/configure.ac @@ -177,7 +177,7 @@ AC_ARG_WITH(plugin-path, [plugin_path=$withval], [plugin_path=yes]) AC_ARG_WITH(rtc-date, - AS_HELP_STRING([--with-rtc-date=DATE], [If RTC date/time is too old, restore to DATE, format "YYYY-MM-DD HH:MM", default "2000-01-01 00:00"]), + AS_HELP_STRING([--with-rtc-date=DATE], [If RTC date/time is too old, restore to DATE, format "YYYY-MM-DD HH:MM:SS", default "2000-01-01 00:00:00"]), [rtc_date=$withval], [rtc_date=no]) AC_ARG_WITH(rtc-file, @@ -282,7 +282,7 @@ AS_IF([test "x$with_random_seed" != "xno"], [ AC_DEFINE_UNQUOTED(RANDOMSEED, "$random_path", [Improve random at boot by seeding it with sth from before.])]) AS_IF([test "x$rtc_date" != "xno"], [ - AC_DEFINE(RTC_TIMESTAMP_CUSTOM, "$rtc_date", [Custom RTC restore date, default: 2000-01-01 00:00])], [ + AC_DEFINE_UNQUOTED(RTC_TIMESTAMP_CUSTOM, "$rtc_date", [Custom RTC restore date, default: 2000-01-01 00:00])], [ rtc_date=""]) AS_IF([test "x$rtc_file" != "xno"], [ diff --git a/plugins/rtc.c b/plugins/rtc.c index 9b4eeae5..a733f754 100644 --- a/plugins/rtc.c +++ b/plugins/rtc.c @@ -321,10 +321,12 @@ PLUGIN_INIT(plugin_init) { struct tm tm = { 0 }; - if (!strptime(rtc_timestamp, "%Y-%m-%d %H:%M", &tm)) - rtc_date_fallback = mktime(&tm); - else + if (!strptime(rtc_timestamp, RTC_FMT, &tm)) { + logit(LOG_ERR, "Invalid restore date '%s', reverting to '%s'", + rtc_timestamp, RTC_TIMESTAMP_BEGIN_2000); rtc_timestamp = RTC_TIMESTAMP_BEGIN_2000; + } else + rtc_date_fallback = mktime(&tm); uev_timer_init(ctx, &rtc_timer, update, NULL, RTC_PERIOD, RTC_PERIOD);