[pkg-ntp-maintainers] Bug#731976: ntpdate: Please use flock(1) in /etc/network/if-up.d/ntpdate

Christoph Biedl debian.axhn at manchmal.in-ulm.de
Wed Dec 11 21:26:32 UTC 2013


Package: ntpdate
Version: 1:4.2.6.p5+dfsg-2
Severity: normal
Tags: patch

Dear Maintainer,

the code in /etc/network/if-up.d/ntpdate tries to prevent parallel
excution of ntpdate-debian by perusing the lockfile-progs package. If
this is not installed - and it seldom is here -, the script proceeds
without. Plan B works quite well: The listening port of an ntpdate
process which will cause any second one to fail - unless "-u" has been
added to NTPOPTIONS in /etc/default/ntpdate, which I did for certain
reasons. Then, several ntpdate processes may happily try to correct
the time, causing multiple jumps, like in

Dec 11 21:47:46 host ntpdate[2452]: step time server 192.168.29.1 offset 617.710431 sec
Dec 11 21:47:46 host ntpdate[2432]: step time server 192.168.29.1 offset 617.710419 sec

As a result, the system time was somewhat ten minutes into the future,
additionally causing nasty fsck warnings during the reboot I had to do
a few seconds later.

Here's my suggestion: Use flock(1) instead, provided by the essential
util-linux package thus avaiable everywhere. Also the code is shorter
now. If the semaphore is locked, no second ntpdate process is started
at all, assuming one is good enough.

Regards,

    Christoph

--- /etc/network/if-up.d/ntpdate        2008-07-09 17:23:38.000000000 +0200
+++ /etc/network/if-up.d/ntpdate        2013-12-11 22:08:23.000000000 +0100
@@ -32,18 +32,10 @@

 LOCKFILE=/var/lock/ntpdate

-# Avoid running more than one at a time
-if [ -x /usr/bin/lockfile-create ]; then
-       lockfile-create $LOCKFILE
-       lockfile-touch $LOCKFILE &
-       LOCKTOUCHPID="$!"
-fi
+(
+    flock --exclusive --nonblock 9 || exit 0

-/usr/sbin/ntpdate-debian -s $OPTS 2>/dev/null || :
-
-if [ -x /usr/bin/lockfile-create ] ; then
-       kill $LOCKTOUCHPID
-       lockfile-remove $LOCKFILE
-fi
+    /usr/sbin/ntpdate-debian -s $OPTS 2>/dev/null || :
+) 9>"$LOCKFILE"

 ) &



-- System Information:
Debian Release: 7.2
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 3.10.17 (SMP w/4 CPU cores; PREEMPT)
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages ntpdate depends on:
ii  dpkg         1.16.12
ii  libc6        2.13-38
ii  libssl1.0.0  1.0.1e-2
ii  netbase      5.0

Versions of packages ntpdate recommends:
pn  lockfile-progs  <none>

ntpdate suggests no packages.

-- Configuration Files:
/etc/default/ntpdate changed [not included]

-- no debconf information

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.alioth.debian.org/pipermail/pkg-ntp-maintainers/attachments/20131211/bc6894fc/attachment.sig>


More information about the pkg-ntp-maintainers mailing list