From: Ivana Hutarova Varekova Date: Mon, 28 Jan 2013 13:44:24 +0000 (+0100) Subject: cgrulesengd: cache templates X-Git-Tag: v0.41~87 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6bc26fe74a1159baef12c2d6043fa5c1726a5193;p=thirdparty%2Flibcgroup.git cgrulesengd: cache templates This patch adds templates caching to cgrulesengd * they are initialized * reloaded in case of signal SIGUSR1 Signed-off-by: Ivana Hutarova Varekova Acked-by: Jan Safranek --- diff --git a/src/daemon/cgrulesengd.c b/src/daemon/cgrulesengd.c index ff729651..f12db454 100644 --- a/src/daemon/cgrulesengd.c +++ b/src/daemon/cgrulesengd.c @@ -884,6 +884,26 @@ void cgre_flash_rules(int signum) cgroup_print_rules_config(logfile); fprintf(logfile, "\n"); } + + /* Ask libcgroup to reload the template rules table. */ + cgroup_reload_cached_templates(CGCONFIG_CONF_FILE); +} + +/** + * Catch the SIGUSR1 signal and reload the rules configuration. This function + * makes use of the logfile and flog() to print the new rules. + * @param signum The signal that we caught (always SIGUSR1) + */ +void cgre_flash_templates(int signum) +{ + /* Current time */ + time_t tm = time(0); + + flog(LOG_NOTICE, "Reloading templates configuration."); + flog(LOG_DEBUG, "Current time: %s", ctime(&tm)); + + /* Ask libcgroup to reload the templates table. */ + cgroup_reload_cached_templates(CGCONFIG_CONF_FILE); } /** @@ -1092,6 +1112,15 @@ int main(int argc, char *argv[]) goto finished; } + /* ask libcgroup to load template rules as well */ + ret = cgroup_init_templates_cache(CGCONFIG_CONF_FILE); + if (ret != 0) { + fprintf(stderr, "Error: libcgroup failed to initialize teplate"\ + "rules from %s. %s\n", CGCONFIG_CONF_FILE, + cgroup_strerror(ret)); + goto finished; + } + /* Now, start the daemon. */ ret = cgre_start_daemon(logp, facility, daemon, verbosity); if (ret < 0) { @@ -1113,6 +1142,18 @@ int main(int argc, char *argv[]) goto finished; } + /* + * Set up the signal handler to reload templates cache upon + * reception of a SIGUSR1 signal. + */ + sa.sa_handler = &cgre_flash_templates; + ret = sigaction(SIGUSR1, &sa, NULL); + if (ret) { + flog(LOG_ERR, "Failed to set up signal handler for SIGUSR1."\ + " Error: %s", strerror(errno)); + goto finished; + } + /* * Set up the signal handler to catch SIGINT and SIGTERM so that we * can exit gracefully. diff --git a/src/daemon/cgrulesengd.h b/src/daemon/cgrulesengd.h index 97c62f11..e273b4bc 100644 --- a/src/daemon/cgrulesengd.h +++ b/src/daemon/cgrulesengd.h @@ -105,6 +105,13 @@ int cgre_start_daemon(const char *logp, const int logf, */ void cgre_flash_rules(int signum); +/** + * Catch the SIGUSR1 signal and reload the rules configuration. This function + * makes use of the logfile and flog() to print the new rules. + * @param signum The signal that we caught (always SIGUSR1) + */ +void cgre_flash_templates(int signum); + /** * Catch the SIGTERM and SIGINT signal so that we can exit gracefully. Before * exiting, this function makes use of the logfile and flog().