/usr/bin/calc_tickadj is in ntp 1:4.2.8p10+dfsg-3+deb9u2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | #! /usr/bin/perl -w
#
# drift of 104.8576 -> +1 tick. Base of 10000 ticks.
#
# 970306 HMS Deal with nanoseconds. Fix sign of adjustments.
package calc_tickadj;
use strict;
exit run(@ARGV) unless caller;
sub run {
my $opts;
if (!processOptions(\@_, $opts)) {
usage(1);
};
my $drift_file = $opts->{'drift-file'};
my $tick = $opts->{'tick'};
if (!$tick) {
my ($fl) = `tickadj`;
if (defined $fl && $fl =~ /(?:KERNEL|PRESET)?\s*tick\s+=\s+(\d+)/) {
$tick = $1;
}
else {
die "Could not get tick value, try manually with -t/--tick\n";
}
}
# Drift file is in PPM where Milion is actually 2**20
my $cvt = (2 ** 20) / $tick;
my $drift = 0.;
open my $dfh, $drift_file or die "Could not open $drift_file: $!\n";
$drift = <$dfh>;
close $dfh;
die "Invalid drift file value <$drift>" if $drift !~ /[+-]?\d+\.?[0-9]+/;
while ($drift < 0) {
$drift += $cvt;
$tick--;
}
while ($drift > $cvt) {
$drift -= $cvt;
$tick++;
}
printf "%.3f (drift)\n", $drift;
printf "%d usec; %d nsec\n", $tick, ($tick + ($drift/$cvt)) * 1000;
return 0;
}
# EDIT THIS FILE WITH CAUTION (calc_tickadj-opts)
#
# It has been AutoGen-ed August 31, 2014 at 04:52:46 AM by AutoGen 5.18.4
# From the definitions calc_tickadj-opts.def
# and the template file perlopt
use Getopt::Long qw(GetOptionsFromArray);
Getopt::Long::Configure(qw(no_auto_abbrev no_ignore_case_always));
my $usage;
sub usage {
my ($ret) = @_;
print STDERR $usage;
exit $ret;
}
sub paged_usage {
my ($ret) = @_;
my $pager = $ENV{PAGER} || '(less || more)';
open STDOUT, "| $pager" or die "Can't fork a pager: $!";
print $usage;
exit $ret;
}
sub processOptions {
my $args = shift;
my $opts = {
'drift-file' => '/etc/ntp/drift',
'tick' => '',
'help' => '', 'more-help' => ''
};
my $argument = '';
my $ret = GetOptionsFromArray($args, $opts, (
'drift-file|d=s', 'tick|t=i',
'help|?', 'more-help'));
$usage = <<'USAGE';
calc_tickadj - Calculates "optimal" value for tick given ntp drift file. - Ver. 4.2.7p467
USAGE: calc_tickadj [ -<flag> [<val>] | --<name>[{=| }<val>] ]...
-d, --drift-file=str Ntp drift file to use
-t, --tick=num Tick value of this host
-?, --help Display usage information and exit
--more-help Pass the extended usage text through a pager
Options are specified by doubled hyphens and their name or by a single
hyphen and the flag character.
USAGE
usage(0) if $opts->{'help'};
paged_usage(0) if $opts->{'more-help'};
$_[0] = $opts;
return $ret;
}
END { close STDOUT };
1;
__END__
|