From 6e96b4ba333a45bc21f5a1dd2b23369bd3d8d8ad Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 7 Dec 2010 16:21:24 +0100 Subject: [PATCH] Add reselect command --- candm.h | 8 +++++++- chrony.texi | 11 +++++++++++ client.c | 11 +++++++++++ cmdmon.c | 17 ++++++++++++++++- pktlength.c | 2 ++ sources.c | 10 ++++++++++ sources.h | 3 +++ 7 files changed, 60 insertions(+), 2 deletions(-) diff --git a/candm.h b/candm.h index ac8e4cb..d79b00c 100644 --- a/candm.h +++ b/candm.h @@ -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; diff --git a/chrony.texi b/chrony.texi index 823e20c..f52729a 100644 --- a/chrony.texi +++ b/chrony.texi @@ -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 diff --git a/client.c b/client.c index ecea90c..e6dbd61 100644 --- a/client.c +++ b/client.c @@ -1231,6 +1231,7 @@ give_help(void) printf("online [/] : Set sources in subnet to online status\n"); printf("password [] : Set command authentication password\n"); printf("polltarget
: Modify poll target of source\n"); + printf("reselect : Reselect synchronisation source\n"); printf("rtcdata : Print current RTC performance parameters\n"); printf("settime : 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; diff --git a/cmdmon.c b/cmdmon.c index e5a6f43..c8fc5b0 100644 --- a/cmdmon.c +++ b/cmdmon.c @@ -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; diff --git a/pktlength.c b/pktlength.c index dc1d059..788a367 100644 --- a/pktlength.c +++ b/pktlength.c @@ -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: diff --git a/sources.c b/sources.c index 20c0855..3dcfc42 100644 --- a/sources.c +++ b/sources.c @@ -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 diff --git a/sources.h b/sources.h index b731191..4351e13 100644 --- a/sources.h +++ b/sources.h @@ -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. */