Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 12602 - ntp initscript calculates a wrong NTPDATESERVERS
Summary: ntp initscript calculates a wrong NTPDATESERVERS
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All All
: High normal (vote)
Assignee: SpanKY
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-12-22 23:44 UTC by Christian Birchinger (RETIRED)
Modified: 2002-12-23 11:12 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 Christian Birchinger (RETIRED) gentoo-dev 2002-12-22 23:44:52 UTC
The function where the initscript calculates the default ntp server for ntpdate
is wrong:

The " grep '^[server|peer]' /etc/ntp.conf " function already does something
wrong.I guess the idea was lines which either start with "server" or with "peer". 
But using [ ] means you match on a list of characters and not whole strings.
For example on my config it gets already multiple lines like:

server 192.168.1.6 prefer minpoll 6 maxpoll 10
requestkey 65535
restrict default ignore
restrict 192.168.1.6 noquery nomodify notrap nopeer

The first line is ok ... the rest is already totaly wrong.

You get multiple lines with wrong values in NTPDATESERVERS.
and when you access that var without " " it apears empty.
And with " " it would have newlines. ntpdate doesn't like both versions.
ntpdate doesnt like multiple servers in general. Even if those are valid IPs

Using " grep '^[sp]e[re][vr]' " is one possible solution (maybe a bit ugly).
But multiple values should be also avoided somehow.
Comment 1 Christian Birchinger (RETIRED) gentoo-dev 2002-12-23 00:33:12 UTC
This works better:

grep '^\(server\|peer\)'
Comment 2 Christian Birchinger (RETIRED) gentoo-dev 2002-12-23 00:45:41 UTC
Ok my final sugestion is:

grep -m 1 '^\(server\|peer\)[[:space:]]' /etc/ntp.conf | awk '{print $2}'

-m 1 takes care that you only have one match and not mutliline output which
breaks on ntpdate.

no * after [[:space:]] because with * it also means zero spaces is ok which is
wrong because at leats one space is mandatory. The only alternative would be
[[:space:]][[:space:]]* but that's really not needed in this case.
Comment 3 SpanKY gentoo-dev 2002-12-23 11:08:42 UTC
i fixed the [] in cvs a while ago

multiline server passing to ntpdate works over here ...
/etc/ntp.conf:
server 199.165.76.11
server          ntp-ua.usno.navy.mil
cmd run:
ntpdate `egrep '^(server|peer)[[:space:]]*' /etc/ntp.conf | awk '{print $2}'`

the * was used because the rc script used to be using grep ... i forgot that 
literals were ignored when using regular grep ...

so, i changed the '*' to a '+' ... and ill add the -m 1 even though it works 
for me :p
Comment 4 SpanKY gentoo-dev 2002-12-23 11:12:11 UTC
actually i lied, i wont add -m 1 ...
multiline works over here, and it allows ntpdate to fall back to other servers 
if the user specified them ...