Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 323685 - net-misc/ntp: sntp does not set system clock
Summary: net-misc/ntp: sntp does not set system clock
Status: RESOLVED NEEDINFO
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: High normal
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-12 15:47 UTC by Jeff Shanab
Modified: 2010-09-23 23:51 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeff Shanab 2010-06-12 15:47:36 UTC
ntp-client which calls sntp now instead of ntpdate, does noting.
ntpdate still works.


Reproducible: Always

Steps to Reproduce:
1.emerge ntp-4.2.6_p1-r1
2.start with a clock that is 30 min off
3.start ntp-client or call sntp from command line


Actual Results:  
error about database every time.
>sntp -s -b -u pool.ntp.org
  Initializing KOD DB...
  KoD DB /var/db/ntp-kod empty.
  2010 Jun 12 08:45:48.964011 +0.040962 +/- 0.021942 secs
  2010 Jun 12 08:45:48.992418 +0.01408 +/- 0.029419 secs

Clock does not set


Expected Results:  
Clock to be set, no database errors
Comment 1 SpanKY gentoo-dev 2010-06-13 00:29:25 UTC
umm, no, ntp-client does not call sntp.  if it does, it's because *you* changed it.  default ntp-client calls ntpdate which works fine.

you need to show the system time as well as the remote time and show that you are correctly within the specified limits.  default ntp behavior does not change clocks when the difference is out of the limits.
Comment 2 Jeff Shanab 2010-06-13 00:40:20 UTC
Please don't resolve without even one response.
 ntpdate is deprecated. and was mentioned in the additional info section.
 I should of been more clear in my steps to reproduce.

This wiki, for example, suggests how to switch
    http://en.gentoo-wiki.com/wiki/NTP

When you do, you discover the problem with sntp, it doesn't work.

ntpdate does work, bug is "sntp does not set system clock"

(In reply to comment #1)
> umm, no, ntp-client does not call sntp.  if it does, it's because *you* changed
> it.  default ntp-client calls ntpdate which works fine.
> 
> you need to show the system time as well as the remote time and show that you
> are correctly within the specified limits.  default ntp behavior does not
> change clocks when the difference is out of the limits.
> 

Comment 3 SpanKY gentoo-dev 2010-06-13 02:21:07 UTC
you said "ntp-client calls sntp now" which is clearly wrong.  ntpdate has been "deprecated" for years and nothing has changed.

we dont maintain random wikis, so i dont really care what it says.  if anything, that wiki says you should use "-r" which you clearly arent.  in fact, i asked for specific information which you still havent shown to indicate that sntp is not working as designed.
Comment 4 SpanKY gentoo-dev 2010-07-18 20:59:38 UTC
re-open once you've provided for the information asked for and you've reviewed the man page.  the client section indicates that what you're showing is correct.

       The default is that it should behave as a  client,  and  the  following
       options are then relevant:

       -r     indicates that the system clock should be reset by settimeofday.
              Naturally, this will work only if the user has enough privilege.

       -a     indicates that the system clock  should  be  reset  by  adjtime.
              Naturally, this will work only if the user has enough privilege.

       The default is to write the estimated correct local date and time (i.e.
       not UTC) to  the  standard  output  in  a  format  like  '1996  Oct  15
       20:17:25.123  +  4.567  +/-  0.089  secs', where the '+ 4.567 +/- 0.089
       secs' indicates the estimated error in the time on the local system.
Comment 5 Fitzcarraldo 2010-09-23 18:22:38 UTC
The sntp man page does not show the -r option any longer; the option is now -s.

The example in the Gentoo Wiki article referred to by the OP also shows a -P (uppercase) option, which also no longer exists.

According to a man page for sntp on the Web the options are:

== BEGIN QUOTE ==
sntp(1) - Linux man page
Name
sntp - a SNTP utility (command and daemon)
Synopsis
sntp [ -h | --help | -? ] [ -v | -V | -W ] [ -q [ -f savefile ] | [ { -r | -a } [ -P prompt ] [ -l lockfile ] ] [ -e minerr ] [ -E maxerr ] [ -c count ] [ -d delay | -x [ separation ] ] [ -f savefile ] ] [ -4 ] | [ -6 ] [ address(es) ] ]
Description

sntp can be used as a SNTP client to query a NTP or SNTP server and either display the time or set the local system's time (given suitable privilege). It can be run as an interactive command, in a cron job or as a daemon. It can be run as a daemon to provide a SNTP server for other clients. NTP is the Network Time Protocol (RFC 1305) and SNTP is the Simple Network Time Protocol (RFC 2030, which supersedes RFC 1769).
Options

sntp recognizes the following options:

-h
    displays the syntax error message. If there are no other arguments, it then stops; otherwise it then does what was requested. --help and -? are synonyms. 
-v
    indicates that diagnostic messages for non-fatal errors and a limited amount of tracing should be written to standard error. Fatal ones always produce a diagnostic. This option should be set when there is a suspected problem with the server, network or the source. 
-V
    requests more and less comprehensible output, mainly for investigating problems with apparently inconsistent timestamps. This option should be set when the program fails with a message indicating that is the trouble. 
-W
    requests very verbose debugging output, and will interfere with the timing when writing to the terminal (because of line buffered output from C). Note that the times produced by this are the corrections needed, and not the error in the local clock. This option should be set only when debugging the source. 
-q
    indicates that it should query a daemon save file being maintained by it. This needs no privilege and will change neither the save file nor the clock.

The default is that it should behave as a client, and the following options are then relevant:

-r
    indicates that the system clock should be reset by settimeofday. Naturally, this will work only if the user has enough privilege. 
-a
    indicates that the system clock should be reset by adjtime. Naturally, this will work only if the user has enough privilege.

The default is to write the estimated correct local date and time (i.e. not UTC) to the standard output in a format like '1996 Oct 15 20:17:25.123 + 4.567 +/- 0.089 secs', where the '+ 4.567 +/- 0.089 secs' indicates the estimated error in the time on the local system. In daemon mode, it will add drift information in a format like ' + 1.3 +/- 0.1 ppm', and display this at roughly separation intervals (see under the -x option for details).

-l lockfile
    sets the name of the lock file to ensure that there is only one copy of sntp running at once. The default is installation-dependent, but will usually be /etc/sntp.pid. 
-e minerr
    sets the maximum ignorable variation between the clocks to minerr. Acceptable values are from 0.001 to 1, and the default is 0.1 if a NTP host is is specified and 0.5 otherwise. 
-E maxerr
    sets the maximum value of various delays that are deemed acceptable to maxerr. Acceptable values are from 1 to 60, and the default is 5. It should sometimes be increased if there are problems with the network, NTP server or system clock, but take care. 
-P prompt
    sets the maximum clock change that will be made automatically to maxerr. Acceptable values are from 1 to 3600 or no, and the default is 30. If the program is being run interactively in ordinary client mode, and the system clock is to be changed, larger corrections will prompt the user for confirmation. Specifying no will disable this and the correction will be made regardless. 
-c count
    sets the maximum number of NTP packets required to count. Acceptable values are from 1 to 25 if a NTP host is specified and from 5 to 25 otherwise, and the default is 5. If the maximum isn't enough, the system needs a better consistency algorithm than this program uses. 
-d delay
    sets a rough limit on the total running time to delay seconds. Acceptable values are from 1 to 3600, and the default is 15 if a NTP host is specified and 300 otherwise. 
-x separation
    causes the program to run as a daemon (i.e. forever), and to estimate and correct for the clock drift. separation sets the minimum time between calls to the server in minutes if a NTP host is specified, and between broadcast packets if not. Acceptable values are from 1 to 1440 (a day), and the default (if -x is specified but separation is omitted) is 300. 
-f savefile
    may be used with the -x option to store a record of previous packets, which speeds up recalculating the drift after sntp has to be restarted (e.g. because of network or server outages). In order to restart the data, sntp must be restarted reasonably soon after it died (within a few times the value of separation), with the same value of the -c option, the same value of separation, in the same mode (i.e. broadcast or client), though the NTP servers need not be the same for client mode, and with compatible values of other settings. Note that the file will be created with the default ownerships and permissions, using standard C facilities. The default is installation-dependent, but will usually be /etc/sntp.state. 
-4
    force IPv4 DNS resolution. 
-6
    force IPv6 DNS resolution.

address(es) are the DNS names or IP numbers of hosts to use for the challenge and response protocol; if no names are given, the program waits for broadcasts. Polling a server is vastly more reliable than listening to broadcasts. Note that a single component numeric address is not allowed, to avoid ambiguities. If more than one name is give, they will be used in a round-robin fashion.
== END QUOTE ==


However the version of sntp installed via net-misc/ntp-4.2.6_p2-r1 has different parameters:

== BEGIN QUOTE ==
# sntp --help
sntp - standard SNTP program - Ver. 4.2.6p2
USAGE:  sntp [ -<flag> [<val>] | --<name>[{=| }<val>] ]... hostname-or-IP ...
  Flg Arg Option-Name    Description
   -4 no  ipv4           Force IPv4 DNS name resolution
                                - prohibits these options:
                                ipv6
   -6 no  ipv6           Force IPv6 DNS name resolution
                                - prohibits these options:
                                ipv4
   -d no  normalverbose  Normal verbose
   -K Str kod            KoD history filename
   -p no  syslog         Logging with syslog
                                - prohibits these options:
                                filelog
   -l Str filelog        Log to specified logfile
                                - prohibits these options:
                                syslog
   -s no  settod         Set (step) the time with settimeofday()
                                - prohibits these options:
                                adjtime
   -j no  adjtime        Set (slew) the time with adjtime()
                                - prohibits these options:
                                settod
   -b Str broadcast      Use broadcasts to the address specified for synchronisation
   -t Num timeout        Specify the number of seconds to wait for broadcasts
   -a Num authentication Enable authentication with the key auth-keynumber
   -k Str keyfile        Specify a keyfile. SNTP will look in this file for the key specified with -a
      opt version        Output version information and exit
   -? no  help           Display extended usage information and exit
   -! no  more-help      Extended usage information passed thru pager
   -> opt save-opts      Save the option state to a config file
   -< Str load-opts      Load options from a config file
                                - disabled as --no-load-opts
                                - may appear multiple times

Options are specified by doubled hyphens and their name
or by a single hyphen and the flag character.

The following option preset mechanisms are supported:
 - reading file /root/.ntprc
 - reading file /home/fitzcarraldo/.ntprc
 - examining environment variables named SNTP_*

.I sntp
implements the Simple Network Time Protocol, and is used
to query an NTP or SNTP server and either
display the time
or
set the local system's time (given suitable privilege).

It can be
run interactively from the command line or as a
.I cron
job.

NTP and SNTP are defined by draft-ietf-ntp-ntpv4-proto-13, which
obsoletes RFC 4330 and RFC 1305.

please send bug reports to:  http://bugs.ntp.org, bugs@ntp.org
== END QUOTE ==


Notice that it mentions a file ~/.ntprc for option presets. Is that correct for Gentoo?

Also, without the -P option it is not possible to use "-P no" to force a time change to the system clock regardless of the difference between the system clock and the NTP/SNTP server.

Here's the result of a test I have just performed:

# cat sntp_test.sh 
echo "check system clock using date command:"
date
echo "set time back by roughly one minute:"
date 092319092010
echo "use sntp -s 0.gentoo.pool.ntp.org command to sync system clock with remote NTP server:"
sntp -s 0.gentoo.pool.ntp.org
echo "check system clock using date command"
date
echo "now sync system clock with remote NTP client using ntpdate in net-client init-script:"
/etc/init.d/ntp-client restart
echo "check system clock using date command:"
date
# 
#
#
# date
Thu Sep 23 19:09:57 BST 2010
# sh sntp_test.sh
check system clock using date command:
Thu Sep 23 19:10:03 BST 2010
set time back by roughly one minute:
Thu Sep 23 19:09:00 BST 2010
use sntp -s 0.gentoo.pool.ntp.org command to sync system clock with remote NTP server:
Initializing KOD DB...
KoD DB /var/db/ntp-kod empty.
2010 Sep 23 19:09:00.556673 +0.027442 +/- 0.031921 secs
2010 Sep 23 19:09:00.616662 +0.02990
2010 Sep 23 19:09:00.718398 +0.05079
check system clock using date command
Thu Sep 23 19:09:00 BST 2010
now sync system clock with remote NTP client using ntpdate in net-client init-script:
* Setting clock via the NTP client 'ntpdate'...                                                                                                                                 [ ok ]
check system clock using date command:
Thu Sep 23 19:10:15 BST 2010
#


Now the same test but with NTPD_OPTS="-g" in the /etc/conf.d/ntpd file:

# cat sntp_test.sh 
echo "check system clock using date command:"
date
echo "set time back by roughly one minute:"
date 092319142010
echo "use sntp -s 0.gentoo.pool.ntp.org command to sync system clock with remote NTP server:"
sntp -s 0.gentoo.pool.ntp.org
echo "check system clock using date command"
date
echo "now sync system clock with remote NTP client using ntpdate in net-client init-script:"
/etc/init.d/ntp-client restart
echo "check system clock using date command:"
date
# 
# 
# sh sntp_test.sh
check system clock using date command:
Thu Sep 23 19:15:09 BST 2010
set time back by roughly one minute:
Thu Sep 23 19:14:00 BST 2010
use sntp -s 0.gentoo.pool.ntp.org command to sync system clock with remote NTP server:
Initializing KOD DB...
KoD DB /var/db/ntp-kod empty.
2010 Sep 23 19:14:00.158677 +0.045810 +/- 0.021652 secs
2010 Sep 23 19:14:00.274666 +0.057905 +/- 0.061783 secs
2010 Sep 23 19:14:00.351139 +0.038152 +/- 0.041733 secs
check system clock using date command
Thu Sep 23 19:14:00 BST 2010
now sync system clock with remote NTP client using ntpdate in net-client init-script:
* Caching service dependencies...                                                                                                                                               [ ok ]
* Setting clock via the NTP client 'ntpdate'...                                                                                                                                 [ ok ]
check system clock using date command:
Thu Sep 23 19:15:21 BST 2010
#


So the sntp -s command does not work for some reason.
Comment 6 Fitzcarraldo 2010-09-23 23:51:20 UTC
As the sntp command (Ver. 4.2.6p2) doesn't appear to be functional then, if one does not want to use the ntpdate command in /etc/conf.d/ntp-client, it is possible to use the ntpd command instead. This is mentioned in the header of the as-installed /etc/conf.d/ntp-client file, and is anyway recommended on the NTP Web site page http://doc.ntp.org/4.1.2/ntpdate.htm

The following version of /etc/conf.d/ntp-client works fine:

# /etc/conf.d/ntp-client

# Command to run to set the clock initially
# Most people should just leave this line alone ...
# however, if you know what you're doing, and you
# want to use ntpd to set the clock, change this to 'ntpd'
#NTPCLIENT_CMD="ntpdate"
NTPCLIENT_CMD="ntpd"

# Options to pass to the above command
# This default setting should work fine but you should
# change the default 'pool.ntp.org' to something closer
# to your machine.  See http://www.pool.ntp.org/ or
# try running `netselect -s 3 pool.ntp.org`.
#NTPCLIENT_OPTS="-s -b -u \
#       0.gentoo.pool.ntp.org 1.gentoo.pool.ntp.org \
#       2.gentoo.pool.ntp.org 3.gentoo.pool.ntp.org"
NTPCLIENT_OPTS="-g -q"

(ntpd gets the NTP server addresses from the /etc/ntp.conf file)