<div dir="auto">Hello systemd community,<div dir="auto"><br></div><div dir="auto">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.</div><div dir="auto"><br></div><div dir="auto">***** Problem description *****</div><div dir="auto">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.</div><div dir="auto"><br></div><div dir="auto">***** Proposed fix *****</div><div dir="auto">My patch creates three additional functions:</div><div dir="auto"><ul><li>static usec_t get_timesyncd_clock_timestamp(void): returns the modification time of /var/lib/systemd/timesync/clock, or USEC_INFINITY on failure;</li><li>static usec_t get_journald_lastlog_timestamp(void): returns the last log timestamp from journald, or USEC_INFINITY on failure;</li><li>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.</li></ul>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.</div><div dir="auto"><br></div><div dir="auto">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.<br><br></div><div dir="auto">*****  Request for feedback *****</div><div dir="auto">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.</div><div dir="auto"><br></div><div dir="auto">Patch file has been attached.</div><div dir="auto"><br></div><div dir="auto">Best regards,  </div><div dir="auto">Arijit Kumar Das</div></div>