coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug#682969: timeout 20 /usr/sbin/ntpd -g -q gives wrong return code


From: Goswin von Brederlow
Subject: Re: Bug#682969: timeout 20 /usr/sbin/ntpd -g -q gives wrong return code
Date: Wed, 1 Aug 2012 11:13:46 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

On Fri, Jul 27, 2012 at 07:19:35PM +0100, Pádraig Brady wrote:
> On 07/27/2012 05:56 PM, Jim Meyering wrote:
> > Goswin von Brederlow wrote:
> >> Package: coreutils
> >> Version: 8.13-3.2
> >> Severity: normal
> >> File: /usr/bin/timeout
> >>
> >> I'm trying to set the time during boot. Unfortunately ntpd hangs forever
> >> if the timeserver is unavailable. So I added a timeout to it so the
> >> system still continues to boot without the correct time.
> >>
> >> But I would like to log the error. Timeout is supposed to return 124 if the
> >> time was exceeded. But if ntpd corrects the time by more than the timeout
> >> then the return value is 124 despite the fact the real time passed was 
> >> less.
> >>
> >> Wouldn't it be possible to detect this case and return the exit code of
> >> ntpd instead of a false timeout error?
> > 
> > Thanks for the report.
> > Did you experience an actual problem?

I got a timeout message:

----------------------------------------------------------------------
SERVER=$(grep "^server" /etc/ntp.conf | cut -d" " -f2-)

ERR=124
COUNT=0

while [ $ERR = 124 ]; do
  ERR=0
  if [ $COUNT -gt 0 ]; then
    echo >/dev/console "[$COUNT] Timeout from ntp server ($SERVER), still 
trying ..."
  fi
  COUNT=$((COUNT+1))
  timeout 10 /usr/sbin/ntpd -g -q || ERR=$?
  if grep -q no-ntp /proc/cmdline; then
    break;
  fi
done
----------------------------------------------------------------------

At boot the loop did run twice and print a timeout message.

> > When I try to trigger such misbehavior, timeout seems to work fine
> > on a system (Fedora 17) with a working timer_settime function:
> > 
> >     $ timeout 2 date --set=$(LC_ALL=C date -d 10\ sec +@%s); echo $?
> >     0
> > 
> > I.e., when timeout's child terminates, the clock says
> > 10 seconds have elapsed, yet it exits 0, because the
> > duration was less than 2 seconds.
> > 
> > I'm using the timeout from coreutils-8.17, but nothing
> > has changed in this area since before 8.13.
> > 
> > I even rebuilt my timeout binary, simulating no timer_settime
> > function so that it would take the alarm-using path.  Same result.
> 
> Note timeout(1) currently uses timer_create(CLOCK_REALTIME).
> That could jump and cause signals to fire.
> Though I can't reproduce here, even when pushing the
> updated system clock down to the hardware:
> 
> # timeout 3 sh -c 'date --set=$(LC_ALL=C date -d 10\ sec +@%s); hwclock -w; 
> sleep 1'
> # echo $?
> 0

Does ntpd -g -q use a different method to adjust time compared to
date? I know normaly ntpd adjust the time gradually so time doesn't
jump. But not -q. Also this was inside kvm. Maybe the clock behaves
differently there too.

If it isn't that then maybe I'm just overestimating the speed of ntpd
and it actually takes too long under load with cold caches:

beo-04:~# date --set=$(LC_ALL=C date -d -1000\ sec +@%s)
Wed Aug  1 10:42:35 CEST 2012
beo-04:~# timeout 10 ntpd -g -q; echo $?
ntpd: time set +1000.683261s
0

So I can't reproduce the bug myself on a booted system.

Must have been a strange timeing so that ntpd did just manage to set
the time and print its message within the timeout but not enough time
to actualy exit. Sorry for the noise.

> I was wondering about using CLOCK_MONOTONIC instead,
> though I'd need to test how that functions over a suspend/resume.
> I suspect it only counts up while the system is running.
> Maybe we should default to system running time, rather than
> wall clock time, though then we'd have to look at/document
> the inconsistency on systems without CLOCK_MONOTONIC.
> 
> Goswin what's the output from uname -a
> as a matter of interest?
> 
> cheers,
> Pádraig.

Linux beo-04 2.6.32.59-ql-nfsroot-42 #1 SMP Mon Jul 23 16:55:30 CEST 2012 
x86_64 GNU/Linux

Any kernel options that would affect this?

MfG
        Goswin



reply via email to

[Prev in Thread] Current Thread [Next in Thread]