From: Harlan Stenn Date: Fri, 5 Jul 2013 00:43:53 +0000 (-0400) Subject: Fix ntpsweep to use sntp instead of ntpdate, from Oliver Kindernay X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ec96b8ddeeb727feae33058056ecfe39df887cd;p=thirdparty%2Fntp.git Fix ntpsweep to use sntp instead of ntpdate, from Oliver Kindernay bk: 51d616c95XGVSQiqGXAkNo6pq6pi_A --- diff --git a/ChangeLog b/ChangeLog index 3294e88321..670046e9f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ +* Fix ntpsweep to use sntp instead of ntpdate, from Oliver Kindernay. (4.2.7p365) 2013/04/16 Released by Harlan Stenn * [Bug 2149] Log an error message if /proc/net/if_inet6 cannot be opened. (4.2.7p364) 2013/03/26 Released by Harlan Stenn diff --git a/scripts/ntpsweep.in b/scripts/ntpsweep.in index e503a0637a..650d2c5ec0 100644 --- a/scripts/ntpsweep.in +++ b/scripts/ntpsweep.in @@ -26,7 +26,7 @@ my $version = 1.3; (my $program = $0) =~ s%.*/(.+?)(.pl)?$%$1%; # Hardcoded paths/program names -my $ntpdate = "ntpdate"; +my $sntp = "sntp"; my $ntpq = "ntpq"; # no STDOUT buffering @@ -138,18 +138,18 @@ sub scan_host($;$;$) { if (&item_in_list($host, @known_hosts)) { $known_host = 1; } else { - # ntpdate part - open(NTPDATE, "$ntpdate -bd $host 2>/dev/null |") || - die "Cannot open ntpdate pipe: $!\n"; - while () { - /^stratum\s+(\d+).*$/ && do { - $stratum = $1; - }; - /^offset\s+([0-9.-]+)$/ && do { - $offset = $1; - }; - } - close(NTPDATE); + # sntp part + open my $sntp_pipe, "$sntp $host 2>/dev/null |" + or die "Cannot open $sntp pipe: $1"; + + while (<$sntp_pipe>) { + next if !/^\d{4}-\d\d-\d\d/; + my @output = split / /; + + $offset = $output[3]; + ($stratum = pop @output) =~ s/s(\d{1,2})/$1/; + } + close $sntp_pipe; # got answers ? If so, go on. if ($stratum) {