conf: improve log message for failed additions in sources reload

Describe the error status in the log message when adding a source from
sourcedir failed.
This commit is contained in:
Miroslav Lichvar 2023-09-11 16:14:53 +02:00
parent 37deee7140
commit aa8196328c
5 changed files with 37 additions and 1 deletions

3
conf.c
View file

@ -1734,7 +1734,8 @@ reload_source_dirs(void)
if (s == NSR_UnresolvedName) { if (s == NSR_UnresolvedName) {
unresolved++; unresolved++;
} else if (s != NSR_Success) { } 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 */ /* Mark the source as not present */
source->params.name[0] = '\0'; source->params.name[0] = '\0';

View 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 void
NSR_SetSourceResolvingEndHandler(NSR_SourceResolvingEndHandler handler) NSR_SetSourceResolvingEndHandler(NSR_SourceResolvingEndHandler handler)
{ {

View 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, extern NSR_Status NSR_AddSourceByName(char *name, int port, int pool, NTP_Source_Type type,
SourceParameters *params, uint32_t *conf_id); 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 /* Function type for handlers to be called back when an attempt
* (possibly unsuccessful) to resolve unresolved sources ends */ * (possibly unsuccessful) to resolve unresolved sources ends */
typedef void (*NSR_SourceResolvingEndHandler)(void); typedef void (*NSR_SourceResolvingEndHandler)(void);

View file

@ -207,6 +207,12 @@ NSR_AddSourceByName(char *name, int port, int pool, NTP_Source_Type type,
return NSR_TooManySources; return NSR_TooManySources;
} }
const char *
NSR_StatusToString(NSR_Status status)
{
return "NTP not supported";
}
NSR_Status NSR_Status
NSR_RemoveSource(IPAddr *address) NSR_RemoveSource(IPAddr *address)
{ {

View 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(status == NSR_Success || status == NSR_AlreadyInUse);
} }
TEST_CHECK(strlen(NSR_StatusToString(status)) > 0);
return status == NSR_Success; return status == NSR_Success;
} }