Skip to content

Commit 77542a7

Browse files
poetteringkeszybz
authored andcommitted
timer: don't use persietent file timestamps from the future (systemd#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: systemd#6821
1 parent 60c776f commit 77542a7

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/core/timer.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,9 +614,23 @@ static int timer_start(Unit *u) {
614614
if (t->stamp_path) {
615615
struct stat st;
616616

617-
if (stat(t->stamp_path, &st) >= 0)
618-
t->last_trigger.realtime = timespec_load(&st.st_atim);
619-
else if (errno == ENOENT)
617+
if (stat(t->stamp_path, &st) >= 0) {
618+
usec_t ft;
619+
620+
/* Load the file timestamp, but only if it is actually in the past. If it is in the future,
621+
* something is wrong with the system clock. */
622+
623+
ft = timespec_load(&st.st_mtim);
624+
if (ft < now(CLOCK_REALTIME))
625+
t->last_trigger.realtime = ft;
626+
else {
627+
char z[FORMAT_TIMESTAMP_MAX];
628+
629+
log_unit_warning(u, "Not using persistent file timestamp %s as it is in the future.",
630+
format_timestamp(z, sizeof(z), ft));
631+
}
632+
633+
} else if (errno == ENOENT)
620634
/* The timer has never run before,
621635
* make sure a stamp file exists.
622636
*/

0 commit comments

Comments
 (0)