Signed-off-by: Ted Hess <thess@kitschensync.net>lilik-openwrt-22.03
@ -0,0 +1,57 @@ | |||
# | |||
# Copyright (C) 2006-2014 OpenWrt.org | |||
# | |||
# This is free software, licensed under the GNU General Public License v2. | |||
# See /LICENSE for more information. | |||
# | |||
include $(TOPDIR)/rules.mk | |||
PKG_NAME:=ntpclient | |||
PKG_VERSION:=2010_365 | |||
PKG_RELEASE:=1 | |||
PKG_SOURCE:=$(PKG_NAME)_$(PKG_VERSION).tar.gz | |||
PKG_SOURCE_URL:=http://doolittle.icarus.com/ntpclient/ | |||
PKG_MD5SUM:=a64689398f2df8933ee0d8da246e9eaa | |||
PKG_MAINTAINER:=Ted Hess <thess@kitschensync.net> | |||
PKG_LICENSE:=GPL-2.0 | |||
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-2010 | |||
include $(INCLUDE_DIR)/package.mk | |||
define Package/ntpclient | |||
SUBMENU:=Time Synchronization | |||
SECTION:=net | |||
CATEGORY:=Network | |||
TITLE:=NTP (Network Time Protocol) client | |||
URL:=http://doolittle.icarus.com/ntpclient/ | |||
DEPENDS:=+librt | |||
endef | |||
define Package/ntpclient/description | |||
NTP client for setting system time from NTP servers. | |||
endef | |||
define Package/ntpclient/conffiles | |||
/etc/config/ntpclient | |||
endef | |||
MAKE_FLAGS += \ | |||
all adjtimex | |||
define Package/ntpclient/install | |||
$(INSTALL_DIR) $(1)/etc/hotplug.d/iface | |||
$(INSTALL_DATA) ./files/ntpclient.hotplug $(1)/etc/hotplug.d/iface/20-ntpclient | |||
$(INSTALL_DIR) $(1)/etc/config | |||
$(INSTALL_CONF) ./files/ntpclient.config $(1)/etc/config/ntpclient | |||
$(INSTALL_DIR) $(1)/usr/sbin | |||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/ntpclient $(1)/usr/sbin/ | |||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/adjtimex $(1)/usr/sbin/ | |||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/rate.awk $(1)/usr/sbin/ | |||
endef | |||
$(eval $(call BuildPackage,ntpclient)) |
@ -0,0 +1,23 @@ | |||
config ntpserver | |||
option hostname '0.openwrt.pool.ntp.org' | |||
option port '123' | |||
config ntpserver | |||
option hostname '1.openwrt.pool.ntp.org' | |||
option port '123' | |||
config ntpserver | |||
option hostname '2.openwrt.pool.ntp.org' | |||
option port '123' | |||
config ntpserver | |||
option hostname '3.openwrt.pool.ntp.org' | |||
option port '123' | |||
config ntpdrift | |||
option freq '0' | |||
config ntpclient | |||
option interval 600 | |||
#option count 10 | |||
#option interface wan |
@ -0,0 +1,78 @@ | |||
#!/bin/sh | |||
# Copyright (C) 2006-2014 OpenWrt.org | |||
. /lib/functions.sh | |||
unset SERVER | |||
unset PORT | |||
unset INTERVAL | |||
unset COUNT | |||
unset INTERFACE_GLOBAL | |||
NTPC=`which ntpclient` | |||
check_server() { | |||
local hostname | |||
local port | |||
local interface | |||
[ -n "$SERVER" ] && return | |||
config_get hostname $1 hostname | |||
config_get port $1 port | |||
config_get interface $1 interface | |||
[ -z "$interface" ] && interface=$INTERFACE_GLOBAL | |||
[ -n "$interface" ] && { | |||
# $INTERFACE is passed from hotplug event | |||
[ "$interface" = "$INTERFACE" ] || return | |||
} | |||
[ -z "$hostname" ] && return | |||
$NTPC -c 1 -p ${port:-123} -i 2 -h $hostname > /dev/null && { SERVER=$hostname; PORT=${port:-123}; } | |||
} | |||
set_drift() { | |||
config_get freq $1 freq | |||
[ -n "$freq" ] && adjtimex -f $freq >/dev/null | |||
} | |||
start_ntpclient() { | |||
config_foreach set_drift ntpdrift | |||
config_foreach check_server ntpserver | |||
[ -z "$SERVER" ] && exit 0 | |||
logger starting ntpclient | |||
$NTPC ${COUNT:+-c $COUNT} ${INTERVAL:+-i $INTERVAL} -s -l -D -p $PORT -h $SERVER 2> /dev/null | |||
} | |||
stop_ntpclient() { | |||
logger stopping ntpclient | |||
killall ntpclient | |||
} | |||
load_settings() { | |||
local interval | |||
local count | |||
local iface | |||
config_get interval $1 interval | |||
config_get count $1 count | |||
config_get interface $1 interface | |||
[ -n "$count" ] && COUNT=$count | |||
[ -n "$interval" ] && INTERVAL=$interval | |||
[ -n "$interface" ] && INTERFACE_GLOBAL=$interface | |||
} | |||
config_load ntpclient | |||
config_foreach load_settings ntpclient | |||
NTP_RUNNING=`ps | grep $NTPC | grep -v grep` | |||
case "${ACTION:-ifup}" in | |||
ifup) | |||
[ -z "$NTP_RUNNING" ] && start_ntpclient | |||
;; | |||
ifdown) | |||
[ -n "$NTP_RUNNING" ] && stop_ntpclient | |||
;; | |||
esac |
@ -0,0 +1,22 @@ | |||
--- a/ntpclient.c | |||
+++ b/ntpclient.c | |||
@@ -611,7 +611,7 @@ int main(int argc, char *argv[]) { | |||
ntpc.cross_check=1; | |||
for (;;) { | |||
- c = getopt( argc, argv, "c:" DEBUG_OPTION "f:g:h:i:lp:q:" REPLAY_OPTION "st"); | |||
+ c = getopt( argc, argv, "c:" DEBUG_OPTION "f:g:h:i:lp:q:" REPLAY_OPTION "stD"); | |||
if (c == EOF) break; | |||
switch (c) { | |||
case 'c': | |||
@@ -660,6 +660,10 @@ int main(int argc, char *argv[]) { | |||
(ntpc.cross_check)=0; | |||
break; | |||
+ case 'D': | |||
+ daemon(0, 0); | |||
+ break; | |||
+ | |||
default: | |||
usage(argv[0]); | |||
exit(1); |