cmdmon: convert doffset request to float

This commit is contained in:
Miroslav Lichvar 2021-03-03 18:18:54 +01:00
parent e86b60a9d7
commit 52b29f673f
4 changed files with 12 additions and 16 deletions

View file

@ -108,7 +108,8 @@
#define REQ_CLIENT_ACCESSES_BY_INDEX3 68
#define REQ_SELECT_DATA 69
#define REQ_RELOAD_SOURCES 70
#define N_REQUEST_TYPES 71
#define REQ_DOFFSET2 71
#define N_REQUEST_TYPES 72
/* Structure used to exchange timespecs independent of time_t size */
typedef struct {
@ -308,8 +309,7 @@ typedef struct {
} REQ_Dfreq;
typedef struct {
int32_t sec;
int32_t usec;
Float doffset;
int32_t EOR;
} REQ_Doffset;
@ -404,7 +404,7 @@ typedef struct {
domain socket.
Version 6 (no authentication) : changed format of client accesses by index
(using new request/reply types) and manual timestamp, added new fields and
(two times), delta offset, and manual timestamp, added new fields and
flags to NTP source request and report, made length of manual list constant,
added new commands: authdata, ntpdata, onoffline, refresh, reset,
selectdata, serverstats, shutdown, sourcename

View file

@ -1008,19 +1008,16 @@ process_cmd_dfreq(CMD_Request *msg, char *line)
static int
process_cmd_doffset(CMD_Request *msg, char *line)
{
struct timeval tv;
double doffset;
msg->command = htons(REQ_DOFFSET);
msg->command = htons(REQ_DOFFSET2);
if (sscanf(line, "%lf", &doffset) != 1) {
LOG(LOGS_ERR, "Invalid value");
return 0;
}
UTI_DoubleToTimeval(doffset, &tv);
msg->data.doffset.sec = htonl(tv.tv_sec);
msg->data.doffset.usec = htonl(tv.tv_usec);
msg->data.doffset.doffset = UTI_FloatHostToNetwork(doffset);
return 1;
}

View file

@ -143,6 +143,7 @@ static const char permissions[] = {
PERMIT_AUTH, /* CLIENT_ACCESSES_BY_INDEX3 */
PERMIT_AUTH, /* SELECT_DATA */
PERMIT_AUTH, /* RELOAD_SOURCES */
PERMIT_AUTH, /* DOFFSET2 */
};
/* ================================================== */
@ -856,13 +857,10 @@ handle_dfreq(CMD_Request *rx_message, CMD_Reply *tx_message)
static void
handle_doffset(CMD_Request *rx_message, CMD_Reply *tx_message)
{
long sec, usec;
double doffset;
sec = (int32_t)ntohl(rx_message->data.doffset.sec);
usec = (int32_t)ntohl(rx_message->data.doffset.usec);
doffset = (double) sec + 1.0e-6 * (double) usec;
LOG(LOGS_INFO, "Accumulated delta offset of %.6f seconds", doffset);
doffset = UTI_FloatNetworkToHost(rx_message->data.doffset.doffset);
LCL_AccumulateOffset(doffset, 0.0);
LOG(LOGS_INFO, "Accumulated delta offset of %.6f seconds", doffset);
}
/* ================================================== */
@ -1637,7 +1635,7 @@ read_from_cmd_socket(int sock_fd, int event, void *anything)
handle_dfreq(&rx_message, &tx_message);
break;
case REQ_DOFFSET:
case REQ_DOFFSET2:
handle_doffset(&rx_message, &tx_message);
break;

View file

@ -87,7 +87,7 @@ static const struct request_length request_lengths[] = {
REQ_LENGTH_ENTRY(del_source, null), /* DEL_SOURCE */
REQ_LENGTH_ENTRY(null, null), /* WRITERTC */
REQ_LENGTH_ENTRY(dfreq, null), /* DFREQ */
REQ_LENGTH_ENTRY(doffset, null), /* DOFFSET */
{ 0, 0 }, /* DOFFSET - not supported */
REQ_LENGTH_ENTRY(null, tracking), /* TRACKING */
REQ_LENGTH_ENTRY(sourcestats, sourcestats), /* SOURCESTATS */
REQ_LENGTH_ENTRY(null, rtc), /* RTCREPORT */
@ -128,6 +128,7 @@ static const struct request_length request_lengths[] = {
client_accesses_by_index), /* CLIENT_ACCESSES_BY_INDEX3 */
REQ_LENGTH_ENTRY(select_data, select_data), /* SELECT_DATA */
REQ_LENGTH_ENTRY(null, null), /* RELOAD_SOURCES */
REQ_LENGTH_ENTRY(doffset, null), /* DOFFSET2 */
};
static const uint16_t reply_lengths[] = {