aboutsummaryrefslogtreecommitdiffstats
path: root/package/base-files/files/etc/hotplug.d
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2010-03-27 17:13:33 +0000
committerJo-Philipp Wich <jow@openwrt.org>2010-03-27 17:13:33 +0000
commit63f49e43e62fa70bf8f3aa0a8082cb133a1b82cf (patch)
tree06cc3aa2ed27a4ddad29a6e98d0c1f701958b568 /package/base-files/files/etc/hotplug.d
parent0cdaaa90fe8ff8c6da8b145aa08af1be8cb14a5e (diff)
downloadupstream-63f49e43e62fa70bf8f3aa0a8082cb133a1b82cf.tar.gz
upstream-63f49e43e62fa70bf8f3aa0a8082cb133a1b82cf.tar.bz2
upstream-63f49e43e62fa70bf8f3aa0a8082cb133a1b82cf.zip
base-files: add a hotplug handler for rdate
SVN-Revision: 20518
Diffstat (limited to 'package/base-files/files/etc/hotplug.d')
-rw-r--r--package/base-files/files/etc/hotplug.d/iface/40-rdate46
1 files changed, 46 insertions, 0 deletions
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