Add option to ignore initstepslew and makestep directives

When chronyd is started with -R, the initstepslew directive and the
makestep directive with a positive limit will be ignored. This is useful
when restarting chronyd to avoid unnecessary clock adjustments. It can
be used with -r.
This commit is contained in:
Miroslav Lichvar 2013-04-26 16:27:15 +02:00
parent 4933c216b2
commit f2eb6b165a
5 changed files with 37 additions and 1 deletions

View file

@ -1067,6 +1067,12 @@ maintain clock compensation whilst not under @code{chronyd's} control.
The only version where this happens so far is Linux. On systems where
this is not the case, e.g. Solaris and SunOS the option should not be
used.
@item -R
When this option is used, the @code{initstepslew} directive and the
@code{makestep} directive used with a positive limit will be ignored.
This option is useful when restarting @code{chronyd} and can be used
in conjuction 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

View file

@ -69,6 +69,12 @@ systems where the kernel can maintain clock compensation whilst not under
On systems where this is not the case, e.g. Solaris and SunOS the option
should not be used.
.TP
.B \-R
When this option is used, the \fIinitstepslew\fR directive and the
\fImakestep\fR directive used with a positive limit will be ignored. This
option is useful when restarting \fBchronyd\fR and can be used in conjuction
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

19
conf.c
View file

@ -117,6 +117,7 @@ static void parse_leapsectz(const char *);
/* ================================================== */
/* Configuration variables */
static int restarted = 0;
static char *rtc_device = "/dev/rtc";
static int acquisition_port = 0; /* 0 means let kernel choose port */
static int ntp_port = 123;
@ -325,6 +326,14 @@ static AllowDeny cmd_auth_list = {&cmd_auth_list, &cmd_auth_list};
/* ================================================== */
void
CNF_SetRestarted(int r)
{
restarted = r;
}
/* ================================================== */
/* Read the configuration file */
void
CNF_ReadFile(const char *filename)
@ -853,6 +862,11 @@ parse_initstepslew(const char *line)
int threshold;
IPAddr ip_addr;
/* Ignore the line if chronyd was started with -R. */
if (restarted) {
return;
}
n_init_srcs = 0;
p = line;
@ -955,6 +969,11 @@ parse_makestep(const char *line)
"Could not read threshold or update limit for stepping clock at line %d\n",
line_number);
}
/* Disable limited makestep if chronyd was started with -R. */
if (restarted && make_step_limit > 0) {
make_step_limit = 0;
}
}
/* ================================================== */

2
conf.h
View file

@ -29,6 +29,8 @@
#include "addressing.h"
extern void CNF_SetRestarted(int);
extern char *CNF_GetRtcDevice(void);
extern void CNF_ReadFile(const char *filename);

5
main.c
View file

@ -287,7 +287,7 @@ int main
char *conf_file = NULL;
char *user = NULL;
int debug = 0, nofork = 0;
int do_init_rtc = 0;
int do_init_rtc = 0, restarted = 0;
int other_pid;
int lock_memory = 0, sched_priority = 0;
@ -308,6 +308,8 @@ int main
lock_memory = 1;
} else if (!strcmp("-r", *argv)) {
reload = 1;
} else if (!strcmp("-R", *argv)) {
restarted = 1;
} else if (!strcmp("-u", *argv)) {
++argv, --argc;
if (argc == 0) {
@ -352,6 +354,7 @@ int main
LOG(LOGS_INFO, LOGF_Main, "chronyd version %s starting", CHRONY_VERSION);
CNF_SetRestarted(restarted);
CNF_ReadFile(conf_file);
/* Check whether another chronyd may already be running. Do this after