From 916ed70c4a815d7dcbd99eb8ed003ad508044c98 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 6 Aug 2024 12:56:39 +0200 Subject: [PATCH] conf: save source status in sourcedir reload 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 | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/conf.c b/conf.c index b1fd36e..f18dfa9 100644 --- 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; + } } }