From: Miroslav Lichvar Date: Thu, 13 Mar 2025 14:40:47 +0000 (+0100) Subject: sources: switch unselect_selected_source() to variable arguments X-Git-Tag: 4.7-pre1~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c27a298d9c868100825b160c60740060f0954275;p=thirdparty%2Fchrony.git sources: switch unselect_selected_source() to variable arguments Switch the function to the full printf style, which will be needed to log an integer. --- diff --git a/sources.c b/sources.c index d7c11231..edd145a0 100644 --- a/sources.c +++ b/sources.c @@ -206,8 +206,7 @@ static LOG_FileID logfileid; /* Forward prototype */ static void update_sel_options(void); -static void unselect_selected_source(LOG_Severity severity, const char *format, - const char *arg); +static void unselect_selected_source(LOG_Severity severity, const char *format, ...); static void slew_sources(struct timespec *raw, struct timespec *cooked, double dfreq, double doffset, LCL_ChangeType change_type, void *anything); static void add_dispersion(double dispersion, void *anything); @@ -339,7 +338,7 @@ void SRC_DestroyInstance(SRC_Instance instance) if (selected_source_index > dead_index) --selected_source_index; else if (selected_source_index == dead_index) - unselect_selected_source(LOGS_INFO, NULL, NULL); + unselect_selected_source(LOGS_INFO, NULL); SRC_SelectSource(NULL); } @@ -813,16 +812,24 @@ mark_ok_sources(SRC_Status status) call providing a message or selection of another source, which resets the report_selection_loss flag. */ +FORMAT_ATTRIBUTE_PRINTF(2, 3) static void -unselect_selected_source(LOG_Severity severity, const char *format, const char *arg) +unselect_selected_source(LOG_Severity severity, const char *format, ...) { + char buf[256]; + va_list ap; + if (selected_source_index != INVALID_SOURCE) { selected_source_index = INVALID_SOURCE; report_selection_loss = 1; } if (report_selection_loss && format) { - log_selection_message(severity, format, arg); + va_start(ap, format); + vsnprintf(buf, sizeof (buf), format, ap); + va_end(ap); + + log_selection_message(severity, "%s", buf); report_selection_loss = 0; } } @@ -945,7 +952,7 @@ SRC_SelectSource(SRC_Instance updated_inst) } if (n_sources == 0) { - unselect_selected_source(LOGS_INFO, "Can't synchronise: no sources", NULL); + unselect_selected_source(LOGS_INFO, "Can't synchronise: no sources"); return; } @@ -1132,7 +1139,7 @@ SRC_SelectSource(SRC_Instance updated_inst) if (n_badstats_sources && n_sel_sources && selected_source_index == INVALID_SOURCE && max_sel_reach_size < SOURCE_REACH_BITS && max_sel_reach >> 1 == max_badstat_reach) { mark_ok_sources(SRC_WAITS_STATS); - unselect_selected_source(LOGS_INFO, NULL, NULL); + unselect_selected_source(LOGS_INFO, NULL); return; } @@ -1146,7 +1153,7 @@ SRC_SelectSource(SRC_Instance updated_inst) if (n_endpoints == 0) { /* No sources provided valid endpoints */ - unselect_selected_source(LOGS_INFO, "Can't synchronise: no selectable sources", NULL); + unselect_selected_source(LOGS_INFO, "Can't synchronise: no selectable sources"); return; } @@ -1400,7 +1407,7 @@ SRC_SelectSource(SRC_Instance updated_inst) /* Before selecting the new synchronisation source wait until the reference can be updated */ if (sources[max_score_index]->updates == 0) { - unselect_selected_source(LOGS_INFO, NULL, NULL); + unselect_selected_source(LOGS_INFO, NULL); mark_ok_sources(SRC_WAITS_UPDATE); return; }