]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sources: switch unselect_selected_source() to variable arguments
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 13 Mar 2025 14:40:47 +0000 (15:40 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 13 Mar 2025 15:25:42 +0000 (16:25 +0100)
Switch the function to the full printf style, which will be needed to
log an integer.

sources.c

index d7c112317e0e042f84074b61bae77d660d1b1387..edd145a0ab0cbbe5f1ef68474c637e0609dbf392 100644 (file)
--- 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;
     }