0
0
mirror of https://github.com/libretro/Lakka-LibreELEC.git synced 2025-03-01 13:51:22 +00:00

wait-time-sync: new package to reliable detect ntp synchronized system time

This commit is contained in:
mglae
2020-06-10 23:46:03 +02:00
parent 423f3bd56d
commit b38318f8a1
4 changed files with 78 additions and 0 deletions
packages/sysutils/wait-time-sync

@ -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
}

@ -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

@ -0,0 +1,23 @@
/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright (C) 2020-present Team LibreELEC (https://libreelec.tv) */
#include <sys/timex.h>
#include <unistd.h>
#include <errno.h>
int main()
{
int rc;
for (;;)
{
struct timex tx = {};
rc = adjtimex(&tx);
if (rc != TIME_ERROR)
break;
usleep(1000000U/3);
}
return rc == -1 ? errno : 0;
}

@ -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