If for whatever reason cfservd.conf has a timestamp from the
future, cfservd will keep rereading it over and over again because it
stat()s the file and considers it changed if the mtime is later than
the daemon start time.
With this patch we look at the mtime, inode number and filesize and
iff one or more of them change we checksum the file and see if it is
actually different before rereading.
--- cfengine-2.2.10/src/cfservd.c
+++ cfengine-2.2.10/src/cfservd.c
@@ -68,6 +68,9 @@ struct option CFDOPTIONS[] =
struct Item *CONNECTIONLIST = NULL;
+struct stat confstat;
+unsigned char confdigest[EVP_MAX_MD_SIZE+1];
+
/*******************************************************************/
/* Functions internal to cfservd.c */
@@ -985,6 +988,7 @@ void CheckFileChanges(int argc,char **argv,int sd)
{ struct stat newstat;
char filename[CF_BUFSIZE],*sp;
+ unsigned char newdigest[EVP_MAX_MD_SIZE+1];
memset(&newstat,0,sizeof(struct stat));
memset(filename,0,CF_BUFSIZE);
@@ -1017,9 +1021,22 @@ if (stat(filename,&newstat) == -1)
return;
}
-Debug("Checking file updates on %s (%x/%x)\n",filename, newstat.st_mtime, CFDSTARTTIME);
+if (!confstat.st_mtime) /* First run */
+ {
+ memmove(&confstat,&newstat,sizeof(struct stat));
+ ChecksumFile(filename,confdigest,'m');
+ }
+
+Debug("Checking file updates on %s ({%x/%x)\n",filename, newstat.st_mtime, confstat.st_mtime);
+
+if (newstat.st_mtime == confstat.st_mtime && newstat.st_ino == confstat.st_ino && newstat.st_size == confstat.st_size)
+ {
+ return;
+ }
+
+ChecksumFile(filename,newdigest,'m');
-if (CFDSTARTTIME < newstat.st_mtime)
+if (memcmp(newdigest,confdigest,EVP_MAX_MD_SIZE))
{
snprintf(OUTPUT,CF_BUFSIZE*2,"Rereading config files %s..\n",filename);
CfLog(cfinform,OUTPUT,"");
@@ -1061,6 +1078,9 @@ if (CFDSTARTTIME < newstat.st_mtime)
CheckVariables();
SummarizeParsing();
}
+
+memmove(&confstat,&newstat,sizeof(struct stat));
+memmove(&confdigest,&newdigest,EVP_MAX_MD_SIZE+1);
}
/*********************************************************************/
_______________________________________________
Bug-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/bug-cfengine