mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-23 17:34:00 +03:00
26698337f3
When the RTC time at boot is off in the future by a few days, OnCalendar= timers will be scheduled based on the time at boot. But if the time has been adjusted since boot, the timers will end up scheduled way in the future, which may cause them not to fire as shortly or often as expected. Update the logic so that the time will be adjusted based on monotonic time. We do that by calculating the adjusted manager startup realtime from the monotonic time stored at that time, by comparing that time with the realtime and monotonic time of the current time. Added a test case to validate this works as expected. The test case creates a QEMU virtual machine with the clock 3 days in the future. Then we adjust the clock back 3 days, and test creating a timer with an OnCalendar= for every 15 minutes. We also check the manager startup timestamp from both `systemd-analyze dump` and from D-Bus. Test output without the corresponding code changes that fix the issue: Timer elapse outside of the expected 20 minute window. next_elapsed=1594686119 now=1594426921 time_delta=259198 With the code changes in, the test passes as expected.
31 lines
773 B
Bash
Executable File
31 lines
773 B
Bash
Executable File
#!/usr/bin/env bash
|
|
set -ex
|
|
set -o pipefail
|
|
|
|
>/failed
|
|
|
|
# Reset host date to current time, 3 days in the past.
|
|
date -s "-3 days"
|
|
|
|
# Run a timer for every 15 minutes.
|
|
systemd-run --unit test-timer --on-calendar "*:0/15:0" true
|
|
|
|
next_elapsed=$(systemctl show test-timer.timer -p NextElapseUSecRealtime --value)
|
|
next_elapsed=$(date -d "${next_elapsed}" +%s)
|
|
now=$(date +%s)
|
|
time_delta=$((next_elapsed - now))
|
|
|
|
# Check that the timer will elapse in less than 20 minutes.
|
|
((0 < time_delta && time_delta < 1200)) || {
|
|
echo 'Timer elapse outside of the expected 20 minute window.'
|
|
echo " next_elapsed=${next_elapsed}"
|
|
echo " now=${now}"
|
|
echo " time_delta=${time_delta}"
|
|
echo ''
|
|
} >>/failed
|
|
|
|
if test ! -s /failed ; then
|
|
rm -f /failed
|
|
touch /testok
|
|
fi
|