From: Lennart Poettering Date: Thu, 14 Sep 2017 16:26:10 +0000 (+0200) Subject: timer: don't use persietent file timestamps from the future (#6823) X-Git-Tag: v235~111 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=77542a7905520f1d637912bf47bddb4855506e41;p=thirdparty%2Fsystemd.git 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 --- diff --git a/src/core/timer.c b/src/core/timer.c index 701949fd60d..3032a237b17 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -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. */