diff options
author | jow <jow@3c298f89-4303-0410-b956-a3cf2f4a3e73> | 2010-03-27 17:13:33 +0000 |
---|---|---|
committer | jow <jow@3c298f89-4303-0410-b956-a3cf2f4a3e73> | 2010-03-27 17:13:33 +0000 |
commit | 1ac5ad687b35793ca0563d7cb9a4ce59e314a483 (patch) | |
tree | 5ea210b471db86e04135159e5ef7f40d3eb083da /package/base-files | |
parent | 2dde85630069fe4e531ce5c8bd41aeb7f5c00222 (diff) |
[package] base-files: add a hotplug handler for rdate
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@20518 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package/base-files')
-rw-r--r-- | package/base-files/Makefile | 2 | ||||
-rw-r--r-- | package/base-files/files/etc/config/system | 9 | ||||
-rw-r--r-- | package/base-files/files/etc/hotplug.d/iface/40-rdate | 46 |
3 files changed, 56 insertions, 1 deletions
diff --git a/package/base-files/Makefile b/package/base-files/Makefile index 88ab610187..856340f667 100644 --- a/package/base-files/Makefile +++ b/package/base-files/Makefile @@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk include $(INCLUDE_DIR)/kernel.mk PKG_NAME:=base-files -PKG_RELEASE:=40 +PKG_RELEASE:=41 PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/ diff --git a/package/base-files/files/etc/config/system b/package/base-files/files/etc/config/system index b0726b7b7b..3f121bd4d3 100644 --- a/package/base-files/files/etc/config/system +++ b/package/base-files/files/etc/config/system @@ -1,3 +1,12 @@ config system option hostname OpenWrt option timezone UTC + +config rdate + list server ac-ntp0.net.cmu.edu + list server ptbtime1.ptb.de + list server ac-ntp1.net.cmu.edu + list server ntp.xs4all.nl + list server ptbtime2.ptb.de + list server cudns.cit.cornell.edu + list server ptbtime3.ptb.de diff --git a/package/base-files/files/etc/hotplug.d/iface/40-rdate b/package/base-files/files/etc/hotplug.d/iface/40-rdate new file mode 100644 index 0000000000..cf56c02ac5 --- /dev/null +++ b/package/base-files/files/etc/hotplug.d/iface/40-rdate @@ -0,0 +1,46 @@ +uci_get_one() +{ + for var in "$@"; do + uci -P /var/state get "$var" 2>/dev/null && break + done +} + +rand() +{ + random=$(awk 'BEGIN { srand(); print int(rand() * 10 + 1); }') +} + +sync_rdate() +{ + local servers=$(uci_get_one "network.$INTERFACE.lease_timesrv" \ + "system.@rdate[0].server") + + if [ -n "$servers" ]; then + match=0 + tries=3 + rand + + while [ $match = 0 ] && [ $tries != 0 ]; do + for server in $servers; do + if [ $((--random)) = 0 ]; then + rdate -s $server >/dev/null 2>/dev/null && { + logger -t rdate "Synced with $server" + match=1 + } || { + logger -t rdate "Failed to sync with $server" + let tries="$tries - 1" + rand + } + + break + fi + done + done + else + logger -t rdate "No usable time server found" + fi +} + +case "$ACTION" in + ifup) route -n | grep -q ^0.0.0.0 && sync_rdate;; +esac |