check_ntp_time: add polling delay

NTP server can have rate limiting which might be triggered by
check_ntp_time due to many requests in a short time span.

This patch adds a default delay (of 0.5s) between requests to each server
and a command line option (--poll-delay) to make this delay
configurable.

Co-authored-by: Lorenz Kästle <lorenz@vulgrim.de>
This commit is contained in:
Paul Crawford 2026-06-11 02:02:51 +02:00 committed by Lorenz Kästle
parent cc8d5b55de
commit 8a0dca477a

View file

@ -5,6 +5,9 @@
#include "thresholds.h"
#include <stddef.h>
/* Time in microseconds to delay between polling to avoid a blocking response. */
const long default_polling_delay = 500000L;
typedef struct {
char *server_address;
char *port;
@ -15,6 +18,7 @@ typedef struct {
mp_thresholds offset_thresholds;
bool output_format_is_set;
long poll_delay;
mp_output_format output_format;
} check_ntp_time_config;
@ -29,6 +33,7 @@ check_ntp_time_config check_ntp_time_config_init() {
.offset_thresholds = mp_thresholds_init(),
.output_format_is_set = false,
.poll_delay = default_polling_delay,
};
mp_range warning = mp_range_init();