diff --git a/conf.c b/conf.c index 5d2ba15..fa74459 100644 --- 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'; diff --git a/ntp_sources.c b/ntp_sources.c index 28af1c1..d8bd2d8 100644 --- a/ntp_sources.c +++ b/ntp_sources.c @@ -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) { diff --git a/ntp_sources.h b/ntp_sources.h index ba3b9c4..5aeb1a3 100644 --- a/ntp_sources.h +++ b/ntp_sources.h @@ -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 cb7b9a6..b729c2f 100644 --- 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) { diff --git a/test/unit/ntp_sources.c b/test/unit/ntp_sources.c index 1626552..e3d7c4d 100644 --- a/test/unit/ntp_sources.c +++ b/test/unit/ntp_sources.c @@ -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; }