Add reselect command

This commit is contained in:
Miroslav Lichvar 2010-12-07 16:21:24 +01:00
parent 2d326bfc48
commit 6e96b4ba33
7 changed files with 60 additions and 2 deletions

View file

@ -89,7 +89,8 @@
#define REQ_MODIFY_MINSTRATUM 45
#define REQ_MODIFY_POLLTARGET 46
#define REQ_MODIFY_MAXDELAYDEVRATIO 47
#define N_REQUEST_TYPES 48
#define REQ_RESELECT 48
#define N_REQUEST_TYPES 49
/* Special utoken value used to log on with first exchange being the
password. (This time value has long since gone by) */
@ -338,6 +339,10 @@ typedef struct {
int32_t EOR;
} REQ_Activity;
typedef struct {
int32_t EOR;
} REQ_Reselect;
/* ================================================== */
#define PKT_TYPE_CMD_REQUEST 1
@ -423,6 +428,7 @@ typedef struct {
REQ_ManualDelete manual_delete;
REQ_MakeStep make_step;
REQ_Activity activity;
REQ_Reselect reselect;
} data; /* Command specific parameters */
} CMD_Request;

View file

@ -2883,6 +2883,7 @@ interface.
* password command:: Provide password needed for most commands
* polltarget command:: Set poll target for a source
* quit command:: Exit from chronyc
* reselect command:: Reselect synchronisation source
* retries command:: Set maximum number of retries
* rtcdata command:: Display RTC parameters
* settime command:: Provide a manual input of the current time
@ -3695,6 +3696,16 @@ to 12.
The quit command exits from chronyc and returns the user to the shell
(same as the exit command).
@c }}}
@c {{{ reselect command
@node reselect command
@subsubsection reselect
To avoid excessive switching between sources, @code{chronyd} may stay
synchronised to a source even when it is not currently the best one among the
available sources.
The @code{reselect} command can be used to force @code{chronyd} to
reselect the best synchronisation source.
@c }}}
@c {{{ retries
@node retries command
@subsubsection retries

View file

@ -1231,6 +1231,7 @@ give_help(void)
printf("online [<mask>/<masked-address>] : Set sources in subnet to online status\n");
printf("password [<new-password>] : Set command authentication password\n");
printf("polltarget <address> <new-poll-target> : Modify poll target of source\n");
printf("reselect : Reselect synchronisation source\n");
printf("rtcdata : Print current RTC performance parameters\n");
printf("settime <date/time (e.g. Nov 21, 1997 16:30:05 or 16:30:05)> : Manually set the daemon time\n");
printf("sources [-v] : Display information about current sources\n");
@ -2372,6 +2373,14 @@ process_cmd_activity(const char *line)
/* ================================================== */
static void
process_cmd_reselect(CMD_Request *msg, char *line)
{
msg->command = htons(REQ_RESELECT);
}
/* ================================================== */
static int
process_cmd_dns(const char *line)
{
@ -2545,6 +2554,8 @@ process_line(char *line, int *quit)
} else if (!strncmp(p, "activity", 8)) {
ret = process_cmd_activity(p+8);
do_normal_submit = 0;
} else if (!strncmp(p, "reselect", 8)) {
process_cmd_reselect(&tx_message, p+8);
} else if (!strncmp(p, "dns ", 4)) {
ret = process_cmd_dns(p+4);
do_normal_submit = 0;

View file

@ -161,7 +161,8 @@ static int permissions[] = {
PERMIT_OPEN, /* ACTIVITY */
PERMIT_AUTH, /* MODIFY_MINSTRATUM */
PERMIT_AUTH, /* MODIFY_POLLTARGET */
PERMIT_AUTH /* MODIFY_MAXDELAYDEVRATIO */
PERMIT_AUTH, /* MODIFY_MAXDELAYDEVRATIO */
PERMIT_AUTH /* RESELECT */
};
/* ================================================== */
@ -1709,6 +1710,16 @@ handle_activity(CMD_Request *rx_message, CMD_Reply *tx_message)
/* ================================================== */
static void
handle_reselect(CMD_Request *rx_message, CMD_Reply *tx_message)
{
SRC_ReselectSource();
tx_message->status = htons(STT_SUCCESS);
return;
}
/* ================================================== */
#if 0
/* ================================================== */
@ -2236,6 +2247,10 @@ read_from_cmd_socket(void *anything)
handle_activity(&rx_message, &tx_message);
break;
case REQ_RESELECT:
handle_reselect(&rx_message, &tx_message);
break;
case REQ_MODIFY_MINSTRATUM:
handle_modify_minstratum(&rx_message, &tx_message);
break;

View file

@ -149,6 +149,8 @@ PKL_CommandLength(CMD_Request *r)
return offsetof(CMD_Request, data.make_step.EOR);
case REQ_ACTIVITY:
return offsetof(CMD_Request, data.activity.EOR);
case REQ_RESELECT:
return offsetof(CMD_Request, data.reselect.EOR);
case REQ_MODIFY_MINSTRATUM:
return offsetof(CMD_Request, data.modify_minstratum.EOR);
case REQ_MODIFY_POLLTARGET:

View file

@ -778,6 +778,16 @@ SRC_SelectSource(unsigned long match_addr)
}
/* ================================================== */
/* Force reselecting the best source */
void
SRC_ReselectSource(void)
{
selected_source_index = INVALID_SOURCE;
SRC_SelectSource(0);
}
/* ================================================== */
double

View file

@ -136,6 +136,9 @@ extern void SRC_UnsetReachable(SRC_Instance instance);
selected reference make a difference) */
extern void SRC_SelectSource(unsigned long match_addr);
/* Force reselecting the best source */
extern void SRC_ReselectSource(void);
/* Predict the offset of the local clock relative to a given source at
a given local cooked time. Positive indicates local clock is FAST
relative to reference. */