On 11/21/2012 01:11 PM, Ivana Hutarova Varekova wrote:
> This patch adds templates caching to cgrulesengd
>  * they are initialized
>  * reloaded in case of signal SIGUSR1
> 
> Signed-off-by: Ivana Hutarova Varekova <varek...@redhat.com>

IMHO reload-all on SIGUSR2 would be enough, but why not...
Acked-By: Jan Safranek <jsafr...@redhat.com>

> ---
> 
>  src/daemon/cgrulesengd.c |   41 +++++++++++++++++++++++++++++++++++++++++
>  src/daemon/cgrulesengd.h |    7 +++++++
>  2 files changed, 48 insertions(+), 0 deletions(-)
> 
> diff --git a/src/daemon/cgrulesengd.c b/src/daemon/cgrulesengd.c
> index ff72965..f12db45 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) {
> @@ -1114,6 +1143,18 @@ int main(int argc, char *argv[])
>       }
>  
>       /*
> +      * 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 97c62f1..e273b4b 100644
> --- a/src/daemon/cgrulesengd.h
> +++ b/src/daemon/cgrulesengd.h
> @@ -106,6 +106,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().
>   *   @param signum The signal that we caught (SIGTERM, SIGINT)
> 
> 
> ------------------------------------------------------------------------------
> Monitor your physical, virtual and cloud infrastructure from a single
> web console. Get in-depth insight into apps, servers, databases, vmware,
> SAP, cloud infrastructure, etc. Download 30-day Free Trial.
> Pricing starts from $795 for 25 servers or applications!
> http://p.sf.net/sfu/zoho_dev2dev_nov
> _______________________________________________
> Libcg-devel mailing list
> Libcg-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/libcg-devel
> 


------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to