]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
conf: improve log message for failed additions in sources reload
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 11 Sep 2023 14:14:53 +0000 (16:14 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 12 Sep 2023 06:11:25 +0000 (08:11 +0200)
Describe the error status in the log message when adding a source from
sourcedir failed.

conf.c
ntp_sources.c
ntp_sources.h
stubs.c
test/unit/ntp_sources.c

diff --git a/conf.c b/conf.c
index 5d2ba15a4271070871971b80b4c5bbf2183afbbb..fa74459440cad84eb363e7f931ccd708e306b8e6 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -1734,7 +1734,8 @@ reload_source_dirs(void)
         if (s == NSR_UnresolvedName) {
           unresolved++;
         } else if (s != NSR_Success) {
-          LOG(LOGS_ERR, "Could not add source %s", source->params.name);
+          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';
index 28af1c1051ece42389bd1c9f7eeca022c9ed47ca..d8bd2d832053526c072cc6cc491a46f129eccdcd 100644 (file)
@@ -844,6 +844,31 @@ NSR_AddSourceByName(char *name, int port, int pool, NTP_Source_Type type,
 
 /* ================================================== */
 
+const char *
+NSR_StatusToString(NSR_Status status)
+{
+  switch (status) {
+    case NSR_Success:
+      return "Success";
+    case NSR_NoSuchSource:
+      return "No such source";
+    case NSR_AlreadyInUse:
+      return "Already in use";
+    case NSR_TooManySources:
+      return "Too many sources";
+    case NSR_InvalidAF:
+      return "Invalid address";
+    case NSR_InvalidName:
+      return "Invalid name";
+    case NSR_UnresolvedName:
+      return "Unresolved name";
+    default:
+      return "?";
+  }
+}
+
+/* ================================================== */
+
 void
 NSR_SetSourceResolvingEndHandler(NSR_SourceResolvingEndHandler handler)
 {
index ba3b9c4b9e05a6778fbddea789afad5c05a63191..5aeb1a3da9daf9fabf403bd151f0aaf6e0fdf138 100644 (file)
@@ -60,6 +60,8 @@ extern NSR_Status NSR_AddSource(NTP_Remote_Address *remote_addr, NTP_Source_Type
 extern NSR_Status NSR_AddSourceByName(char *name, int port, int pool, NTP_Source_Type type,
                                       SourceParameters *params, uint32_t *conf_id);
 
+extern const char *NSR_StatusToString(NSR_Status status);
+
 /* Function type for handlers to be called back when an attempt
  * (possibly unsuccessful) to resolve unresolved sources ends */
 typedef void (*NSR_SourceResolvingEndHandler)(void);
diff --git a/stubs.c b/stubs.c
index cb7b9a655cd844cd999cc76057efa3ccd942b949..b729c2f6a6dc69391c84eb21e5da38e7f8de4edd 100644 (file)
--- a/stubs.c
+++ b/stubs.c
@@ -207,6 +207,12 @@ NSR_AddSourceByName(char *name, int port, int pool, NTP_Source_Type type,
   return NSR_TooManySources;
 }
 
+const char *
+NSR_StatusToString(NSR_Status status)
+{
+  return "NTP not supported";
+}
+
 NSR_Status
 NSR_RemoveSource(IPAddr *address)
 {
index 162655200c9503669ca9e79e89cec4627a6c9575..e3d7c4d5d3386880325ed351193c0a55af05395f 100644 (file)
@@ -88,6 +88,8 @@ update_random_address(NTP_Remote_Address *addr, int rand_bits)
     TEST_CHECK(status == NSR_Success || status == NSR_AlreadyInUse);
   }
 
+  TEST_CHECK(strlen(NSR_StatusToString(status)) > 0);
+
   return status == NSR_Success;
 }