]> git.ipfire.org Git - thirdparty/systemd.git/commit
systemctl: Fix shutdown time parsing across DST changes
authorChris Down <chris@chrisdown.name>
Tue, 4 Nov 2025 10:19:07 +0000 (18:19 +0800)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 4 Nov 2025 16:36:47 +0000 (01:36 +0900)
commita8c3ac66721de23cceff359d946ecd9695bbacb8
tree78082abd3d7acba553bd27301b95fea95f748b84
parent05b880ac46b27c65de09d7add6b0e2f5ac3bcd9a
systemctl: Fix shutdown time parsing across DST changes

When parsing an absolute time specification like `hh:mm` for the
`shutdown` command, the code interprets a time in the past as "tomorrow
at this time". It currently implements this by adding a fixed 24-hour
duration (`USEC_PER_DAY`) to the timestamp.

This assumption breaks across DST transitions, as the day might not be
24 hours long. This can cause the shutdown to be scheduled at the wrong
time (typically off by one hour in either direction).

Change the logic to perform calendar arithmetic instead of timestamp
arithmetic. If the calculated time is in the past, we increment
`tm.tm_mday` and call `mktime_or_timegm_usec()` a second time.

This delegates all date normalization logic to `mktime()`, which
correctly handles all edge cases, including DST transitions, month-end
rollovers, and leap years.

Fixes: https://github.com/systemd/systemd/issues/39232
src/systemctl/systemctl-compat-shutdown.c