How to intercept the time change event

Hello,

I would like to know how to intercept the time change event in systemd.


with

journalctl --since="today"

I could see that systemd call some services when time is set:

Jan 01 01:00:43 beaglebone connmand[128]: ntp: time slew +439068426.471130 s
. . .
Nov 29 20:27:50 beaglebone systemd[1]: Time has been changed
Nov 29 20:27:50 beaglebone systemd[1]: cpu-ondemand.timer: time change, recalculating next elapse.
Nov 29 20:27:50 beaglebone systemd[1]: systemd-tmpfiles-clean.timer: time change, recalculating next elapse.
Nov 29 20:27:50 beaglebone connmand[128]: connmand[128]: Setting hostname to beaglebone
. . .

How to add new services on time change ? I would like to set a hardware clock automatically.

I searched through the systemd codebase and found that they use this call to set up a file_descriptor that can be monitored for jumps between the system time and the monotonic time.

http://linux.die.net/man/2/timerfd_create

You can look up the “manger.c” file in the systemd codebase and look at the manager_setup_time_change() function (line 252) to see what they are doing
http://cgit.freedesktop.org/systemd/systemd/tree/src/core/manager.c

Thanks Michael,

It’s harder than what I think.

I will try this, but I need to be more skilled on Linux C programming.

Regards