]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
cgrulesengd: cache templates
authorIvana Hutarova Varekova <varekova@redhat.com>
Mon, 28 Jan 2013 13:44:24 +0000 (14:44 +0100)
committerIvana Hutarova Varekova <varekova@redhat.com>
Mon, 28 Jan 2013 13:44:24 +0000 (14:44 +0100)
    This patch adds templates caching to cgrulesengd
     * they are initialized
     * reloaded in case of signal SIGUSR1

Signed-off-by: Ivana Hutarova Varekova <varekova@redhat.com>
Acked-by: Jan Safranek<jsafrane@redhat.com>
src/daemon/cgrulesengd.c
src/daemon/cgrulesengd.h

index ff729651a922bfa1003ac83b400d9a3cbb1bdadc..f12db4546264fdc70af247f89dd1d9e82f968cdd 100644 (file)
@@ -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.
index 97c62f1148fff4e8458d40aad57c5e894345ebb3..e273b4bcefe49e7d40621485fcaa0e40e50eb442 100644 (file)
@@ -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().