Skip to content

Commit 41d9e7a

Browse files
committed
plugins:rtc.c: drop some invalid condition checks
There are some invalid condition checks in rtc.c, when rtc_file is missing, it should not consider that as a error and return, otherwise, it can lead to the case that time_set wont be called at all. With this fix, when both RTC and file restore fail, it will fall back to call time_set(NULL) and restore time from rtc_timestamp, this ensures the OS has a valid time at the very first boot. Also explicitly check strptime return value against "NULL" rather than using "!", which is not always accurate. Signed-off-by: Ming Liu <liu.ming50@gmail.com>
1 parent 6f6267f commit 41d9e7a

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

plugins/rtc.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,6 @@ static void file_restore(void *arg)
173173
int rc = 1;
174174
FILE *fp;
175175

176-
if (!rtc_file) {
177-
logit(LOG_NOTICE, "System has no RTC (missing driver?), skipping restore.");
178-
return;
179-
}
180-
181176
print_desc(NULL, "Restoring system clock from backup");
182177

183178
fp = fopen(rtc_file, "r");
@@ -292,8 +287,7 @@ static void rtc_restore(void *arg)
292287
print(2, NULL);
293288

294289
/* Try restoring from last save game */
295-
if (rtc_file)
296-
file_restore(arg);
290+
file_restore(arg);
297291
} else
298292
print(0, NULL);
299293

@@ -327,7 +321,7 @@ PLUGIN_INIT(__init)
327321
{
328322
struct tm tm = { 0 };
329323

330-
if (!strptime(rtc_timestamp, RTC_FMT, &tm)) {
324+
if (strptime(rtc_timestamp, RTC_FMT, &tm) == NULL) {
331325
logit(LOG_WARNING, "Invalid restore date '%s', reverting to '%s'",
332326
rtc_timestamp, RTC_TIMESTAMP_BEGIN_2000);
333327
rtc_timestamp = RTC_TIMESTAMP_BEGIN_2000;

0 commit comments

Comments
 (0)