mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-04 04:25:06 -05:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01965d147a | ||
|
|
6a84126c28 | ||
|
|
32f8bec92d | ||
|
|
00a6394b48 | ||
|
|
ca5a791d09 | ||
|
|
6a9c756cf0 | ||
|
|
1714d3e8ae | ||
|
|
25b7d47b34 | ||
|
|
9e8b4bae11 |
5
NEWS
5
NEWS
@@ -5,7 +5,7 @@ Enhancements
|
||||
------------
|
||||
* Add support for configuration and monitoring over Unix domain socket
|
||||
(accessible by root or chrony user when root privileges are dropped)
|
||||
* Add support for system call filtering with seccomp on Linux
|
||||
* Add support for system call filtering with seccomp on Linux (experimental)
|
||||
* Add support for dropping root privileges on NetBSD
|
||||
* Control frequency of system clock on FreeBSD, NetBSD, Solaris
|
||||
* Add system leap second handling mode on FreeBSD, NetBSD, Solaris
|
||||
@@ -14,9 +14,12 @@ Enhancements
|
||||
* Add maxdistance directive to limit source selection by root distance
|
||||
* Add refresh command to get new addresses of NTP sources
|
||||
* Allow wildcard patterns in include directive
|
||||
* Restore time from driftfile with -s option if later than RTC time
|
||||
* Add configure option to set default hwclockfile
|
||||
* Add -d option to chronyc to enable debug messages
|
||||
* Allow multiple addresses to be specified for chronyc with -h option
|
||||
and reconnect when no valid reply is received
|
||||
* Make check interval in waitsync command configurable
|
||||
|
||||
Bug fixes
|
||||
---------
|
||||
|
||||
@@ -34,7 +34,7 @@ useful configuration file would look something like
|
||||
server bar.example.net iburst
|
||||
server baz.example.net iburst
|
||||
driftfile @CHRONYVARDIR@/drift
|
||||
makestep 10 3
|
||||
makestep 1.0 3
|
||||
rtcsync
|
||||
.EE
|
||||
|
||||
@@ -46,7 +46,7 @@ case look like
|
||||
.EX
|
||||
pool pool.ntp.org iburst
|
||||
driftfile @CHRONYVARDIR@/drift
|
||||
makestep 10 3
|
||||
makestep 1.0 3
|
||||
rtcsync
|
||||
.EE
|
||||
|
||||
|
||||
@@ -419,7 +419,7 @@ minimal useful configuration file could be
|
||||
|
||||
@example
|
||||
pool pool.ntp.org iburst
|
||||
makestep 10 3
|
||||
makestep 1.0 3
|
||||
rtcsync
|
||||
@end example
|
||||
|
||||
@@ -576,7 +576,7 @@ server foo.example.net iburst
|
||||
server bar.example.net iburst
|
||||
server baz.example.net iburst
|
||||
driftfile @CHRONYVARDIR@/drift
|
||||
makestep 10 3
|
||||
makestep 1.0 3
|
||||
rtcsync
|
||||
@end example
|
||||
|
||||
@@ -588,7 +588,7 @@ could in this case look like
|
||||
@example
|
||||
pool pool.ntp.org iburst
|
||||
driftfile @CHRONYVARDIR@/drift
|
||||
makestep 10 3
|
||||
makestep 1.0 3
|
||||
rtcsync
|
||||
@end example
|
||||
@c }}}
|
||||
@@ -648,7 +648,7 @@ server foo.example.net offline
|
||||
server bar.example.net offline
|
||||
server baz.example.net offline
|
||||
driftfile @CHRONYVARDIR@/drift
|
||||
makestep 10 3
|
||||
makestep 1.0 3
|
||||
rtcsync
|
||||
@end example
|
||||
|
||||
@@ -845,7 +845,7 @@ server baz.example.net maxdelay 0.4 offline
|
||||
logdir /var/log/chrony
|
||||
log statistics measurements tracking
|
||||
driftfile @CHRONYVARDIR@/drift
|
||||
makestep 10 3
|
||||
makestep 1.0 3
|
||||
maxupdateskew 100.0
|
||||
dumponexit
|
||||
dumpdir @CHRONYVARDIR@
|
||||
@@ -972,13 +972,9 @@ This option is useful when restarting @code{chronyd} and can be used
|
||||
in conjunction with the `-r' option.
|
||||
|
||||
@item -s
|
||||
This option will set the system clock from the computer's real-time
|
||||
clock. This is analogous to supplying the `-s' flag to the
|
||||
@file{/sbin/hwclock} program during the Linux boot sequence.
|
||||
|
||||
Support for real-time clocks is limited at present - the criteria are
|
||||
described in the section on the @code{rtcfile} directive (@pxref{rtcfile
|
||||
directive}).
|
||||
This option will set the system clock from the computer's real-time clock or
|
||||
to the last modification time of the file specified by the @code{driftfile}
|
||||
directive. Real-time clocks are supported only on Linux.
|
||||
|
||||
If used in conjunction with the `-r' flag, @code{chronyd} will attempt
|
||||
to preserve the old samples after setting the system clock from the real
|
||||
@@ -989,11 +985,10 @@ to work well, it relies on @code{chronyd} having been able to determine
|
||||
accurate statistics for the difference between the RTC and
|
||||
system clock last time the computer was on.
|
||||
|
||||
If @code{chronyd} doesn't support the RTC on your computer or there is no RTC
|
||||
installed, the system clock will be set with this option forward to the time of
|
||||
the last modification of the drift file (specified by the @code{driftfile}
|
||||
directive) to restore the system time at which @code{chronyd} was previously
|
||||
stopped.
|
||||
If the last modification time of the drift file is later than the current time
|
||||
and the RTC time, the system time will be set to it to restore the time when
|
||||
@code{chronyd} was previously stopped. This is useful on computers that have
|
||||
no RTC or the RTC is broken (e.g. it has no battery).
|
||||
@item -u <user>
|
||||
This option sets the name of the system user to which @code{chronyd} will
|
||||
switch after start in order to drop root privileges. It overrides the
|
||||
@@ -1600,9 +1595,11 @@ NTP, reference clocks or manual input.
|
||||
@node hwclockfile directive
|
||||
@subsection hwclockfile
|
||||
The @code{hwclockfile} directive sets the location of the adjtime file which is
|
||||
used by the @file{/sbin/hwclock} program. With this directive, @code{chronyd}
|
||||
will parse the file to find out if the RTC keeps local time or UTC. It
|
||||
overrides the @code{rtconutc} directive (@pxref{rtconutc directive}).
|
||||
used by the @file{/sbin/hwclock} program on Linux. @code{chronyd} parses the
|
||||
file to find out if the RTC keeps local time or UTC. It overrides the
|
||||
@code{rtconutc} directive (@pxref{rtconutc directive}).
|
||||
|
||||
The default value is @file{@DEFAULT_HWCLOCK_FILE@}.
|
||||
|
||||
An example of the command is
|
||||
|
||||
@@ -2328,10 +2325,10 @@ only with NTP sources.
|
||||
An example of the use of this directive is
|
||||
|
||||
@example
|
||||
makestep 1000 10
|
||||
makestep 0.1 10
|
||||
@end example
|
||||
|
||||
This would step system clock if the adjustment is larger than 1000
|
||||
This would step system clock if the adjustment is larger than 0.1
|
||||
seconds, but only in the first ten clock updates.
|
||||
@c }}}
|
||||
@c {{{ manual
|
||||
@@ -4692,10 +4689,10 @@ with the @code{rtcautotrim} directive (@pxref{rtcautotrim directive}).
|
||||
@subsubsection waitsync
|
||||
The @code{waitsync} command waits for @code{chronyd} to synchronise.
|
||||
|
||||
Up to three optional arguments can be specified, the first is the maximum
|
||||
number of tries in 10 second intervals before giving up and returning a
|
||||
non-zero error code. When 0 is specified, or there are no arguments, the
|
||||
number of tries will not be limited.
|
||||
Up to four optional arguments can be specified, the first is the maximum
|
||||
number of tries before giving up and returning a non-zero error code. When 0
|
||||
is specified, or there are no arguments, the number of tries will not be
|
||||
limited.
|
||||
|
||||
The second and third arguments are the maximum allowed remaining correction of
|
||||
the system clock and the maximum allowed skew (in ppm) as reported by the
|
||||
@@ -4703,14 +4700,18 @@ the system clock and the maximum allowed skew (in ppm) as reported by the
|
||||
and @code{Skew} fields. If not specified or zero, the value will not be
|
||||
checked.
|
||||
|
||||
The fourth argument is the interval in which the check is repeated. The
|
||||
interval is 10 seconds by default.
|
||||
|
||||
An example is
|
||||
|
||||
@example
|
||||
waitsync 60 0.01
|
||||
@end example
|
||||
|
||||
which will wait up to about 10 minutes for @code{chronyd} to synchronise to a
|
||||
source and the remaining correction to be less than 10 milliseconds.
|
||||
which will wait up to about 10 minutes (60 times 10 seconds) for @code{chronyd}
|
||||
to synchronise to a source and the remaining correction to be less than 10
|
||||
milliseconds.
|
||||
@c }}}
|
||||
@c {{{ writertc
|
||||
@node writertc command
|
||||
|
||||
19
chronyd.8.in
19
chronyd.8.in
@@ -80,13 +80,9 @@ option is useful when restarting \fBchronyd\fR and can be used in conjunction
|
||||
with the \fB-r\fR option.
|
||||
.TP
|
||||
.B \-s
|
||||
This option will set the system clock from the computer's real-time
|
||||
clock. This is analogous to supplying the \fI-s\fR flag to the
|
||||
\fI/sbin/hwclock\fR program during the Linux boot sequence.
|
||||
|
||||
Support for real-time clocks is limited at present - the criteria
|
||||
are described in the section on the \fIrtcfile\fR directive in the
|
||||
documentation supplied with the distribution.
|
||||
This option will set the system clock from the computer's real-time clock or
|
||||
to the last modification time of the file specified by the \fIdriftfile\fR
|
||||
directive. Real-time clocks are supported only on Linux.
|
||||
|
||||
If used in conjunction with the \fB-r\fR flag, \fBchronyd\fR will attempt
|
||||
to preserve the old samples after setting the system clock from
|
||||
@@ -97,11 +93,10 @@ not in use. For this to work well, it relies on \fBchronyd\fR having
|
||||
been able to determine accurate statistics for the difference
|
||||
between the RTC and system clock last time the computer was on.
|
||||
|
||||
If \fBchronyd\fR doesn't support the RTC on your computer or there is no RTC
|
||||
installed, the system clock will be set with this option forward to the time of
|
||||
the last modification of the drift file (specified by the \fIdriftfile\fR
|
||||
directive) to restore the system time at which \fBchronyd\fR was previously
|
||||
stopped.
|
||||
If the last modification time of the drift file is later than the current time
|
||||
and the RTC time, the system time will be set to it to restore the time when
|
||||
\fBchronyd\fR was previously stopped. This is useful on computers that have no
|
||||
RTC or the RTC is broken (e.g. it has no battery).
|
||||
.TP
|
||||
\fB\-u\fR \fIuser\fR
|
||||
This option sets the name of the system user to which \fBchronyd\fR will switch
|
||||
|
||||
16
client.c
16
client.c
@@ -1191,7 +1191,7 @@ give_help(void)
|
||||
"makestep\0Correct clock by stepping immediately\0"
|
||||
"makestep <threshold> <updates>\0Configure automatic clock stepping\0"
|
||||
"maxupdateskew <skew>\0Modify maximum valid skew to update frequency\0"
|
||||
"waitsync [max-tries [max-correction [max-skew]]]\0"
|
||||
"waitsync [max-tries [max-correction [max-skew [interval]]]]\0"
|
||||
"Wait until synchronised in specified limits\0"
|
||||
"\0\0"
|
||||
"Time sources:\0\0"
|
||||
@@ -2313,14 +2313,20 @@ process_cmd_waitsync(char *line)
|
||||
CMD_Request request;
|
||||
CMD_Reply reply;
|
||||
uint32_t ref_id, a, b, c, d;
|
||||
double correction, skew_ppm, max_correction, max_skew_ppm;
|
||||
double correction, skew_ppm, max_correction, max_skew_ppm, interval;
|
||||
int ret = 0, max_tries, i;
|
||||
struct timeval timeout;
|
||||
|
||||
max_tries = 0;
|
||||
max_correction = 0.0;
|
||||
max_skew_ppm = 0.0;
|
||||
interval = 10.0;
|
||||
|
||||
sscanf(line, "%d %lf %lf", &max_tries, &max_correction, &max_skew_ppm);
|
||||
sscanf(line, "%d %lf %lf %lf", &max_tries, &max_correction, &max_skew_ppm, &interval);
|
||||
|
||||
/* Don't allow shorter interval than 0.1 seconds */
|
||||
if (interval < 0.1)
|
||||
interval = 0.1;
|
||||
|
||||
request.command = htons(REQ_TRACKING);
|
||||
|
||||
@@ -2347,7 +2353,9 @@ process_cmd_waitsync(char *line)
|
||||
}
|
||||
|
||||
if (!ret && (!max_tries || i < max_tries) && !quit) {
|
||||
sleep(10);
|
||||
UTI_DoubleToTimeval(interval, &timeout);
|
||||
if (select(0, NULL, NULL, NULL, &timeout))
|
||||
break;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
3
conf.c
3
conf.c
@@ -124,7 +124,7 @@ static int enable_manual=0;
|
||||
static int rtc_on_utc = 0;
|
||||
|
||||
/* Filename used to read the hwclock(8) LOCAL/UTC setting */
|
||||
static char *hwclock_file = NULL;
|
||||
static char *hwclock_file;
|
||||
|
||||
/* Flag set if the RTC should be automatically synchronised by kernel */
|
||||
static int rtc_sync = 0;
|
||||
@@ -324,6 +324,7 @@ CNF_Initialise(int r)
|
||||
bind_cmd_path = Strdup(DEFAULT_COMMAND_SOCKET);
|
||||
pidfile = Strdup("/var/run/chronyd.pid");
|
||||
rtc_device = Strdup("/dev/rtc");
|
||||
hwclock_file = Strdup(DEFAULT_HWCLOCK_FILE);
|
||||
user = Strdup(DEFAULT_USER);
|
||||
}
|
||||
|
||||
|
||||
7
configure
vendored
7
configure
vendored
@@ -102,6 +102,7 @@ For better control, use the options below.
|
||||
--with-ntp-era=SECONDS Specify earliest assumed NTP time in seconds
|
||||
since 1970-01-01 [50*365 days ago]
|
||||
--with-user=USER Specify default chronyd user [root]
|
||||
--with-hwclockfile=PATH Specify default path to hwclock(8) adjtime file
|
||||
--with-sendmail=PATH Path to sendmail binary [/usr/lib/sendmail]
|
||||
--enable-debug Enable debugging support
|
||||
|
||||
@@ -214,6 +215,7 @@ feat_asyncdns=1
|
||||
feat_forcednsretry=1
|
||||
ntp_era_split=""
|
||||
default_user="root"
|
||||
default_hwclockfile=""
|
||||
mail_program="/usr/lib/sendmail"
|
||||
|
||||
for option
|
||||
@@ -321,6 +323,9 @@ do
|
||||
--with-user=* )
|
||||
default_user=`echo $option | sed -e 's/^.*=//;'`
|
||||
;;
|
||||
--with-hwclockfile=* )
|
||||
default_hwclockfile=`echo $option | sed -e 's/^.*=//;'`
|
||||
;;
|
||||
--with-sendmail=* )
|
||||
mail_program=`echo $option | sed -e 's/^.*=//;'`
|
||||
;;
|
||||
@@ -784,6 +789,7 @@ if [ "x$SETCHRONYVARDIR" != "x" ]; then
|
||||
fi
|
||||
|
||||
add_def DEFAULT_CONF_FILE "\"$SYSCONFDIR/chrony.conf\""
|
||||
add_def DEFAULT_HWCLOCK_FILE "\"$default_hwclockfile\""
|
||||
add_def DEFAULT_USER "\"$default_user\""
|
||||
add_def DEFAULT_COMMAND_SOCKET "\"$CHRONYSOCKDIR/chronyd.sock\""
|
||||
add_def MAIL_PROGRAM "\"$mail_program\""
|
||||
@@ -824,6 +830,7 @@ do
|
||||
s%@LOCALSTATEDIR@%${LOCALSTATEDIR}%;\
|
||||
s%@CHRONYSOCKDIR@%${CHRONYSOCKDIR}%;\
|
||||
s%@CHRONYVARDIR@%${CHRONYVARDIR}%;\
|
||||
s%@DEFAULT_HWCLOCK_FILE@%${default_hwclockfile}%;\
|
||||
s%@DEFAULT_USER@%${default_user}%;"\
|
||||
< ${f}.in > $f
|
||||
done
|
||||
|
||||
@@ -9,7 +9,7 @@ Wants=time-sync.target
|
||||
Type=oneshot
|
||||
# Wait up to ~10 minutes for chronyd to synchronize and the remaining
|
||||
# clock correction to be less than 0.1 seconds
|
||||
ExecStart=/usr/bin/chronyc waitsync 60 0.1
|
||||
ExecStart=/usr/bin/chronyc waitsync 600 0.1 0.0 1
|
||||
RemainAfterExit=yes
|
||||
StandardOutput=null
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ pool pool.ntp.org iburst
|
||||
driftfile /var/lib/chrony/drift
|
||||
|
||||
# In first three updates step the system clock instead of slew
|
||||
# if the adjustment is larger than 10 seconds.
|
||||
makestep 10 3
|
||||
# if the adjustment is larger than 1 second.
|
||||
makestep 1.0 3
|
||||
|
||||
# Enable kernel synchronization of the real-time clock (RTC).
|
||||
rtcsync
|
||||
|
||||
@@ -6,8 +6,8 @@ pool pool.ntp.org iburst
|
||||
driftfile /var/lib/chrony/drift
|
||||
|
||||
# In first three updates step the system clock instead of slew
|
||||
# if the adjustment is larger than 10 seconds.
|
||||
makestep 10 3
|
||||
# if the adjustment is larger than 1 second.
|
||||
makestep 1.0 3
|
||||
|
||||
# Enable kernel synchronization of the real-time clock (RTC).
|
||||
rtcsync
|
||||
|
||||
@@ -128,15 +128,15 @@ driftfile /var/lib/chrony/drift
|
||||
#######################################################################
|
||||
### INITIAL CLOCK CORRECTION
|
||||
# This option is useful to quickly correct the clock on start if it's
|
||||
# off by a large amount. The value '10' means that if the error is less
|
||||
# than 10 seconds, it will be gradually removed by speeding up or
|
||||
# slowing down your computer's clock until it is correct. If the error
|
||||
# is above 10 seconds, an immediate time jump will be applied to correct
|
||||
# it. The value '1' means the step is allowed only on the first update
|
||||
# of the clock. Some software can get upset if the system clock jumps
|
||||
# off by a large amount. The value '1.0' means that if the error is less
|
||||
# than 1 second, it will be gradually removed by speeding up or slowing
|
||||
# down your computer's clock until it is correct. If the error is above
|
||||
# 1 second, an immediate time jump will be applied to correct it. The
|
||||
# value '3' means the step is allowed only in the first three updates of
|
||||
# the clock. Some software can get upset if the system clock jumps
|
||||
# (especially backwards), so be careful!
|
||||
|
||||
! makestep 10 1
|
||||
! makestep 1.0 3
|
||||
|
||||
#######################################################################
|
||||
### LOGGING
|
||||
|
||||
62
rtc.c
62
rtc.c
@@ -39,11 +39,12 @@
|
||||
/* ================================================== */
|
||||
|
||||
static int driver_initialised = 0;
|
||||
static int driver_preinit_ok = 0;
|
||||
|
||||
static struct {
|
||||
int (*init)(void);
|
||||
void (*fini)(void);
|
||||
int (*time_pre_init)(void);
|
||||
int (*time_pre_init)(time_t driftfile_time);
|
||||
void (*time_init)(void (*after_hook)(void*), void *anything);
|
||||
void (*start_measurements)(void);
|
||||
int (*write_parameters)(void);
|
||||
@@ -73,29 +74,37 @@ static struct {
|
||||
};
|
||||
|
||||
/* ================================================== */
|
||||
/* Set the system clock to the time of last modification of driftfile
|
||||
if it's in the future */
|
||||
/* Get the last modification time of the driftfile */
|
||||
|
||||
static void
|
||||
fallback_time_init(void)
|
||||
static time_t
|
||||
get_driftfile_time(void)
|
||||
{
|
||||
struct timeval now;
|
||||
struct stat buf;
|
||||
char *drift_file;
|
||||
|
||||
drift_file = CNF_GetDriftFile();
|
||||
if (!drift_file)
|
||||
return;
|
||||
return 0;
|
||||
|
||||
if (stat(drift_file, &buf))
|
||||
return;
|
||||
return 0;
|
||||
|
||||
return buf.st_mtime;
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
/* Set the system time to the driftfile time if it's in the future */
|
||||
|
||||
static void
|
||||
apply_driftfile_time(time_t t)
|
||||
{
|
||||
struct timeval now;
|
||||
|
||||
LCL_ReadCookedTime(&now, NULL);
|
||||
|
||||
if (now.tv_sec < buf.st_mtime) {
|
||||
if (LCL_ApplyStepOffset(now.tv_sec - buf.st_mtime))
|
||||
LOG(LOGS_INFO, LOGF_Rtc, "System clock set from driftfile %s",
|
||||
drift_file);
|
||||
if (now.tv_sec < t) {
|
||||
if (LCL_ApplyStepOffset(now.tv_sec - t))
|
||||
LOG(LOGS_INFO, LOGF_Rtc, "System time restored from driftfile");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,15 +113,24 @@ fallback_time_init(void)
|
||||
void
|
||||
RTC_Initialise(int initial_set)
|
||||
{
|
||||
time_t driftfile_time;
|
||||
char *file_name;
|
||||
|
||||
/* Do an initial read of the RTC and set the system time to it. This
|
||||
is analogous to what /sbin/hwclock -s would do on Linux. If that fails
|
||||
or RTC is not supported, set the clock to the time of the last
|
||||
modification of driftfile, so we at least get closer to the truth. */
|
||||
/* If the -s option was specified, try to do an initial read of the RTC and
|
||||
set the system time to it. Also, read the last modification time of the
|
||||
driftfile (i.e. system time when chronyd was previously stopped) and set
|
||||
the system time to it if it's in the future to bring the clock closer to
|
||||
the true time when the RTC is broken (e.g. it has no battery), is missing,
|
||||
or there is no RTC driver. */
|
||||
if (initial_set) {
|
||||
if (!driver.time_pre_init || !driver.time_pre_init()) {
|
||||
fallback_time_init();
|
||||
driftfile_time = get_driftfile_time();
|
||||
|
||||
if (driver.time_pre_init && driver.time_pre_init(driftfile_time)) {
|
||||
driver_preinit_ok = 1;
|
||||
} else {
|
||||
driver_preinit_ok = 0;
|
||||
if (driftfile_time)
|
||||
apply_driftfile_time(driftfile_time);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,9 +168,9 @@ RTC_Finalise(void)
|
||||
/* ================================================== */
|
||||
/* Start the processing to get a single measurement from the real time
|
||||
clock, and use it to trim the system time, based on knowing the
|
||||
drift rate of the RTC and the error the last time we set it. The
|
||||
TimePreInit routine has already run, so we can be sure that the
|
||||
trim required is not *too* large.
|
||||
drift rate of the RTC and the error the last time we set it. If the
|
||||
TimePreInit routine has succeeded, we can be sure that the trim required
|
||||
is not *too* large.
|
||||
|
||||
We are called with a hook to a function to be called after the
|
||||
initialisation is complete. We also call this if we cannot do the
|
||||
@@ -161,7 +179,7 @@ RTC_Finalise(void)
|
||||
void
|
||||
RTC_TimeInit(void (*after_hook)(void *), void *anything)
|
||||
{
|
||||
if (driver_initialised) {
|
||||
if (driver_initialised && driver_preinit_ok) {
|
||||
(driver.time_init)(after_hook, anything);
|
||||
} else {
|
||||
(after_hook)(anything);
|
||||
|
||||
45
rtc_linux.c
45
rtc_linux.c
@@ -367,6 +367,9 @@ t_from_rtc(struct tm *stm) {
|
||||
t2 = mktime(&temp2);
|
||||
diff = t2 - t1;
|
||||
|
||||
if (t1 - diff == -1)
|
||||
DEBUG_LOG(LOGF_RtcLinux, "Could not convert RTC time");
|
||||
|
||||
return t1 - diff;
|
||||
}
|
||||
|
||||
@@ -379,13 +382,13 @@ read_hwclock_file(const char *hwclock_file)
|
||||
char line[256];
|
||||
int i;
|
||||
|
||||
if (!hwclock_file)
|
||||
if (!hwclock_file || !hwclock_file[0])
|
||||
return;
|
||||
|
||||
in = fopen(hwclock_file, "r");
|
||||
if (!in) {
|
||||
LOG(LOGS_WARN, LOGF_RtcLinux, "Could not open hwclockfile %s",
|
||||
hwclock_file);
|
||||
LOG(LOGS_WARN, LOGF_RtcLinux, "Could not open %s : %s",
|
||||
hwclock_file, strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -402,7 +405,7 @@ read_hwclock_file(const char *hwclock_file)
|
||||
} else if (i == 3 && !strncmp(line, "UTC", 3)) {
|
||||
rtc_on_utc = 1;
|
||||
} else {
|
||||
LOG(LOGS_WARN, LOGF_RtcLinux, "Could not read LOCAL/UTC setting from hwclockfile %s",
|
||||
LOG(LOGS_WARN, LOGF_RtcLinux, "Could not read RTC LOCAL/UTC setting from %s",
|
||||
hwclock_file);
|
||||
}
|
||||
}
|
||||
@@ -445,7 +448,7 @@ read_coefs_from_file(void)
|
||||
&file_ref_offset,
|
||||
&file_rate_ppm) == 4) {
|
||||
} else {
|
||||
LOG(LOGS_WARN, LOGF_RtcLinux, "Could not read coefficients from RTC file %s",
|
||||
LOG(LOGS_WARN, LOGF_RtcLinux, "Could not read coefficients from %s",
|
||||
coefs_file_name);
|
||||
}
|
||||
fclose(in);
|
||||
@@ -607,14 +610,16 @@ switch_interrupts(int onoff)
|
||||
if (onoff) {
|
||||
status = ioctl(fd, RTC_UIE_ON, 0);
|
||||
if (status < 0) {
|
||||
LOG(LOGS_ERR, LOGF_RtcLinux, "Could not start measurement : %s", strerror(errno));
|
||||
LOG(LOGS_ERR, LOGF_RtcLinux, "Could not %s RTC interrupt : %s",
|
||||
"enable", strerror(errno));
|
||||
return;
|
||||
}
|
||||
skip_interrupts = 1;
|
||||
} else {
|
||||
status = ioctl(fd, RTC_UIE_OFF, 0);
|
||||
if (status < 0) {
|
||||
LOG(LOGS_ERR, LOGF_RtcLinux, "Could not stop measurement : %s", strerror(errno));
|
||||
LOG(LOGS_ERR, LOGF_RtcLinux, "Could not %s RTC interrupt : %s",
|
||||
"disable", strerror(errno));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -694,10 +699,11 @@ handle_initial_trim(void)
|
||||
/* sys_error_now is positive if the system clock is fast */
|
||||
sys_error_now = rtc_error_now - coef_seconds_fast;
|
||||
|
||||
LOG(LOGS_INFO, LOGF_RtcLinux, "System trim from RTC = %f", sys_error_now);
|
||||
LCL_AccumulateOffset(sys_error_now, 0.0);
|
||||
LOG(LOGS_INFO, LOGF_RtcLinux, "System clock off from RTC by %f seconds (slew)",
|
||||
sys_error_now);
|
||||
} else {
|
||||
LOG(LOGS_WARN, LOGF_RtcLinux, "No valid file coefficients, cannot trim system time");
|
||||
LOG(LOGS_WARN, LOGF_RtcLinux, "No valid rtcfile coefficients");
|
||||
}
|
||||
|
||||
coefs_valid = 0;
|
||||
@@ -722,7 +728,7 @@ handle_relock_after_trim(void)
|
||||
if (valid) {
|
||||
write_coefs_to_file(1,ref,fast,saved_coef_gain_rate);
|
||||
} else {
|
||||
LOG(LOGS_WARN, LOGF_RtcLinux, "Could not do regression after trim");
|
||||
DEBUG_LOG(LOGF_RtcLinux, "Could not do regression after trim");
|
||||
}
|
||||
|
||||
coefs_valid = 0;
|
||||
@@ -857,7 +863,6 @@ read_from_device(void *any)
|
||||
rtc_t = t_from_rtc(&rtc_tm);
|
||||
|
||||
if (rtc_t == (time_t)(-1)) {
|
||||
LOG(LOGS_ERR, LOGF_RtcLinux, "Could not convert RTC time to timeval");
|
||||
error = 1;
|
||||
goto turn_off_interrupt;
|
||||
}
|
||||
@@ -883,7 +888,7 @@ turn_off_interrupt:
|
||||
switch (operating_mode) {
|
||||
case OM_INITIAL:
|
||||
if (error) {
|
||||
LOG(LOGS_WARN, LOGF_RtcLinux, "Could not complete initial step due to errors");
|
||||
DEBUG_LOG(LOGF_RtcLinux, "Could not complete initial step due to errors");
|
||||
operating_mode = OM_NORMAL;
|
||||
(after_init_hook)(after_init_hook_arg);
|
||||
|
||||
@@ -897,7 +902,7 @@ turn_off_interrupt:
|
||||
|
||||
case OM_AFTERTRIM:
|
||||
if (error) {
|
||||
LOG(LOGS_WARN, LOGF_RtcLinux, "Could not complete after trim relock due to errors");
|
||||
DEBUG_LOG(LOGF_RtcLinux, "Could not complete after trim relock due to errors");
|
||||
operating_mode = OM_NORMAL;
|
||||
|
||||
switch_interrupts(0);
|
||||
@@ -974,7 +979,7 @@ RTC_Linux_WriteParameters(void)
|
||||
RTC behaviour than we do for the rest of the module. */
|
||||
|
||||
int
|
||||
RTC_Linux_TimePreInit(void)
|
||||
RTC_Linux_TimePreInit(time_t driftfile_time)
|
||||
{
|
||||
int fd, status;
|
||||
struct rtc_time rtc_raw, rtc_raw_retry;
|
||||
@@ -1039,16 +1044,19 @@ RTC_Linux_TimePreInit(void)
|
||||
|
||||
UTI_AddDoubleToTimeval(&new_sys_time, -accumulated_error, &new_sys_time);
|
||||
|
||||
if (new_sys_time.tv_sec < driftfile_time) {
|
||||
LOG(LOGS_WARN, LOGF_RtcLinux, "RTC time before last driftfile modification (ignored)");
|
||||
return 0;
|
||||
}
|
||||
|
||||
UTI_DiffTimevalsToDouble(&sys_offset, &old_sys_time, &new_sys_time);
|
||||
|
||||
/* Set system time only if the step is larger than 1 second */
|
||||
if (fabs(sys_offset) >= 1.0) {
|
||||
if (LCL_ApplyStepOffset(sys_offset))
|
||||
LOG(LOGS_INFO, LOGF_RtcLinux, "Set system time, error in RTC = %f",
|
||||
accumulated_error);
|
||||
LOG(LOGS_INFO, LOGF_RtcLinux, "System time set from RTC");
|
||||
}
|
||||
} else {
|
||||
LOG(LOGS_WARN, LOGF_RtcLinux, "Could not convert RTC reading to seconds since 1/1/1970");
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
@@ -1092,7 +1100,8 @@ RTC_Linux_Trim(void)
|
||||
|
||||
if (fabs(coef_seconds_fast) > 1.0) {
|
||||
|
||||
LOG(LOGS_INFO, LOGF_RtcLinux, "Trimming RTC, error = %.3f seconds", coef_seconds_fast);
|
||||
LOG(LOGS_INFO, LOGF_RtcLinux, "RTC wrong by %.3f seconds (step)",
|
||||
coef_seconds_fast);
|
||||
|
||||
/* Do processing to set clock. Let R be the value we set the
|
||||
RTC to, then in 500ms the RTC ticks (R+1) (see comments in
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
extern int RTC_Linux_Initialise(void);
|
||||
extern void RTC_Linux_Finalise(void);
|
||||
extern int RTC_Linux_TimePreInit(void);
|
||||
extern int RTC_Linux_TimePreInit(time_t driftile_time);
|
||||
extern void RTC_Linux_TimeInit(void (*after_hook)(void *), void *anything);
|
||||
extern void RTC_Linux_StartMeasurements(void);
|
||||
|
||||
|
||||
@@ -563,7 +563,7 @@ SYS_Linux_EnableSystemCallFilter(int level)
|
||||
}
|
||||
|
||||
if (seccomp_load(ctx) < 0)
|
||||
LOG(LOGS_INFO, LOGF_SysLinux, "Failed to load seccomp rules");
|
||||
LOG_FATAL(LOGF_SysLinux, "Failed to load seccomp rules");
|
||||
|
||||
LOG(LOGS_INFO, LOGF_SysLinux, "Loaded seccomp filter");
|
||||
seccomp_release(ctx);
|
||||
|
||||
Reference in New Issue
Block a user