Skip to content

Commit 5b7eef7

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. Signed-off-by: Ming Liu <liu.ming50@gmail.com>
1 parent 6f6267f commit 5b7eef7

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

plugins/rtc.c

Lines changed: 5 additions & 10 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");
@@ -190,12 +185,13 @@ static void file_restore(void *arg)
190185
rc = time_set(&tm);
191186
}
192187
fclose(fp);
193-
} else
194-
logit(LOG_WARNING, "Missing %s", rtc_file);
188+
}
195189

196190
if (rc) {
191+
logit(LOG_WARNING, "Failed restoring system time from %s, try restoring system clock from build timestamp", rtc_file);
192+
print(2, NULL);
197193
time_set(NULL);
198-
rc = 2;
194+
rc = 0;
199195
}
200196

201197
print(rc, NULL);
@@ -292,8 +288,7 @@ static void rtc_restore(void *arg)
292288
print(2, NULL);
293289

294290
/* Try restoring from last save game */
295-
if (rtc_file)
296-
file_restore(arg);
291+
file_restore(arg);
297292
} else
298293
print(0, NULL);
299294

0 commit comments

Comments
 (0)