mirror of
https://github.com/LibreELEC/LibreELEC.tv.git
synced 2025-07-29 21:56:42 +00:00
wait-time-sync: new package to reliable detect ntp synchronized system time
This commit is contained in:
parent
3d42b3a84c
commit
d142c8df78
15
packages/sysutils/wait-time-sync/package.mk
Normal file
15
packages/sysutils/wait-time-sync/package.mk
Normal file
@ -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
|
||||||
|
}
|
12
packages/sysutils/wait-time-sync/sources/Makefile
Normal file
12
packages/sysutils/wait-time-sync/sources/Makefile
Normal file
@ -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
|
23
packages/sysutils/wait-time-sync/sources/wait-time-sync.c
Normal file
23
packages/sysutils/wait-time-sync/sources/wait-time-sync.c
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user