From: Alan T. DeKok Date: Sat, 6 Jun 2015 14:34:13 +0000 (-0400) Subject: Start of "hup module" code. X-Git-Tag: release_3_0_9~236 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f08fd1a285d364850d731553bf8e830084262dd;p=thirdparty%2Ffreeradius-server.git Start of "hup module" code. 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 --- diff --git a/src/include/conffile.h b/src/include/conffile.h index 2a3a45dc83c..973c1fc6cb4 100644 --- a/src/include/conffile.h +++ b/src/include/conffile.h @@ -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; diff --git a/src/main/conffile.c b/src/main/conffile.c index 697812a386f..18e8ca10477 100644 --- a/src/main/conffile.c +++ b/src/main/conffile.c @@ -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) diff --git a/src/main/mainconfig.c b/src/main/mainconfig.c index 73087ac8034..b9eda025092 100644 --- a/src/main/mainconfig.c +++ b/src/main/mainconfig.c @@ -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;