CONF_ITEM *cf_reference_item(CONF_SECTION const *parentcs,
CONF_SECTION *outercs,
char const *ptr);
-bool cf_file_changed(CONF_SECTION *cs);
+
+#define CF_FILE_NONE (0)
+#define CF_FILE_ERROR (1)
+#define CF_FILE_CONFIG (2)
+#define CF_FILE_MODULE (3)
+int cf_file_changed(CONF_SECTION *cs);
extern CONF_SECTION *root_config;
extern bool cf_new_escape;
typedef struct cf_file_t {
char const *filename;
+ CONF_SECTION *cs;
+ bool input;
struct stat buf;
} cf_file_t;
fclose(fp);
return NULL;
}
+
file->filename = filename;
+ file->cs = cs;
+ file->input = true;
if (fstat(fd, &file->buf) == 0) {
#ifdef S_IWOTH
if (!file) return false;
file->filename = filename;
+ file->cs = cs;
+ file->input = true;
if (stat(filename, &file->buf) < 0) {
ERROR("Unable to open file \"%s\": %s",
/*
* Return 0 for keep going, 1 for stop.
*/
-static int file_callback(UNUSED void *ctx, void *data)
+static int file_callback(void *ctx, void *data)
{
+ int *rcode = ctx;
struct stat buf;
cf_file_t *file = data;
- if (stat(file->filename, &buf) < 0) return 1;
+ /*
+ * The file doesn't exist or we can no longer read it.
+ */
+ if (stat(file->filename, &buf) < 0) {
+ *rcode = CF_FILE_ERROR;
+ return 1;
+ }
/*
* The file changed, we'll need to re-read it.
*/
- if (buf.st_mtime != file->buf.st_mtime) return 1;
+ if (buf.st_mtime != file->buf.st_mtime) {
+ /*
+ * Set none -> whatever
+ */
+ if (*rcode == CF_FILE_NONE) {
+ if (!file->input) {
+ *rcode = CF_FILE_CONFIG;
+ return 1;
+ }
+
+ *rcode = CF_FILE_MODULE;
+ return 0;
+
+ }
+
+ /*
+ * A module WAS changed, but now we discover that
+ * a main config file has changed. We might as
+ * well re-load everything.
+ */
+ if ((*rcode == CF_FILE_MODULE) && !file->input) {
+ *rcode = CF_FILE_CONFIG;
+ return 1;
+ }
+ }
return 0;
}
/*
* See if any of the files have changed.
*/
-bool cf_file_changed(CONF_SECTION *cs)
+int cf_file_changed(CONF_SECTION *cs)
{
int rcode;
CONF_DATA *cd;
tree = cd->data;
- rcode = rbtree_walk(tree, RBTREE_IN_ORDER, file_callback, cs);
- if (rcode == 0) {
- return false;
- }
+ rcode = CF_FILE_NONE;
+ (void) rbtree_walk(tree, RBTREE_IN_ORDER, file_callback, &rcode);
- return true;
+ return rcode;
}
static int _cf_section_free(CONF_SECTION *cs)
void main_config_hup(void)
{
+ int rcode;
cached_config_t *cc;
CONF_SECTION *cs;
char buffer[1024];
*/
hup_logfile();
- if (!cf_file_changed(cs_cache->cs)) {
+ rcode = cf_file_changed(cs_cache->cs);
+ if (rcode == CF_FILE_NONE) {
INFO("HUP - No files changed. Ignoring");
return;
}
+ if (rcode == CF_FILE_ERROR) {
+ INFO("HUP - Cannot read configuration files. Ignoring");
+ return;
+ }
+
+ if (rcode == CF_FILE_MODULE) {
+ INFO("HUP - Files loaded by a module have changed.");
+ return;
+ }
+
cs = cf_section_alloc(NULL, "main", NULL);
if (!cs) return;