From: Miroslav Lichvar Date: Mon, 1 Jun 2020 15:22:58 +0000 (+0200) Subject: sources: include hostname in selection log message X-Git-Tag: 4.0-pre3~106 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bc46174e98fabe3ee17915286e23faf98d21706d;p=thirdparty%2Fchrony.git sources: include hostname in selection log message When selecting an NTP source, include the hostname in the log message. --- diff --git a/sources.c b/sources.c index 160977bf..6ae77142 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 1c666297..a314a2eb 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();