]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
conf: save source status in sourcedir reload
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 6 Aug 2024 10:56:39 +0000 (12:56 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 7 Aug 2024 07:48:13 +0000 (09:48 +0200)
Save the NSR status when adding a source from a sourcedir and don't
hide sources that failed the addition by clearing their name.

conf.c

diff --git a/conf.c b/conf.c
index b1fd36e54bb3227ea4782f42ee6c7390c841883a..f18dfa90adc7ec0ff71239e4a268af866df636b2 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -294,6 +294,7 @@ typedef struct {
   NTP_Source_Type type;
   int pool;
   CPS_NTP_Source params;
+  NSR_Status status;
   uint32_t conf_id;
 } NTP_Source;
 
@@ -834,6 +835,7 @@ parse_source(char *line, char *type, int fatal)
   }
 
   source.params.name = Strdup(source.params.name);
+  source.status = NSR_NoSuchSource;
   source.conf_id = 0;
 
   ARR_AppendElement(ntp_sources, &source);
@@ -1735,31 +1737,31 @@ reload_source_dirs(void)
         d = i < prev_size ? -1 : 1;
 
       /* Remove missing sources before adding others to avoid conflicts */
-      if (pass == 0 && d < 0 && prev_sources[i].params.name[0] != '\0') {
+      if (pass == 0 && d < 0 && prev_sources[i].status == NSR_Success) {
         NSR_RemoveSourcesById(prev_sources[i].conf_id);
       }
 
-      /* Add new sources */
-      if (pass == 1 && d > 0) {
+      /* Add new sources and sources that could not be added before */
+      if (pass == 1 && (d > 0 || (d == 0 && prev_sources[i].status != NSR_Success))) {
         source = &new_sources[j];
         s = NSR_AddSourceByName(source->params.name, source->params.family, source->params.port,
                                 source->pool, source->type, &source->params.params,
                                 &source->conf_id);
+        source->status = s;
 
         if (s == NSR_UnresolvedName) {
           unresolved++;
         } else if (s != NSR_Success) {
           LOG(LOGS_ERR, "Could not add source %s : %s",
               source->params.name, NSR_StatusToString(s));
-
-          /* Mark the source as not present */
-          source->params.name[0] = '\0';
         }
       }
 
       /* Keep unchanged sources */
-      if (pass == 1 && d == 0)
+      if (pass == 1 && d == 0) {
+        new_sources[j].status = prev_sources[i].status;
         new_sources[j].conf_id = prev_sources[i].conf_id;
+      }
     }
   }