mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 22:55:07 -05:00
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:
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
|
||||
SRC_IsSyncPeer(SRC_Instance inst)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user