<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Aug 17, 2022 at 1:59 PM Etienne Doms <<a href="mailto:etienne.doms@gmail.com">etienne.doms@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
I'm developing an application for an embedded system that needs to<br>
wait for proper NTP synchronization. systemd-timesyncd is running and<br>
I can read NTPSynchronized from /org/freedesktop/timedate1 using<br>
D-Bus. I read in the manual that this property is not signaled, and<br>
that I need to do some weird magic with timerfd's<br>
TFD_TIMER_CANCEL_ON_SET flag.<br>
<br>
It works, but having the ECANCELLED on the read() means that something<br>
somewhere did clock_settime(CLOCK_REALTIME, <...>), not especially<br>
that I got a proper NTP synchronization. Then, I still need to query<br>
NTPSynchronized after, and retry the timerfd thing if it didn't switch<br>
to "true", which is still some kind of polling (but very unlikely,<br>
sure).<br>
<br>
As a result, I'm a bit curious, what was the rationale of not simply<br>
signaling NTPSynchronized?<br></blockquote><div><br></div><div>timedated itself doesn't have knowledge of that event, because it isn't the daemon that performs actual synchronization (that's timesyncd), so all that the D-Bus property does is report you the status of <span style="font-family:monospace">adjtimex()</span> – specifically it returns whether "<span style="font-family:monospace">.maxerror < 16000000</span>". Timedated would still need to poll and/or do timerfd tricks in order to see that state being reached. (Currently timedated is not a continuously running daemon – it starts up only whenever properties are queried and exits when idle.) </div><div><br></div><div></div><div>A better question is why the timesyncd daemon does not have such a D-Bus signal; looks like it *almost* does (org.freedesktop.timesync1.Manager.NTPMessage) but it looks like it only emits the raw messages and not whether they resulted in a successful sync.</div><div><br></div><div>For now, if you're using timesyncd you can use inotify to watch <span style="font-family:monospace">/run/systemd/timesync/synchronized</span>, which is touched after a sync.<br></div></div><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">Mantas Mikulėnas</div></div></div>