Modify

Opened 8 years ago

Closed 6 years ago

Last modified 4 years ago

#7054 closed defect (obsolete)

busybox 1.16.1 rdate won't sync time

Reported by: anonymous Owned by: thepeople
Priority: normal Milestone: Barrier Breaker 14.07
Component: packages Version: Trunk
Keywords: Cc:

Description

Hi,

fresh build of trunk doesn't sync time on boot up.

OpenWrt user.notice rdate: Failed to sync with ac-ntp1.net.cmu.edu
OpenWrt user.notice rdate: Failed to sync with ptbtime1.ptb.de
...

Only working by manual do '/etc/network restart'.

Attachments (0)

Change History (6)

comment:1 Changed 8 years ago by thepeople

  • Owner changed from developers to thepeople
  • Status changed from new to assigned

comment:2 Changed 8 years ago by pverda@…

Not all the servers in /etc/config/system are still working. The following ones no longer serve the rfc868 time protocol: ac-ntp0.net.cmu.edu, ptbtime1.ptb.de, ac-ntp1.net.cmu.edu and ptbtime3.ptb.de.

There is also a flaw in the randomness of the function in /etc/hotplug.d/iface/40-rdate. If a timeserver rejects a packet the random function does get called very likely in the same second as the first time it got called. The seed will then be the same and thereby the generated random value also. This leads to the selection of the same timeserver. Further, if a user disconnects the power supply in order to stop the router the script /etc/rc.d/K95luci_fixtime doesn't run. The seed of the random function in the script 40-rdate will then be the uptime in seconds plus a constant. This leads to the same timeserver being selected every time between boots. Would it not be better to simply take the pid of the last executed program. The pid of udhcpc varies with every reboot. This means that the pids of the programs running in the script 40-rdate will vary accordingly. The pid of the last running program (busybox) can be obtained from:

SEED=$( pidof busybox | cut -f 1 -d ' ' )

And then a random value between 1 and 10 can be generated with:

echo $(( $SEED %10 + 1 ))

comment:3 Changed 7 years ago by florian

Can you check if this got fixed with the update to busybox 1.17?

comment:4 Changed 7 years ago by pverda@…

It is not necessary to check this because the error is not due to busybox. Busybox worked exactly the way it should. The problem is in the rand() function of the script /etc/hotplug.d/iface/40-rdate. That is: the pseudo random function generator in awk gets called with the same seed.

I have written another 40-rdate script. It goes like this:

sync_rdate()
{
	local servers=`uci -q get system.@rdate[0].server`
	local number=`echo $servers | wc -w`
	local serial=$$
	local remain=$number
	local index
	local server

	while [ $remain != 0 ]; do
		let "index = serial % number + 1"
		server=`echo $servers | cut -f $index -d ' '`
		if rdate -s $server >/dev/null 2>&1; then
			logger -t rdate "Synced with $server"
			return
		fi
		logger -t rdate "Failed to sync with $server"
		let "remain = remain - 1"
		let "serial = serial + 1"
	done

	logger -t rdate "No usable time server found"
}

case "$ACTION" in
	ifup) route -n | grep -q ^0.0.0.0 && sync_rdate;;
esac

The script will pick a timeserver (based on the PID of this script) from the list of timeservers. If this server fails then next one will be tried. This goes on until all servers have been tested.
In this script the usage of the timeservers which are provided via the network is dropped because they are most likely to be ntpservers which are unsuitable for rdate.

comment:5 Changed 6 years ago by nbd

  • Resolution set to obsolete
  • Status changed from assigned to closed

ntpd is used now

comment:6 Changed 4 years ago by jow

  • Milestone changed from Attitude Adjustment 12.09 to Barrier Breaker 14.07

Milestone Attitude Adjustment 12.09 deleted

Add Comment

Modify Ticket

Action
as closed .
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.