]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: allow disabling system time correction if rtc returns time far in the future
authorFranck Bui <fbui@suse.com>
Tue, 23 Aug 2022 15:07:23 +0000 (17:07 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 24 Aug 2022 20:39:46 +0000 (21:39 +0100)
There might be (embedded) systems that get never updated (things like
e.g. entertainment systems of trains, for example) and where the adjustment of
the system clock (introduced by b10abe4bba61aebe4c667c412741193f11886298) would
do the wrong thing even if the difference between the systemd build time and
the rtc is 15 years or more.

This patch allows disabling the adjustment by setting
'clock-valid-range-usec-max' meson option to 0 or to a negative value.

meson_options.txt
src/shared/clock-util.c

index d5237f02ae3c878ce934c237f500158efb0aa325..814f34084099a21cd259a565b591a1c0d5d93e0e 100644 (file)
@@ -223,7 +223,7 @@ option('status-unit-format-default', type : 'combo',
 option('time-epoch', type : 'integer', value : 0,
        description : 'time epoch for time clients')
 option('clock-valid-range-usec-max', type : 'integer', value : 473364000000000, # 15 years
-       description : 'maximum value in microseconds for the difference between RTC and epoch, exceeding which is considered an RTC error')
+       description : 'maximum value in microseconds for the difference between RTC and epoch, exceeding which is considered an RTC error ["0" disables]')
 option('default-user-shell', type : 'string', value : '/bin/bash',
        description : 'default interactive shell')
 
index eb6f12a2556b028d29a1d234e344bc7d8e026503..a4c00d713e3887dd8aca49fbc490b6b5673bfb23 100644 (file)
@@ -153,7 +153,7 @@ int clock_apply_epoch(ClockChangeDirection *ret_attempted_change) {
         now_usec = now(CLOCK_REALTIME);
         if (now_usec < epoch_usec)
                 *ret_attempted_change = CLOCK_CHANGE_FORWARD;
-        else if (now_usec > usec_add(epoch_usec, CLOCK_VALID_RANGE_USEC_MAX))
+        else if (CLOCK_VALID_RANGE_USEC_MAX > 0 && now_usec > usec_add(epoch_usec, CLOCK_VALID_RANGE_USEC_MAX))
                 *ret_attempted_change = CLOCK_CHANGE_BACKWARD;
         else {
                 *ret_attempted_change = CLOCK_CHANGE_NOOP;