Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions plugins/rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,35 +170,44 @@ static void file_save(void *arg)
static void file_restore(void *arg)
{
struct tm tm = { 0 };
int rc = 1;
int rc = 0;
FILE *fp;
char msg[120];

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;
}

print_desc(NULL, "Restoring system clock from backup");

fp = fopen(rtc_file, "r");
if (fp) {
char buf[32];

if (fgets(buf, sizeof(buf), fp)) {
chomp(buf);
strptime(buf, RTC_FMT, &tm);
rc = time_set(&tm);
if (!strptime(buf, RTC_FMT, &tm))
rc = 1;
}
fclose(fp);
} else
logit(LOG_WARNING, "Missing %s", rtc_file);
}
rc = 1;

if (rc) {
time_set(NULL);
rc = 2;
print_desc(NULL, "Failed to restore system clock from restore file");
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);
} else {
print_desc(NULL, "Restoring system clock from restore file");
rc = time_set(&tm);
print(rc, NULL);
}

print(rc, NULL);
}

static int rtc_open(void)
Expand Down Expand Up @@ -292,8 +301,7 @@ static void rtc_restore(void *arg)
print(2, NULL);

/* Try restoring from last save game */
if (rtc_file)
file_restore(arg);
file_restore(arg);
} else
print(0, NULL);

Expand Down