From bc46174e98fabe3ee17915286e23faf98d21706d Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Mon, 1 Jun 2020 17:22:58 +0200 Subject: [PATCH] sources: include hostname in selection log message When selecting an NTP source, include the hostname in the log message. --- sources.c | 21 +++++++++++++++++++-- test/unit/sources.c | 2 ++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/sources.c b/sources.c index 160977b..6ae7714 100644 --- a/sources.c +++ b/sources.c @@ -573,6 +573,24 @@ log_selection_message(const char *format, const char *arg) /* ================================================== */ +static void +log_selection_source(const char *format, SRC_Instance inst) +{ + char buf[320], *name, *ntp_name; + + name = source_to_string(inst); + ntp_name = inst->type == SRC_NTP ? NSR_GetName(inst->ip_addr) : NULL; + + if (ntp_name && strcmp(name, ntp_name) != 0) + snprintf(buf, sizeof (buf), "%s (%s)", name, ntp_name); + else + snprintf(buf, sizeof (buf), "%s", name); + + log_selection_message(format, buf); +} + +/* ================================================== */ + static int compare_sort_elements(const void *a, const void *b) { @@ -1166,8 +1184,7 @@ SRC_SelectSource(SRC_Instance updated_inst) } selected_source_index = max_score_index; - log_selection_message("Selected source %s", - source_to_string(sources[selected_source_index])); + log_selection_source("Selected source %s", sources[selected_source_index]); /* New source has been selected, reset all scores */ for (i = 0; i < n_sources; i++) { diff --git a/test/unit/sources.c b/test/unit/sources.c index 1c66629..a314a2e 100644 --- a/test/unit/sources.c +++ b/test/unit/sources.c @@ -49,6 +49,7 @@ test_unit(void) SCH_Initialise(); SRC_Initialise(); REF_Initialise(); + NSR_Initialise(); REF_SetMode(REF_ModeIgnore); @@ -224,6 +225,7 @@ test_unit(void) } } + NSR_Finalise(); REF_Finalise(); SRC_Finalise(); SCH_Finalise();