From d142c8df78d029d9714e5e7fb367b05696dcb302 Mon Sep 17 00:00:00 2001 From: mglae Date: Wed, 10 Jun 2020 23:46:03 +0200 Subject: [PATCH 1/2] wait-time-sync: new package to reliable detect ntp synchronized system time --- packages/sysutils/wait-time-sync/package.mk | 15 ++++++++++ .../sysutils/wait-time-sync/sources/Makefile | 12 ++++++++ .../wait-time-sync/sources/wait-time-sync.c | 23 +++++++++++++++ .../system.d/wait-time-sync.service | 28 +++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 packages/sysutils/wait-time-sync/package.mk create mode 100644 packages/sysutils/wait-time-sync/sources/Makefile create mode 100644 packages/sysutils/wait-time-sync/sources/wait-time-sync.c create mode 100644 packages/sysutils/wait-time-sync/system.d/wait-time-sync.service diff --git a/packages/sysutils/wait-time-sync/package.mk b/packages/sysutils/wait-time-sync/package.mk new file mode 100644 index 0000000000..b45468f08b --- /dev/null +++ b/packages/sysutils/wait-time-sync/package.mk @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2020-present Team LibreELEC (https://libreelec.tv) + +PKG_NAME="wait-time-sync" +PKG_VERSION="1.0" +PKG_LICENSE="GPL" +PKG_SITE="" +PKG_URL="" +PKG_DEPENDS_TARGET="toolchain" +PKG_LONGDESC="A simple tool and systemd service to wait until NTP time is synced" + + +post_install() { + enable_service wait-time-sync.service +} diff --git a/packages/sysutils/wait-time-sync/sources/Makefile b/packages/sysutils/wait-time-sync/sources/Makefile new file mode 100644 index 0000000000..1014a4452e --- /dev/null +++ b/packages/sysutils/wait-time-sync/sources/Makefile @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2020-present Team LibreELEC (https://libreelec.tv) + +.PHONY: all +all: wait-time-sync + +PREFIX = /usr + +.PHONY: install +install: wait-time-sync + install -d $(DESTDIR)$(PREFIX)/bin + install $< $(DESTDIR)$(PREFIX)/bin diff --git a/packages/sysutils/wait-time-sync/sources/wait-time-sync.c b/packages/sysutils/wait-time-sync/sources/wait-time-sync.c new file mode 100644 index 0000000000..52cd5d780a --- /dev/null +++ b/packages/sysutils/wait-time-sync/sources/wait-time-sync.c @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2020-present Team LibreELEC (https://libreelec.tv) */ + +#include +#include +#include + +int main() +{ + int rc; + + for (;;) + { + struct timex tx = {}; + + rc = adjtimex(&tx); + if (rc != TIME_ERROR) + break; + usleep(1000000U/3); + } + + return rc == -1 ? errno : 0; +} diff --git a/packages/sysutils/wait-time-sync/system.d/wait-time-sync.service b/packages/sysutils/wait-time-sync/system.d/wait-time-sync.service new file mode 100644 index 0000000000..2a875353ea --- /dev/null +++ b/packages/sysutils/wait-time-sync/system.d/wait-time-sync.service @@ -0,0 +1,28 @@ +# SPDX-License-Identifier: LGPL-2.1+ +# +# This file was part of systemd. +# Modified by Team LibreELEC (https://libreelec.tv) +# +# 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. + +[Unit] +Description=Wait For Kernel Time Synchronized + +ConditionVirtualization=!container + +DefaultDependencies=no +Before=time-sync.target shutdown.target +Wants=time-sync.target +Conflicts=shutdown.target + +[Service] +Type=oneshot +ExecStart=/usr/bin/wait-time-sync +TimeoutStartSec=infinity +RemainAfterExit=yes + +[Install] +WantedBy=sysinit.target From 8dca6fefa37dd909e7d13421ffce3c8db87e80a5 Mon Sep 17 00:00:00 2001 From: mglae Date: Wed, 10 Jun 2020 23:46:17 +0200 Subject: [PATCH 2/2] systemd: remove systemd-time-wait-sync and depend on wait-time-sync --- packages/sysutils/systemd/package.mk | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/sysutils/systemd/package.mk b/packages/sysutils/systemd/package.mk index b59f66d53c..a0a146a599 100644 --- a/packages/sysutils/systemd/package.mk +++ b/packages/sysutils/systemd/package.mk @@ -8,7 +8,7 @@ PKG_SHA256="ec22be9a5dd94c9640e6348ed8391d1499af8ca2c2f01109198a414cff6c6cba" PKG_LICENSE="LGPL2.1+" PKG_SITE="http://www.freedesktop.org/wiki/Software/systemd" PKG_URL="https://github.com/systemd/systemd/archive/v$PKG_VERSION.tar.gz" -PKG_DEPENDS_TARGET="toolchain libcap kmod util-linux entropy libidn2" +PKG_DEPENDS_TARGET="toolchain libcap kmod util-linux entropy libidn2 wait-time-sync" PKG_LONGDESC="A system and session manager for Linux, compatible with SysV and LSB init scripts." PKG_MESON_OPTS_TARGET="--libdir=/usr/lib \ @@ -185,6 +185,10 @@ post_makeinstall_target() { # remove networkd safe_remove $INSTALL/usr/lib/systemd/network + # remove systemd-time-wait-sync (not detecting slew time updates, using package wait-time-sync) + safe_remove $INSTALL/usr/lib/systemd/system/systemd-time-wait-sync.service + safe_remove $INSTALL/usr/lib/systemd/systemd-time-wait-sync + # tune journald.conf sed -e "s,^.*Compress=.*$,Compress=no,g" -i $INSTALL/etc/systemd/journald.conf sed -e "s,^.*SplitMode=.*$,SplitMode=none,g" -i $INSTALL/etc/systemd/journald.conf