conf: merge ntp_source_ids with ntp_sources
Keep the configuration IDs of sources loaded from sourcedir in the NTP_Source structure itself to simplify the code.
This commit is contained in:
parent
fd9e956d27
commit
8ba2da52df
1 changed files with 9 additions and 19 deletions
28
conf.c
28
conf.c
|
@ -294,15 +294,14 @@ typedef struct {
|
||||||
NTP_Source_Type type;
|
NTP_Source_Type type;
|
||||||
int pool;
|
int pool;
|
||||||
CPS_NTP_Source params;
|
CPS_NTP_Source params;
|
||||||
|
uint32_t conf_id;
|
||||||
} NTP_Source;
|
} NTP_Source;
|
||||||
|
|
||||||
/* Array of NTP_Source */
|
/* Array of NTP_Source */
|
||||||
static ARR_Instance ntp_sources;
|
static ARR_Instance ntp_sources;
|
||||||
/* Array of (char *) */
|
/* Array of (char *) */
|
||||||
static ARR_Instance ntp_source_dirs;
|
static ARR_Instance ntp_source_dirs;
|
||||||
/* Array of uint32_t corresponding to ntp_sources (for sourcedirs reload) */
|
/* Flag indicating ntp_sources is used for sourcedirs after config load */
|
||||||
static ARR_Instance ntp_source_ids;
|
|
||||||
/* Flag indicating ntp_sources and ntp_source_ids are used for sourcedirs */
|
|
||||||
static int conf_ntp_sources_added = 0;
|
static int conf_ntp_sources_added = 0;
|
||||||
|
|
||||||
/* Array of RefclockParameters */
|
/* Array of RefclockParameters */
|
||||||
|
@ -403,7 +402,6 @@ CNF_Initialise(int r, int client_only)
|
||||||
init_sources = ARR_CreateInstance(sizeof (IPAddr));
|
init_sources = ARR_CreateInstance(sizeof (IPAddr));
|
||||||
ntp_sources = ARR_CreateInstance(sizeof (NTP_Source));
|
ntp_sources = ARR_CreateInstance(sizeof (NTP_Source));
|
||||||
ntp_source_dirs = ARR_CreateInstance(sizeof (char *));
|
ntp_source_dirs = ARR_CreateInstance(sizeof (char *));
|
||||||
ntp_source_ids = ARR_CreateInstance(sizeof (uint32_t));
|
|
||||||
refclock_sources = ARR_CreateInstance(sizeof (RefclockParameters));
|
refclock_sources = ARR_CreateInstance(sizeof (RefclockParameters));
|
||||||
broadcasts = ARR_CreateInstance(sizeof (NTP_Broadcast_Destination));
|
broadcasts = ARR_CreateInstance(sizeof (NTP_Broadcast_Destination));
|
||||||
|
|
||||||
|
@ -463,7 +461,6 @@ CNF_Finalise(void)
|
||||||
ARR_DestroyInstance(init_sources);
|
ARR_DestroyInstance(init_sources);
|
||||||
ARR_DestroyInstance(ntp_sources);
|
ARR_DestroyInstance(ntp_sources);
|
||||||
ARR_DestroyInstance(ntp_source_dirs);
|
ARR_DestroyInstance(ntp_source_dirs);
|
||||||
ARR_DestroyInstance(ntp_source_ids);
|
|
||||||
ARR_DestroyInstance(refclock_sources);
|
ARR_DestroyInstance(refclock_sources);
|
||||||
ARR_DestroyInstance(broadcasts);
|
ARR_DestroyInstance(broadcasts);
|
||||||
|
|
||||||
|
@ -837,6 +834,8 @@ parse_source(char *line, char *type, int fatal)
|
||||||
}
|
}
|
||||||
|
|
||||||
source.params.name = Strdup(source.params.name);
|
source.params.name = Strdup(source.params.name);
|
||||||
|
source.conf_id = 0;
|
||||||
|
|
||||||
ARR_AppendElement(ntp_sources, &source);
|
ARR_AppendElement(ntp_sources, &source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1694,7 +1693,6 @@ reload_source_dirs(void)
|
||||||
{
|
{
|
||||||
NTP_Source *prev_sources, *new_sources, *source;
|
NTP_Source *prev_sources, *new_sources, *source;
|
||||||
unsigned int i, j, prev_size, new_size, unresolved;
|
unsigned int i, j, prev_size, new_size, unresolved;
|
||||||
uint32_t *prev_ids, *new_ids;
|
|
||||||
char buf[MAX_LINE_LENGTH];
|
char buf[MAX_LINE_LENGTH];
|
||||||
NSR_Status s;
|
NSR_Status s;
|
||||||
int d, pass;
|
int d, pass;
|
||||||
|
@ -1703,13 +1701,9 @@ reload_source_dirs(void)
|
||||||
if (!conf_ntp_sources_added)
|
if (!conf_ntp_sources_added)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
prev_size = ARR_GetSize(ntp_source_ids);
|
prev_size = ARR_GetSize(ntp_sources);
|
||||||
if (ARR_GetSize(ntp_sources) != prev_size)
|
|
||||||
assert(0);
|
|
||||||
|
|
||||||
/* Save the current sources and their configuration IDs */
|
/* Save the current sources */
|
||||||
prev_ids = MallocArray(uint32_t, prev_size);
|
|
||||||
memcpy(prev_ids, ARR_GetElements(ntp_source_ids), prev_size * sizeof (prev_ids[0]));
|
|
||||||
prev_sources = MallocArray(NTP_Source, prev_size);
|
prev_sources = MallocArray(NTP_Source, prev_size);
|
||||||
memcpy(prev_sources, ARR_GetElements(ntp_sources), prev_size * sizeof (prev_sources[0]));
|
memcpy(prev_sources, ARR_GetElements(ntp_sources), prev_size * sizeof (prev_sources[0]));
|
||||||
|
|
||||||
|
@ -1727,8 +1721,6 @@ reload_source_dirs(void)
|
||||||
|
|
||||||
new_size = ARR_GetSize(ntp_sources);
|
new_size = ARR_GetSize(ntp_sources);
|
||||||
new_sources = ARR_GetElements(ntp_sources);
|
new_sources = ARR_GetElements(ntp_sources);
|
||||||
ARR_SetSize(ntp_source_ids, new_size);
|
|
||||||
new_ids = ARR_GetElements(ntp_source_ids);
|
|
||||||
unresolved = 0;
|
unresolved = 0;
|
||||||
|
|
||||||
LOG_SetContext(LOGC_SourceFile);
|
LOG_SetContext(LOGC_SourceFile);
|
||||||
|
@ -1744,7 +1736,7 @@ reload_source_dirs(void)
|
||||||
|
|
||||||
/* Remove missing sources before adding others to avoid conflicts */
|
/* 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].params.name[0] != '\0') {
|
||||||
NSR_RemoveSourcesById(prev_ids[i]);
|
NSR_RemoveSourcesById(prev_sources[i].conf_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add new sources */
|
/* Add new sources */
|
||||||
|
@ -1752,7 +1744,7 @@ reload_source_dirs(void)
|
||||||
source = &new_sources[j];
|
source = &new_sources[j];
|
||||||
s = NSR_AddSourceByName(source->params.name, source->params.family, source->params.port,
|
s = NSR_AddSourceByName(source->params.name, source->params.family, source->params.port,
|
||||||
source->pool, source->type, &source->params.params,
|
source->pool, source->type, &source->params.params,
|
||||||
&new_ids[j]);
|
&source->conf_id);
|
||||||
|
|
||||||
if (s == NSR_UnresolvedName) {
|
if (s == NSR_UnresolvedName) {
|
||||||
unresolved++;
|
unresolved++;
|
||||||
|
@ -1767,7 +1759,7 @@ reload_source_dirs(void)
|
||||||
|
|
||||||
/* Keep unchanged sources */
|
/* Keep unchanged sources */
|
||||||
if (pass == 1 && d == 0)
|
if (pass == 1 && d == 0)
|
||||||
new_ids[j] = prev_ids[i];
|
new_sources[j].conf_id = prev_sources[i].conf_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1776,7 +1768,6 @@ reload_source_dirs(void)
|
||||||
for (i = 0; i < prev_size; i++)
|
for (i = 0; i < prev_size; i++)
|
||||||
Free(prev_sources[i].params.name);
|
Free(prev_sources[i].params.name);
|
||||||
Free(prev_sources);
|
Free(prev_sources);
|
||||||
Free(prev_ids);
|
|
||||||
|
|
||||||
if (unresolved > 0)
|
if (unresolved > 0)
|
||||||
NSR_ResolveSources();
|
NSR_ResolveSources();
|
||||||
|
@ -1875,7 +1866,6 @@ CNF_AddSources(void)
|
||||||
|
|
||||||
/* The arrays will be used for sourcedir (re)loading */
|
/* The arrays will be used for sourcedir (re)loading */
|
||||||
ARR_SetSize(ntp_sources, 0);
|
ARR_SetSize(ntp_sources, 0);
|
||||||
ARR_SetSize(ntp_source_ids, 0);
|
|
||||||
conf_ntp_sources_added = 1;
|
conf_ntp_sources_added = 1;
|
||||||
|
|
||||||
reload_source_dirs();
|
reload_source_dirs();
|
||||||
|
|
Loading…
Reference in a new issue