diff options
author | Ermal <eri@pfsense.org> | 2013-09-04 10:36:15 +0000 |
---|---|---|
committer | Ermal <eri@pfsense.org> | 2013-09-04 10:36:15 +0000 |
commit | b8b78b9ad92f84e49e8cb73778ad3764b0cad291 (patch) | |
tree | d4b4a6cfaf981b4934b33031d60f55df9ffa2f1b /usr | |
parent | 8171a2c2de98c8f505e99ddfb4859058cdb32cba (diff) | |
download | pfsense-b8b78b9ad92f84e49e8cb73778ad3764b0cad291.zip pfsense-b8b78b9ad92f84e49e8cb73778ad3764b0cad291.tar.gz |
Related to Ticket #3045 avoid races in the ntpdate_sync_one script due to killall returning without the process really exiting.
Diffstat (limited to 'usr')
-rwxr-xr-x | usr/local/sbin/ntpdate_sync_once.sh | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/usr/local/sbin/ntpdate_sync_once.sh b/usr/local/sbin/ntpdate_sync_once.sh index ebe33b5..4ba46aa 100755 --- a/usr/local/sbin/ntpdate_sync_once.sh +++ b/usr/local/sbin/ntpdate_sync_once.sh @@ -3,14 +3,25 @@ NOTSYNCED="true" MAX_ATTEMPTS=3 SERVER=`/bin/cat /cf/conf/config.xml | /usr/bin/grep timeservers | /usr/bin/cut -d">" -f2 | /usr/bin/cut -d"<" -f1` +if [ "${SERVER}" = "" ]; then + exit +fi + /bin/pkill -f ntpdate_sync_once.sh ATTEMPT=1 # Loop until we're synchronized, but for a set number of attempts so we don't get stuck here forever. while [ "$NOTSYNCED" = "true" ] && [ ${ATTEMPT} -le ${MAX_ATTEMPTS} ]; do # Ensure that ntpd and ntpdate are not running so that the socket we want will be free. - /usr/bin/killall ntpd 2>/dev/null - /usr/bin/killall ntpdate 2>/dev/null + while [ true ]; do + /usr/bin/killall ntpdate 2>/dev/null + /bin/pgrep ntpd + if [ $? -eq 0 ]; then + /usr/bin/killall ntpd 2>/dev/null + else + break + fi + done sleep 1 /usr/local/bin/ntpdate -s -t 5 ${SERVER} if [ "$?" = "0" ]; then |