sources: remove dump files on start
When chronyd is starting, after the point where dump files are loaded, remove all files in the dump directory that match the naming scheme used for dump files. This prevents loading stale dump files that were not saved in the latest run of chronyd.
This commit is contained in:
parent
fb5d4f1da4
commit
a06a5f1baa
3 changed files with 41 additions and 1 deletions
1
main.c
1
main.c
|
@ -158,6 +158,7 @@ ntp_source_resolving_end(void)
|
||||||
SRC_ReloadSources();
|
SRC_ReloadSources();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SRC_RemoveDumpFiles();
|
||||||
RTC_StartMeasurements();
|
RTC_StartMeasurements();
|
||||||
RCL_StartRefclocks();
|
RCL_StartRefclocks();
|
||||||
NSR_StartSources();
|
NSR_StartSources();
|
||||||
|
|
39
sources.c
39
sources.c
|
@ -1238,6 +1238,45 @@ SRC_ReloadSources(void)
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
SRC_RemoveDumpFiles(void)
|
||||||
|
{
|
||||||
|
char pattern[1024], name[64], *dumpdir, *s;
|
||||||
|
IPAddr ip_addr;
|
||||||
|
glob_t gl;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
dumpdir = CNF_GetDumpDir();
|
||||||
|
if (dumpdir[0] == '\0' ||
|
||||||
|
snprintf(pattern, sizeof (pattern), "%s/*.dat", dumpdir) >= sizeof (pattern))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (glob(pattern, 0, NULL, &gl))
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (i = 0; i < gl.gl_pathc; i++) {
|
||||||
|
s = strrchr(gl.gl_pathv[i], '/');
|
||||||
|
if (!s || snprintf(name, sizeof (name), "%s", s + 1) >= sizeof (name))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* Remove .dat extension */
|
||||||
|
if (strlen(name) < 4)
|
||||||
|
continue;
|
||||||
|
name[strlen(name) - 4] = '\0';
|
||||||
|
|
||||||
|
/* Check if it looks like name of an actual dump file */
|
||||||
|
if (strncmp(name, "refid:", 6) && !UTI_StringToIP(name, &ip_addr))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
DEBUG_LOG(LOGF_Sources, "Removing %s", gl.gl_pathv[i]);
|
||||||
|
unlink(gl.gl_pathv[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
globfree(&gl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
int
|
int
|
||||||
SRC_IsSyncPeer(SRC_Instance inst)
|
SRC_IsSyncPeer(SRC_Instance inst)
|
||||||
{
|
{
|
||||||
|
|
|
@ -157,8 +157,8 @@ extern double SRC_MinRoundTripDelay(SRC_Instance inst);
|
||||||
extern int SRC_IsGoodSample(SRC_Instance inst, double offset, double delay, double max_delay_dev_ratio, double clock_error, struct timespec *when);
|
extern int SRC_IsGoodSample(SRC_Instance inst, double offset, double delay, double max_delay_dev_ratio, double clock_error, struct timespec *when);
|
||||||
|
|
||||||
extern void SRC_DumpSources(void);
|
extern void SRC_DumpSources(void);
|
||||||
|
|
||||||
extern void SRC_ReloadSources(void);
|
extern void SRC_ReloadSources(void);
|
||||||
|
extern void SRC_RemoveDumpFiles(void);
|
||||||
|
|
||||||
extern int SRC_IsSyncPeer(SRC_Instance inst);
|
extern int SRC_IsSyncPeer(SRC_Instance inst);
|
||||||
extern int SRC_IsReachable(SRC_Instance inst);
|
extern int SRC_IsReachable(SRC_Instance inst);
|
||||||
|
|
Loading…
Reference in a new issue