]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Start of "hup module" code.
authorAlan T. DeKok <aland@freeradius.org>
Sat, 6 Jun 2015 14:34:13 +0000 (10:34 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sat, 6 Jun 2015 14:34:13 +0000 (10:34 -0400)
Handle module config files, too.  e.g. "users" file.

It's not clear how to best handle that.  A module has to be told
to re-load the files it loads... but with no changes to the
module config section.  It's probably best to add a "hup" method
to the modules

src/include/conffile.h
src/main/conffile.c
src/main/mainconfig.c

index 2a3a45dc83c391b0fc8b0a21fb889f11a1d81f79..973c1fc6cb4c9157f01417153c678c2933134c37 100644 (file)
@@ -280,7 +280,12 @@ 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);
+
+#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;
index 697812a386f0681b615caefcd377cf4416b7bbbd..18e8ca104775c21b34dd82d9fa7e9e08a50d52a4 100644 (file)
@@ -119,6 +119,8 @@ struct conf_part {
 
 typedef struct cf_file_t {
        char const      *filename;
+       CONF_SECTION    *cs;
+       bool            input;
        struct stat     buf;
 } cf_file_t;
 
@@ -326,7 +328,10 @@ static FILE *cf_file_open(CONF_SECTION *cs, char const *filename)
                fclose(fp);
                return NULL;
        }
+
        file->filename = filename;
+       file->cs = cs;
+       file->input = true;
 
        if (fstat(fd, &file->buf) == 0) {
 #ifdef S_IWOTH
@@ -373,6 +378,8 @@ static bool cf_file_input(CONF_SECTION *cs, char const *filename)
        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",
@@ -404,17 +411,48 @@ static bool cf_file_input(CONF_SECTION *cs, char const *filename)
 /*
  *     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;
 }
@@ -423,7 +461,7 @@ static int file_callback(UNUSED void *ctx, void *data)
 /*
  *     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;
@@ -436,12 +474,10 @@ bool cf_file_changed(CONF_SECTION *cs)
 
        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)
index 73087ac8034968789cf7d0fc331ac81e41469c54..b9eda025092b83ffeb4bb2ad195e41367183d786 100644 (file)
@@ -1052,6 +1052,7 @@ void hup_logfile(void)
 
 void main_config_hup(void)
 {
+       int rcode;
        cached_config_t *cc;
        CONF_SECTION *cs;
        char buffer[1024];
@@ -1065,11 +1066,22 @@ void main_config_hup(void)
         */
        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;