Compare commits

..

9 Commits

Author SHA1 Message Date
Miroslav Lichvar
01965d147a doc: update NEWS 2015-10-09 13:39:44 +02:00
Miroslav Lichvar
6a84126c28 examples: use one-second check interval in chrony-wait.service 2015-10-09 13:39:37 +02:00
Miroslav Lichvar
32f8bec92d configure: make default hwclockfile configurable 2015-10-08 15:20:32 +02:00
Miroslav Lichvar
00a6394b48 rtc: improve logging
Improve, shorten, or convert to debug log messages.
2015-10-08 15:20:28 +02:00
Miroslav Lichvar
ca5a791d09 client: make waitsync check interval configurable 2015-10-07 15:52:37 +02:00
Miroslav Lichvar
6a9c756cf0 rtc: restore time from driftfile if later than RTC time
This is useful on computers that have an RTC, but there is no battery to
keep the time when they are turned off and start with the same time on
each boot.
2015-10-06 15:52:36 +02:00
Miroslav Lichvar
1714d3e8ae rtc: don't run time_init function if pre_init failed 2015-10-06 13:23:14 +02:00
Miroslav Lichvar
25b7d47b34 doc: reduce makestep threshold in examples to 1 second 2015-10-05 10:15:02 +02:00
Miroslav Lichvar
9e8b4bae11 sys_linux: abort when loading seccomp rules fails 2015-10-05 09:56:58 +02:00
15 changed files with 144 additions and 102 deletions

5
NEWS
View File

@@ -5,7 +5,7 @@ Enhancements
------------ ------------
* Add support for configuration and monitoring over Unix domain socket * Add support for configuration and monitoring over Unix domain socket
(accessible by root or chrony user when root privileges are dropped) (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 * Add support for dropping root privileges on NetBSD
* Control frequency of system clock on FreeBSD, NetBSD, Solaris * Control frequency of system clock on FreeBSD, NetBSD, Solaris
* Add system leap second handling mode 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 maxdistance directive to limit source selection by root distance
* Add refresh command to get new addresses of NTP sources * Add refresh command to get new addresses of NTP sources
* Allow wildcard patterns in include directive * 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 * Add -d option to chronyc to enable debug messages
* Allow multiple addresses to be specified for chronyc with -h option * Allow multiple addresses to be specified for chronyc with -h option
and reconnect when no valid reply is received and reconnect when no valid reply is received
* Make check interval in waitsync command configurable
Bug fixes Bug fixes
--------- ---------

View File

@@ -34,7 +34,7 @@ useful configuration file would look something like
server bar.example.net iburst server bar.example.net iburst
server baz.example.net iburst server baz.example.net iburst
driftfile @CHRONYVARDIR@/drift driftfile @CHRONYVARDIR@/drift
makestep 10 3 makestep 1.0 3
rtcsync rtcsync
.EE .EE
@@ -46,7 +46,7 @@ case look like
.EX .EX
pool pool.ntp.org iburst pool pool.ntp.org iburst
driftfile @CHRONYVARDIR@/drift driftfile @CHRONYVARDIR@/drift
makestep 10 3 makestep 1.0 3
rtcsync rtcsync
.EE .EE

View File

@@ -419,7 +419,7 @@ minimal useful configuration file could be
@example @example
pool pool.ntp.org iburst pool pool.ntp.org iburst
makestep 10 3 makestep 1.0 3
rtcsync rtcsync
@end example @end example
@@ -576,7 +576,7 @@ server foo.example.net iburst
server bar.example.net iburst server bar.example.net iburst
server baz.example.net iburst server baz.example.net iburst
driftfile @CHRONYVARDIR@/drift driftfile @CHRONYVARDIR@/drift
makestep 10 3 makestep 1.0 3
rtcsync rtcsync
@end example @end example
@@ -588,7 +588,7 @@ could in this case look like
@example @example
pool pool.ntp.org iburst pool pool.ntp.org iburst
driftfile @CHRONYVARDIR@/drift driftfile @CHRONYVARDIR@/drift
makestep 10 3 makestep 1.0 3
rtcsync rtcsync
@end example @end example
@c }}} @c }}}
@@ -648,7 +648,7 @@ server foo.example.net offline
server bar.example.net offline server bar.example.net offline
server baz.example.net offline server baz.example.net offline
driftfile @CHRONYVARDIR@/drift driftfile @CHRONYVARDIR@/drift
makestep 10 3 makestep 1.0 3
rtcsync rtcsync
@end example @end example
@@ -845,7 +845,7 @@ server baz.example.net maxdelay 0.4 offline
logdir /var/log/chrony logdir /var/log/chrony
log statistics measurements tracking log statistics measurements tracking
driftfile @CHRONYVARDIR@/drift driftfile @CHRONYVARDIR@/drift
makestep 10 3 makestep 1.0 3
maxupdateskew 100.0 maxupdateskew 100.0
dumponexit dumponexit
dumpdir @CHRONYVARDIR@ dumpdir @CHRONYVARDIR@
@@ -972,13 +972,9 @@ This option is useful when restarting @code{chronyd} and can be used
in conjunction with the `-r' option. in conjunction with the `-r' option.
@item -s @item -s
This option will set the system clock from the computer's real-time This option will set the system clock from the computer's real-time clock or
clock. This is analogous to supplying the `-s' flag to the to the last modification time of the file specified by the @code{driftfile}
@file{/sbin/hwclock} program during the Linux boot sequence. directive. Real-time clocks are supported only on Linux.
Support for real-time clocks is limited at present - the criteria are
described in the section on the @code{rtcfile} directive (@pxref{rtcfile
directive}).
If used in conjunction with the `-r' flag, @code{chronyd} will attempt 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 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 accurate statistics for the difference between the RTC and
system clock last time the computer was on. system clock last time the computer was on.
If @code{chronyd} doesn't support the RTC on your computer or there is no RTC If the last modification time of the drift file is later than the current time
installed, the system clock will be set with this option forward to the time of and the RTC time, the system time will be set to it to restore the time when
the last modification of the drift file (specified by the @code{driftfile} @code{chronyd} was previously stopped. This is useful on computers that have
directive) to restore the system time at which @code{chronyd} was previously no RTC or the RTC is broken (e.g. it has no battery).
stopped.
@item -u <user> @item -u <user>
This option sets the name of the system user to which @code{chronyd} will 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 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 @node hwclockfile directive
@subsection hwclockfile @subsection hwclockfile
The @code{hwclockfile} directive sets the location of the adjtime file which is 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} used by the @file{/sbin/hwclock} program on Linux. @code{chronyd} parses the
will parse the file to find out if the RTC keeps local time or UTC. It file to find out if the RTC keeps local time or UTC. It overrides the
overrides the @code{rtconutc} directive (@pxref{rtconutc directive}). @code{rtconutc} directive (@pxref{rtconutc directive}).
The default value is @file{@DEFAULT_HWCLOCK_FILE@}.
An example of the command is An example of the command is
@@ -2328,10 +2325,10 @@ only with NTP sources.
An example of the use of this directive is An example of the use of this directive is
@example @example
makestep 1000 10 makestep 0.1 10
@end example @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. seconds, but only in the first ten clock updates.
@c }}} @c }}}
@c {{{ manual @c {{{ manual
@@ -4692,10 +4689,10 @@ with the @code{rtcautotrim} directive (@pxref{rtcautotrim directive}).
@subsubsection waitsync @subsubsection waitsync
The @code{waitsync} command waits for @code{chronyd} to synchronise. The @code{waitsync} command waits for @code{chronyd} to synchronise.
Up to three optional arguments can be specified, the first is the maximum Up to four optional arguments can be specified, the first is the maximum
number of tries in 10 second intervals before giving up and returning a number of tries before giving up and returning a non-zero error code. When 0
non-zero error code. When 0 is specified, or there are no arguments, the is specified, or there are no arguments, the number of tries will not be
number of tries will not be limited. limited.
The second and third arguments are the maximum allowed remaining correction of 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 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 and @code{Skew} fields. If not specified or zero, the value will not be
checked. checked.
The fourth argument is the interval in which the check is repeated. The
interval is 10 seconds by default.
An example is An example is
@example @example
waitsync 60 0.01 waitsync 60 0.01
@end example @end example
which will wait up to about 10 minutes for @code{chronyd} to synchronise to a which will wait up to about 10 minutes (60 times 10 seconds) for @code{chronyd}
source and the remaining correction to be less than 10 milliseconds. to synchronise to a source and the remaining correction to be less than 10
milliseconds.
@c }}} @c }}}
@c {{{ writertc @c {{{ writertc
@node writertc command @node writertc command

View File

@@ -80,13 +80,9 @@ option is useful when restarting \fBchronyd\fR and can be used in conjunction
with the \fB-r\fR option. with the \fB-r\fR option.
.TP .TP
.B \-s .B \-s
This option will set the system clock from the computer's real-time This option will set the system clock from the computer's real-time clock or
clock. This is analogous to supplying the \fI-s\fR flag to the to the last modification time of the file specified by the \fIdriftfile\fR
\fI/sbin/hwclock\fR program during the Linux boot sequence. directive. Real-time clocks are supported only on Linux.
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.
If used in conjunction with the \fB-r\fR flag, \fBchronyd\fR will attempt 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 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 been able to determine accurate statistics for the difference
between the RTC and system clock last time the computer was on. 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 If the last modification time of the drift file is later than the current time
installed, the system clock will be set with this option forward to the time of and the RTC time, the system time will be set to it to restore the time when
the last modification of the drift file (specified by the \fIdriftfile\fR \fBchronyd\fR was previously stopped. This is useful on computers that have no
directive) to restore the system time at which \fBchronyd\fR was previously RTC or the RTC is broken (e.g. it has no battery).
stopped.
.TP .TP
\fB\-u\fR \fIuser\fR \fB\-u\fR \fIuser\fR
This option sets the name of the system user to which \fBchronyd\fR will switch This option sets the name of the system user to which \fBchronyd\fR will switch

View File

@@ -1191,7 +1191,7 @@ give_help(void)
"makestep\0Correct clock by stepping immediately\0" "makestep\0Correct clock by stepping immediately\0"
"makestep <threshold> <updates>\0Configure automatic clock stepping\0" "makestep <threshold> <updates>\0Configure automatic clock stepping\0"
"maxupdateskew <skew>\0Modify maximum valid skew to update frequency\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" "Wait until synchronised in specified limits\0"
"\0\0" "\0\0"
"Time sources:\0\0" "Time sources:\0\0"
@@ -2313,14 +2313,20 @@ process_cmd_waitsync(char *line)
CMD_Request request; CMD_Request request;
CMD_Reply reply; CMD_Reply reply;
uint32_t ref_id, a, b, c, d; 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; int ret = 0, max_tries, i;
struct timeval timeout;
max_tries = 0; max_tries = 0;
max_correction = 0.0; max_correction = 0.0;
max_skew_ppm = 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); request.command = htons(REQ_TRACKING);
@@ -2347,7 +2353,9 @@ process_cmd_waitsync(char *line)
} }
if (!ret && (!max_tries || i < max_tries) && !quit) { if (!ret && (!max_tries || i < max_tries) && !quit) {
sleep(10); UTI_DoubleToTimeval(interval, &timeout);
if (select(0, NULL, NULL, NULL, &timeout))
break;
} else { } else {
break; break;
} }

3
conf.c
View File

@@ -124,7 +124,7 @@ static int enable_manual=0;
static int rtc_on_utc = 0; static int rtc_on_utc = 0;
/* Filename used to read the hwclock(8) LOCAL/UTC setting */ /* 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 */ /* Flag set if the RTC should be automatically synchronised by kernel */
static int rtc_sync = 0; static int rtc_sync = 0;
@@ -324,6 +324,7 @@ CNF_Initialise(int r)
bind_cmd_path = Strdup(DEFAULT_COMMAND_SOCKET); bind_cmd_path = Strdup(DEFAULT_COMMAND_SOCKET);
pidfile = Strdup("/var/run/chronyd.pid"); pidfile = Strdup("/var/run/chronyd.pid");
rtc_device = Strdup("/dev/rtc"); rtc_device = Strdup("/dev/rtc");
hwclock_file = Strdup(DEFAULT_HWCLOCK_FILE);
user = Strdup(DEFAULT_USER); user = Strdup(DEFAULT_USER);
} }

7
configure vendored
View File

@@ -102,6 +102,7 @@ For better control, use the options below.
--with-ntp-era=SECONDS Specify earliest assumed NTP time in seconds --with-ntp-era=SECONDS Specify earliest assumed NTP time in seconds
since 1970-01-01 [50*365 days ago] since 1970-01-01 [50*365 days ago]
--with-user=USER Specify default chronyd user [root] --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] --with-sendmail=PATH Path to sendmail binary [/usr/lib/sendmail]
--enable-debug Enable debugging support --enable-debug Enable debugging support
@@ -214,6 +215,7 @@ feat_asyncdns=1
feat_forcednsretry=1 feat_forcednsretry=1
ntp_era_split="" ntp_era_split=""
default_user="root" default_user="root"
default_hwclockfile=""
mail_program="/usr/lib/sendmail" mail_program="/usr/lib/sendmail"
for option for option
@@ -321,6 +323,9 @@ do
--with-user=* ) --with-user=* )
default_user=`echo $option | sed -e 's/^.*=//;'` default_user=`echo $option | sed -e 's/^.*=//;'`
;; ;;
--with-hwclockfile=* )
default_hwclockfile=`echo $option | sed -e 's/^.*=//;'`
;;
--with-sendmail=* ) --with-sendmail=* )
mail_program=`echo $option | sed -e 's/^.*=//;'` mail_program=`echo $option | sed -e 's/^.*=//;'`
;; ;;
@@ -784,6 +789,7 @@ if [ "x$SETCHRONYVARDIR" != "x" ]; then
fi fi
add_def DEFAULT_CONF_FILE "\"$SYSCONFDIR/chrony.conf\"" add_def DEFAULT_CONF_FILE "\"$SYSCONFDIR/chrony.conf\""
add_def DEFAULT_HWCLOCK_FILE "\"$default_hwclockfile\""
add_def DEFAULT_USER "\"$default_user\"" add_def DEFAULT_USER "\"$default_user\""
add_def DEFAULT_COMMAND_SOCKET "\"$CHRONYSOCKDIR/chronyd.sock\"" add_def DEFAULT_COMMAND_SOCKET "\"$CHRONYSOCKDIR/chronyd.sock\""
add_def MAIL_PROGRAM "\"$mail_program\"" add_def MAIL_PROGRAM "\"$mail_program\""
@@ -824,6 +830,7 @@ do
s%@LOCALSTATEDIR@%${LOCALSTATEDIR}%;\ s%@LOCALSTATEDIR@%${LOCALSTATEDIR}%;\
s%@CHRONYSOCKDIR@%${CHRONYSOCKDIR}%;\ s%@CHRONYSOCKDIR@%${CHRONYSOCKDIR}%;\
s%@CHRONYVARDIR@%${CHRONYVARDIR}%;\ s%@CHRONYVARDIR@%${CHRONYVARDIR}%;\
s%@DEFAULT_HWCLOCK_FILE@%${default_hwclockfile}%;\
s%@DEFAULT_USER@%${default_user}%;"\ s%@DEFAULT_USER@%${default_user}%;"\
< ${f}.in > $f < ${f}.in > $f
done done

View File

@@ -9,7 +9,7 @@ Wants=time-sync.target
Type=oneshot Type=oneshot
# Wait up to ~10 minutes for chronyd to synchronize and the remaining # Wait up to ~10 minutes for chronyd to synchronize and the remaining
# clock correction to be less than 0.1 seconds # 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 RemainAfterExit=yes
StandardOutput=null StandardOutput=null

View File

@@ -5,8 +5,8 @@ pool pool.ntp.org iburst
driftfile /var/lib/chrony/drift driftfile /var/lib/chrony/drift
# In first three updates step the system clock instead of slew # In first three updates step the system clock instead of slew
# if the adjustment is larger than 10 seconds. # if the adjustment is larger than 1 second.
makestep 10 3 makestep 1.0 3
# Enable kernel synchronization of the real-time clock (RTC). # Enable kernel synchronization of the real-time clock (RTC).
rtcsync rtcsync

View File

@@ -6,8 +6,8 @@ pool pool.ntp.org iburst
driftfile /var/lib/chrony/drift driftfile /var/lib/chrony/drift
# In first three updates step the system clock instead of slew # In first three updates step the system clock instead of slew
# if the adjustment is larger than 10 seconds. # if the adjustment is larger than 1 second.
makestep 10 3 makestep 1.0 3
# Enable kernel synchronization of the real-time clock (RTC). # Enable kernel synchronization of the real-time clock (RTC).
rtcsync rtcsync

View File

@@ -128,15 +128,15 @@ driftfile /var/lib/chrony/drift
####################################################################### #######################################################################
### INITIAL CLOCK CORRECTION ### INITIAL CLOCK CORRECTION
# This option is useful to quickly correct the clock on start if it's # 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 # off by a large amount. The value '1.0' means that if the error is less
# than 10 seconds, it will be gradually removed by speeding up or # than 1 second, it will be gradually removed by speeding up or slowing
# slowing down your computer's clock until it is correct. If the error # down your computer's clock until it is correct. If the error is above
# is above 10 seconds, an immediate time jump will be applied to correct # 1 second, an immediate time jump will be applied to correct it. The
# it. The value '1' means the step is allowed only on the first update # value '3' means the step is allowed only in the first three updates of
# of the clock. Some software can get upset if the system clock jumps # the clock. Some software can get upset if the system clock jumps
# (especially backwards), so be careful! # (especially backwards), so be careful!
! makestep 10 1 ! makestep 1.0 3
####################################################################### #######################################################################
### LOGGING ### LOGGING

62
rtc.c
View File

@@ -39,11 +39,12 @@
/* ================================================== */ /* ================================================== */
static int driver_initialised = 0; static int driver_initialised = 0;
static int driver_preinit_ok = 0;
static struct { static struct {
int (*init)(void); int (*init)(void);
void (*fini)(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 (*time_init)(void (*after_hook)(void*), void *anything);
void (*start_measurements)(void); void (*start_measurements)(void);
int (*write_parameters)(void); int (*write_parameters)(void);
@@ -73,29 +74,37 @@ static struct {
}; };
/* ================================================== */ /* ================================================== */
/* Set the system clock to the time of last modification of driftfile /* Get the last modification time of the driftfile */
if it's in the future */
static void static time_t
fallback_time_init(void) get_driftfile_time(void)
{ {
struct timeval now;
struct stat buf; struct stat buf;
char *drift_file; char *drift_file;
drift_file = CNF_GetDriftFile(); drift_file = CNF_GetDriftFile();
if (!drift_file) if (!drift_file)
return; return 0;
if (stat(drift_file, &buf)) 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); LCL_ReadCookedTime(&now, NULL);
if (now.tv_sec < buf.st_mtime) { if (now.tv_sec < t) {
if (LCL_ApplyStepOffset(now.tv_sec - buf.st_mtime)) if (LCL_ApplyStepOffset(now.tv_sec - t))
LOG(LOGS_INFO, LOGF_Rtc, "System clock set from driftfile %s", LOG(LOGS_INFO, LOGF_Rtc, "System time restored from driftfile");
drift_file);
} }
} }
@@ -104,15 +113,24 @@ fallback_time_init(void)
void void
RTC_Initialise(int initial_set) RTC_Initialise(int initial_set)
{ {
time_t driftfile_time;
char *file_name; char *file_name;
/* Do an initial read of the RTC and set the system time to it. This /* If the -s option was specified, try to do an initial read of the RTC and
is analogous to what /sbin/hwclock -s would do on Linux. If that fails set the system time to it. Also, read the last modification time of the
or RTC is not supported, set the clock to the time of the last driftfile (i.e. system time when chronyd was previously stopped) and set
modification of driftfile, so we at least get closer to the truth. */ 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 (initial_set) {
if (!driver.time_pre_init || !driver.time_pre_init()) { driftfile_time = get_driftfile_time();
fallback_time_init();
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 /* 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 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 drift rate of the RTC and the error the last time we set it. If the
TimePreInit routine has already run, so we can be sure that the TimePreInit routine has succeeded, we can be sure that the trim required
trim required is not *too* large. is not *too* large.
We are called with a hook to a function to be called after the 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 initialisation is complete. We also call this if we cannot do the
@@ -161,7 +179,7 @@ RTC_Finalise(void)
void void
RTC_TimeInit(void (*after_hook)(void *), void *anything) RTC_TimeInit(void (*after_hook)(void *), void *anything)
{ {
if (driver_initialised) { if (driver_initialised && driver_preinit_ok) {
(driver.time_init)(after_hook, anything); (driver.time_init)(after_hook, anything);
} else { } else {
(after_hook)(anything); (after_hook)(anything);

View File

@@ -367,6 +367,9 @@ t_from_rtc(struct tm *stm) {
t2 = mktime(&temp2); t2 = mktime(&temp2);
diff = t2 - t1; diff = t2 - t1;
if (t1 - diff == -1)
DEBUG_LOG(LOGF_RtcLinux, "Could not convert RTC time");
return t1 - diff; return t1 - diff;
} }
@@ -379,13 +382,13 @@ read_hwclock_file(const char *hwclock_file)
char line[256]; char line[256];
int i; int i;
if (!hwclock_file) if (!hwclock_file || !hwclock_file[0])
return; return;
in = fopen(hwclock_file, "r"); in = fopen(hwclock_file, "r");
if (!in) { if (!in) {
LOG(LOGS_WARN, LOGF_RtcLinux, "Could not open hwclockfile %s", LOG(LOGS_WARN, LOGF_RtcLinux, "Could not open %s : %s",
hwclock_file); hwclock_file, strerror(errno));
return; return;
} }
@@ -402,7 +405,7 @@ read_hwclock_file(const char *hwclock_file)
} else if (i == 3 && !strncmp(line, "UTC", 3)) { } else if (i == 3 && !strncmp(line, "UTC", 3)) {
rtc_on_utc = 1; rtc_on_utc = 1;
} else { } 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); hwclock_file);
} }
} }
@@ -445,7 +448,7 @@ read_coefs_from_file(void)
&file_ref_offset, &file_ref_offset,
&file_rate_ppm) == 4) { &file_rate_ppm) == 4) {
} else { } 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); coefs_file_name);
} }
fclose(in); fclose(in);
@@ -607,14 +610,16 @@ switch_interrupts(int onoff)
if (onoff) { if (onoff) {
status = ioctl(fd, RTC_UIE_ON, 0); status = ioctl(fd, RTC_UIE_ON, 0);
if (status < 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; return;
} }
skip_interrupts = 1; skip_interrupts = 1;
} else { } else {
status = ioctl(fd, RTC_UIE_OFF, 0); status = ioctl(fd, RTC_UIE_OFF, 0);
if (status < 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; return;
} }
} }
@@ -694,10 +699,11 @@ handle_initial_trim(void)
/* sys_error_now is positive if the system clock is fast */ /* sys_error_now is positive if the system clock is fast */
sys_error_now = rtc_error_now - coef_seconds_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); 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 { } 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; coefs_valid = 0;
@@ -722,7 +728,7 @@ handle_relock_after_trim(void)
if (valid) { if (valid) {
write_coefs_to_file(1,ref,fast,saved_coef_gain_rate); write_coefs_to_file(1,ref,fast,saved_coef_gain_rate);
} else { } 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; coefs_valid = 0;
@@ -857,7 +863,6 @@ read_from_device(void *any)
rtc_t = t_from_rtc(&rtc_tm); rtc_t = t_from_rtc(&rtc_tm);
if (rtc_t == (time_t)(-1)) { if (rtc_t == (time_t)(-1)) {
LOG(LOGS_ERR, LOGF_RtcLinux, "Could not convert RTC time to timeval");
error = 1; error = 1;
goto turn_off_interrupt; goto turn_off_interrupt;
} }
@@ -883,7 +888,7 @@ turn_off_interrupt:
switch (operating_mode) { switch (operating_mode) {
case OM_INITIAL: case OM_INITIAL:
if (error) { 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; operating_mode = OM_NORMAL;
(after_init_hook)(after_init_hook_arg); (after_init_hook)(after_init_hook_arg);
@@ -897,7 +902,7 @@ turn_off_interrupt:
case OM_AFTERTRIM: case OM_AFTERTRIM:
if (error) { 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; operating_mode = OM_NORMAL;
switch_interrupts(0); switch_interrupts(0);
@@ -974,7 +979,7 @@ RTC_Linux_WriteParameters(void)
RTC behaviour than we do for the rest of the module. */ RTC behaviour than we do for the rest of the module. */
int int
RTC_Linux_TimePreInit(void) RTC_Linux_TimePreInit(time_t driftfile_time)
{ {
int fd, status; int fd, status;
struct rtc_time rtc_raw, rtc_raw_retry; 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); 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); UTI_DiffTimevalsToDouble(&sys_offset, &old_sys_time, &new_sys_time);
/* Set system time only if the step is larger than 1 second */ /* Set system time only if the step is larger than 1 second */
if (fabs(sys_offset) >= 1.0) { if (fabs(sys_offset) >= 1.0) {
if (LCL_ApplyStepOffset(sys_offset)) if (LCL_ApplyStepOffset(sys_offset))
LOG(LOGS_INFO, LOGF_RtcLinux, "Set system time, error in RTC = %f", LOG(LOGS_INFO, LOGF_RtcLinux, "System time set from RTC");
accumulated_error);
} }
} else { } else {
LOG(LOGS_WARN, LOGF_RtcLinux, "Could not convert RTC reading to seconds since 1/1/1970");
return 0; return 0;
} }
} else { } else {
@@ -1092,7 +1100,8 @@ RTC_Linux_Trim(void)
if (fabs(coef_seconds_fast) > 1.0) { 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 /* 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 RTC to, then in 500ms the RTC ticks (R+1) (see comments in

View File

@@ -30,7 +30,7 @@
extern int RTC_Linux_Initialise(void); extern int RTC_Linux_Initialise(void);
extern void RTC_Linux_Finalise(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_TimeInit(void (*after_hook)(void *), void *anything);
extern void RTC_Linux_StartMeasurements(void); extern void RTC_Linux_StartMeasurements(void);

View File

@@ -563,7 +563,7 @@ SYS_Linux_EnableSystemCallFilter(int level)
} }
if (seccomp_load(ctx) < 0) 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"); LOG(LOGS_INFO, LOGF_SysLinux, "Loaded seccomp filter");
seccomp_release(ctx); seccomp_release(ctx);