From: Alan T. DeKok Date: Fri, 5 Jun 2015 18:26:03 +0000 (-0400) Subject: Ignore HUP if no config files have changed X-Git-Tag: release_3_0_9~245 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=610c422825d2a72ec76bba50e1208f153e43931d;p=thirdparty%2Ffreeradius-server.git Ignore HUP if no config files have changed --- diff --git a/src/include/conffile.h b/src/include/conffile.h index 00c7ac1b294..2a3a45dc83c 100644 --- a/src/include/conffile.h +++ b/src/include/conffile.h @@ -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; diff --git a/src/main/conffile.c b/src/main/conffile.c index 909ee00a478..08e69554a3f 100644 --- a/src/main/conffile.c +++ b/src/main/conffile.c @@ -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) { /* diff --git a/src/main/mainconfig.c b/src/main/mainconfig.c index 9888eb8efec..38a58ae82a9 100644 --- a/src/main/mainconfig.c +++ b/src/main/mainconfig.c @@ -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);