[systemd-devel] [PATCH] Add timesync-wait tool

Lennart Poettering lennart at poettering.net
Thu Oct 23 15:28:37 PDT 2014


On Thu, 23.10.14 21:24, Łukasz Stelmach (stlman at poczta.fm) wrote:

> +int main(int argc, char *argv[]) {
> +        struct timex tbuf;
> +        int r;
> +
> +        memset(&tbuf, 0, sizeof(tbuf));

Please initialize this with "= {}" while declaring, instead of using
memset() here.

> +        r = adjtimex(&tbuf);
> +
> +        while (r != TIME_OK) {

This check looks wrong. Should check for tbuf.status & STA_UNSYNC, no? 

Also, we already have the ntp_synced() call for doing this. 

> +                sleep(1);
> +                /* Unfortunately there seem to be no other way than
> +                polling to get this information. */
> +                memset(&tbuf, 0, sizeof(tbuf));

In this case, use zero(), it's nicer, simpler and less error prone.

> +                r = adjtimex(&tbuf);
> +        }

Implementing this with a sleep loop is really ugly. Can't we at least
calculate the expected sync time from the data returned by adjtimex()?

The same way as network-wait-online has a timeout this tool should
probably have one too.

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list