[systemd-devel] [RFC][systemd]: Patch for src/basic/time-util.c that causes the timestamp for /run/systemd/systemd-units-load to reset to epoch.

Arijit Kumar Das arijitkdgit.official at gmail.com
Mon Mar 24 10:58:47 UTC 2025


Hello systemd community,

I am an undergraduate student working on a fix for an epoch timestamp issue
in /run/systemd/systemd-units-load that occurs on devices lacking a
hardware RTC (e.g., Raspberry Pi). Due to my current setup limitations, I
am unable to build and test systemd with this patch, so I would appreciate
feedback on its correctness.

***** Problem description *****
The issue is that the function now() and now_nsec() rely on clock_gettime()
to fetch the RTC timestamp. This works, but on aforementioned devices
clock_gettime() returns an epoch timestamp when called at the earliest boot
stage when systemd has just initialized itself and no time synchronization
services have been loaded yet. Such a call is made from src/core/manager.c
in function manager_ready() where the file /run/systemd/systemd-units-load
is created and its timestamp is set using now(), giving the file an
extremely old timestamp instead of the actual realtime value. This causes
issues with utilities such as mount (which relies on the modification time
of /run/systemd/systemd-units-load to track changes to /etc/fstab) where a
warning is issued every reboot unless systemd daemon-reload is run.

***** Proposed fix *****
My patch creates three additional functions:

   - static usec_t get_timesyncd_clock_timestamp(void): returns the
   modification time of /var/lib/systemd/timesync/clock, or USEC_INFINITY on
   failure;
   - static usec_t get_journald_lastlog_timestamp(void): returns the last
   log timestamp from journald, or USEC_INFINITY on failure;
   - static usec_t get_recent_timestamp(void): returns one result from
   either of the above two functions, with preference to the timesyncd
   timestamp, before falling back to the epoch timestamp.

The functions now() and now_nsec() have also been modified to use the
timestamp returned by get_recent_timestamp() when clock_id ==
CLOCK_REALTIME. The system time is not modified in any of the functions,
though this may be implemented if deemed necessary by the maintainers.

Although this patch doesn't resolve the issue that now() and now_nsec()
return an incorrect time during early boot, it mitigates the problem by
modifying them to return a more recent value instead. This should remove
the false warning produced by mount and other similar programs relying on
/run/systemd/systemd-units-load.

*****  Request for feedback *****
I’d appreciate it if you could inspect my code and provide feedback on its
correctness. Please let me know if any refinements are needed.

Patch file has been attached.

Best regards,
Arijit Kumar Das
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20250324/2dcae72d/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fixed-an-issue-in-time-util.c-where-the-timestamp-of.patch
Type: text/x-diff
Size: 5917 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20250324/2dcae72d/attachment.patch>


More information about the systemd-devel mailing list