timer: don't use persietent file timestamps from the future (#6823)
Also, use the mtime rather than the atime of the timestamp file. While the atime is not completely wrong, the mtime appears more appropriate as that's what we actually explicitly change, and is not effected by mere reading. Fixes: #6821
This commit is contained in:
parent
60c776fd75
commit
77542a7905
|
@ -614,9 +614,23 @@ static int timer_start(Unit *u) {
|
|||
if (t->stamp_path) {
|
||||
struct stat st;
|
||||
|
||||
if (stat(t->stamp_path, &st) >= 0)
|
||||
t->last_trigger.realtime = timespec_load(&st.st_atim);
|
||||
else if (errno == ENOENT)
|
||||
if (stat(t->stamp_path, &st) >= 0) {
|
||||
usec_t ft;
|
||||
|
||||
/* Load the file timestamp, but only if it is actually in the past. If it is in the future,
|
||||
* something is wrong with the system clock. */
|
||||
|
||||
ft = timespec_load(&st.st_mtim);
|
||||
if (ft < now(CLOCK_REALTIME))
|
||||
t->last_trigger.realtime = ft;
|
||||
else {
|
||||
char z[FORMAT_TIMESTAMP_MAX];
|
||||
|
||||
log_unit_warning(u, "Not using persistent file timestamp %s as it is in the future.",
|
||||
format_timestamp(z, sizeof(z), ft));
|
||||
}
|
||||
|
||||
} else if (errno == ENOENT)
|
||||
/* The timer has never run before,
|
||||
* make sure a stamp file exists.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue