]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Ignore HUP if no config files have changed
authorAlan T. DeKok <aland@freeradius.org>
Fri, 5 Jun 2015 18:26:03 +0000 (14:26 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 5 Jun 2015 18:41:20 +0000 (14:41 -0400)
src/include/conffile.h
src/main/conffile.c
src/main/mainconfig.c

index 00c7ac1b294ab2af30a9b40304a210d973e5ef2b..2a3a45dc83c391b0fc8b0a21fb889f11a1d81f79 100644 (file)
@@ -280,6 +280,7 @@ void cf_item_add(CONF_SECTION *cs, CONF_ITEM *ci);
 CONF_ITEM *cf_reference_item(CONF_SECTION const *parentcs,
                             CONF_SECTION *outercs,
                             char const *ptr);
+bool cf_file_changed(CONF_SECTION *cs);
 
 extern CONF_SECTION *root_config;
 extern bool cf_new_escape;
index 909ee00a478acab1d526f1b1e5158f7275881727..08e69554a3fab2c9f53710e06baa6f7d92a6e671 100644 (file)
@@ -349,6 +349,49 @@ static FILE *cf_file_open(CONF_SECTION *cs, char const *filename)
        return fp;
 }
 
+/*
+ *     Return 0 for keep going, 1 for stop.
+ */
+static int file_callback(UNUSED void *ctx, void *data)
+{
+       struct stat buf;
+       cf_file_t *file = data;
+
+       if (stat(file->filename, &buf) < 0) return 1;
+
+       /*
+        *      The file changed, we'll need to re-read it.
+        */
+       if (buf.st_mtime != file->buf.st_mtime) return 1;
+
+       return 0;
+}
+
+
+/*
+ *     See if any of the files have changed.
+ */
+bool cf_file_changed(CONF_SECTION *cs)
+{
+       int rcode;
+       CONF_DATA *cd;
+       CONF_SECTION *top;
+       rbtree_t *tree;
+
+       top = cf_top_section(cs);
+       cd = cf_data_find_internal(top, "filename", 0);
+       if (!cd) return true;
+
+       tree = cd->data;
+
+       rcode = rbtree_walk(tree, RBTREE_IN_ORDER, file_callback, cs);
+       if (rcode == 0) {
+               return false;
+       }
+
+       return true;
+}
+
 static int _cf_section_free(CONF_SECTION *cs)
 {
        /*
index 9888eb8efecfbfdc5490b77e8c0e111b38c5d9b0..38a58ae82a99c1e49b408b2a729029b7261fffe8 100644 (file)
@@ -1056,13 +1056,18 @@ void main_config_hup(void)
        CONF_SECTION *cs;
        char buffer[1024];
 
-       INFO("HUP - Re-reading configuration files");
+       if (!cf_file_changed(cs_cache->cs)) {
+               INFO("HUP - No files changed.  Ignoring");
+               return;
+       }
 
        cs = cf_section_alloc(NULL, "main", NULL);
        if (!cs) return;
 
        /* Read the configuration file */
        snprintf(buffer, sizeof(buffer), "%.200s/%.50s.conf", radius_dir, main_config.name);
+
+       INFO("HUP - Re-reading configuration files");
        if (cf_file_read(cs, buffer) < 0) {
                ERROR("Failed to re-read or parse %s", buffer);
                talloc_free(cs);