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

Ronny Chevalier chevalier.ronny at gmail.com
Thu Oct 23 15:58:33 PDT 2014


2014-10-23 21:24 GMT+02:00 Łukasz Stelmach <stlman at poczta.fm>:
> ---
>  src/timesync/timesync-wait.c | 43 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 43 insertions(+)
>  create mode 100644 src/timesync/timesync-wait.c
>
> I am afraid TFD_TIMER_CANCEL_ON_SET doesn't help much here. You can
> watch for time changes but it is not the moment adjtimex() starts to
> return TIME_OK and STA_UNSYNC flag unset.
>
> Where would you like this to be patched in?
>
> diff --git a/src/timesync/timesync-wait.c b/src/timesync/timesync-wait.c
> new file mode 100644
> index 0000000..9648b09
> --- /dev/null
> +++ b/src/timesync/timesync-wait.c
> @@ -0,0 +1,43 @@
> +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
> +
> +/***
> +  This file is part of systemd.
> +
> +  Copyright 2014 Łukasz Stelmach
> +
> +  systemd is free software; you can redistribute it and/or modify it
> +  under the terms of the GNU Lesser General Public License as published by
> +  the Free Software Foundation; either version 2.1 of the License, or
> +  (at your option) any later version.
> +
> +  systemd is distributed in the hope that it will be useful, but
> +  WITHOUT ANY WARRANTY; without even the implied warranty of
> +  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> +  Lesser General Public License for more details.
> +
> +  You should have received a copy of the GNU Lesser General Public License
> +  along with systemd; If not, see <http://www.gnu.org/licenses/>.
> +***/
> +
> +#include <string.h>
> +#include <sys/timex.h>
> +#include <unistd.h>
> +#include <stdio.h>
> +
> +int main(int argc, char *argv[]) {
You should add a minimal parse_argv() like
systemd-networkd-wait-online in order to handle --help and --version,
like all systemd binaries.

> +        struct timex tbuf;
> +        int r;
> +
> +        memset(&tbuf, 0, sizeof(tbuf));
> +        r = adjtimex(&tbuf);
> +
> +        while (r != TIME_OK) {
> +                sleep(1);
> +                /* Unfortunately there seem to be no other way than
> +                polling to get this information. */
> +                memset(&tbuf, 0, sizeof(tbuf));
> +                r = adjtimex(&tbuf);
> +        }
> +
> +        return 0;
> +}
> --
> 2.0.4
You should add the .service and a minimal man-page for this tool.

Also, you should add a little summary in the commit message explaining
why this is needed and/or a link to the discussion:
http://lists.freedesktop.org/archives/systemd-devel/2014-October/024346.html


More information about the systemd-devel mailing list