mirror of
https://github.com/troglobit/finit.git
synced 2026-09-30 21:13:01 +07:00
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>
This commit is contained in:
+20
-12
@@ -170,16 +170,18 @@ static void file_save(void *arg)
|
|||||||
static void file_restore(void *arg)
|
static void file_restore(void *arg)
|
||||||
{
|
{
|
||||||
struct tm tm = { 0 };
|
struct tm tm = { 0 };
|
||||||
int rc = 1;
|
int rc = 0;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
char msg[120];
|
||||||
|
|
||||||
if (!rtc_file) {
|
if (!rtc_file) {
|
||||||
logit(LOG_NOTICE, "System has no RTC (missing driver?), skipping restore.");
|
snprintf(msg, sizeof(msg), "Resetting system clock to kernel default, %s.", rtc_timestamp);
|
||||||
|
print_desc(NULL, msg);
|
||||||
|
rc = time_set(NULL);
|
||||||
|
print(rc, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
print_desc(NULL, "Restoring system clock from backup");
|
|
||||||
|
|
||||||
fp = fopen(rtc_file, "r");
|
fp = fopen(rtc_file, "r");
|
||||||
if (fp) {
|
if (fp) {
|
||||||
char buf[32];
|
char buf[32];
|
||||||
@@ -187,18 +189,25 @@ static void file_restore(void *arg)
|
|||||||
if (fgets(buf, sizeof(buf), fp)) {
|
if (fgets(buf, sizeof(buf), fp)) {
|
||||||
chomp(buf);
|
chomp(buf);
|
||||||
strptime(buf, RTC_FMT, &tm);
|
strptime(buf, RTC_FMT, &tm);
|
||||||
rc = time_set(&tm);
|
if (!strptime(buf, RTC_FMT, &tm))
|
||||||
|
rc = 1;
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
} else
|
}
|
||||||
logit(LOG_WARNING, "Missing %s", rtc_file);
|
rc = 1;
|
||||||
|
|
||||||
if (rc) {
|
if (rc) {
|
||||||
time_set(NULL);
|
print_desc(NULL, "Failed to restore system clock from restore file");
|
||||||
rc = 2;
|
print(2, NULL);
|
||||||
}
|
snprintf(msg, sizeof(msg), "Resetting system clock to kernel default, %s.", rtc_timestamp);
|
||||||
|
print_desc(NULL, msg);
|
||||||
|
rc = time_set(NULL);
|
||||||
print(rc, NULL);
|
print(rc, NULL);
|
||||||
|
} else {
|
||||||
|
print_desc(NULL, "Restoring system clock from restore file");
|
||||||
|
rc = time_set(&tm);
|
||||||
|
print(rc, NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rtc_open(void)
|
static int rtc_open(void)
|
||||||
@@ -292,7 +301,6 @@ static void rtc_restore(void *arg)
|
|||||||
print(2, NULL);
|
print(2, NULL);
|
||||||
|
|
||||||
/* Try restoring from last save game */
|
/* Try restoring from last save game */
|
||||||
if (rtc_file)
|
|
||||||
file_restore(arg);
|
file_restore(arg);
|
||||||
} else
|
} else
|
||||||
print(0, NULL);
|
print(0, NULL);
|
||||||
|
|||||||
Reference in New Issue
Block a user