----- Original Message -----
> From: "jchaloup" <jchal...@redhat.com>
> To: libcg-devel@lists.sourceforge.net
> Cc: varek...@redhat.com
> Sent: Tuesday, May 20, 2014 10:11:25 AM
> Subject: [PATCH 2/4] cgrulesengd.c: loading of multiples files during 
> init/reload from daemon
> 
> This patch use new implementation. In cgrulesengd.c, static variable
> template_files is used to save all config files, i.e. /etc/cgconfig.conf and
> /etc/cgconfig.d/*. This list of files is then passed to
> cgroup_templates_cache_set_source_files, which saves files to template_files
> in config.c module. This list is accessed through invocation of
> cgroup_init_templates_cache_from_files and
> cgroup_reload_templates_cache_from_files, which can access variables only
> from config.c, thus presenting cgroup_templates_cache_set_source_files
> function. At the end, this list is set free.
> 
> Signed-off-by: jchaloup <jchal...@redhat.com>
> ---
>  src/daemon/cgrulesengd.c |   40 ++++++++++++++++++++++++++++++++++++----
>  src/libcgroup-internal.h |    3 +++
>  src/tools/tools-common.h |    2 +-
>  3 files changed, 40 insertions(+), 5 deletions(-)
> 
> diff --git a/src/daemon/cgrulesengd.c b/src/daemon/cgrulesengd.c
> index 367b898..5b6d513 100644
> --- a/src/daemon/cgrulesengd.c
> +++ b/src/daemon/cgrulesengd.c
> @@ -34,6 +34,7 @@
>  #include "libcgroup.h"
>  #include "cgrulesengd.h"
>  #include "../libcgroup-internal.h"
> +#include "../tools/tools-common.h"
>  
>  #include <errno.h>
>  #include <stdarg.h>
> @@ -59,6 +60,9 @@
>  
>  #define NUM_PER_REALLOCATIOM (100)
>  
> +/* list of config files from /etc/cgconfig.conf and /etc/cgconfig.d/ */

use  z CGCONFIG_CONF_FILE a ..DIR here

> +static struct cgroup_string_list template_files;
> +
>  /* Log file, NULL if logging to file is disabled */
>  FILE* logfile;
>  
> @@ -1180,6 +1184,25 @@ int main(int argc, char *argv[])
>       }
>  
>       /* Ask libcgroup to load the configuration rules. */
> +     ret = cgroup_string_list_init(&template_files,
> +             CGCONFIG_CONF_FILES_LIST_MINIMUM_SIZE);
> +     if (ret) {
> +             fprintf(stderr, "%s: cannot init file list, out of memory?\n",
> +                     argv[0]);
> +             goto finished;
> +     }
> +     /* first add CGCONFIG_CONF_FILE into file list */
> +     ret = cgroup_string_list_add_item(&template_files, CGCONFIG_CONF_FILE);
> +     if (ret) {
> +             fprintf(stderr, "%s: cannot add file to list, out of memory?\n"
> +                     , argv[0]);
> +             goto finished;
> +     }
> +
> +     /* then read CGCONFIG_CONF_DIR directory for additional config files */
> +     cgroup_string_list_add_directory(&template_files, CGCONFIG_CONF_DIR,
> +             argv[0]);
> +
>       if ((ret = cgroup_init_rules_cache()) != 0) {
>               fprintf(stderr, "Error: libcgroup failed to initialize rules"
>                               "cache from %s. %s\n", CGRULES_CONF_FILE,
> @@ -1188,11 +1211,18 @@ int main(int argc, char *argv[])
>       }
>  
>       /* ask libcgroup to load template rules as well */
> -     ret = cgroup_init_templates_cache(CGCONFIG_CONF_FILE);
> +     cgroup_templates_cache_set_source_files(&template_files);
> +     int fileindex;

please allocate variables at the beginning of function

> +     ret = cgroup_init_templates_cache_from_files(&fileindex);
>       if (ret != 0) {
> -             fprintf(stderr, "Error: libcgroup failed to initialize teplate"\
> -                             "rules from %s. %s\n", CGCONFIG_CONF_FILE,
> -                             cgroup_strerror(ret));
> +             if (fileindex < 0) {
> +#define DE1 "Error: Template source files have not been set\n"
don't use define here
> +                     fprintf(stderr, DE1);
> +             } else {
> +#define DE2 "Error: Failed to initialize template rules from %s. %s\n"
> +                     fprintf(stderr, DE2, template_files.items[fileindex],
> +                             cgroup_strerror(-ret));
> +             }
>               goto finished;
>       }
>  
> @@ -1262,5 +1292,7 @@ finished:
>       if (logfile && logfile != stdout)
>               fclose(logfile);
>  
> +     cgroup_string_list_free(&template_files);

this function should not be called if template files variable is not set e.g. 
in case when cgroup_string_list_init is not true.
so reorder finished: part and create new goto label


> +
>       return ret;
>  }
> diff --git a/src/libcgroup-internal.h b/src/libcgroup-internal.h
> index 4c0f46c..c128788 100644
> --- a/src/libcgroup-internal.h
> +++ b/src/libcgroup-internal.h
> @@ -48,6 +48,9 @@ __BEGIN_DECLS
>  
>  
>  #define CGCONFIG_CONF_FILE           "/etc/cgconfig.conf"
> +/* Minimum number of file in template file list for cgrulesengd */
> +#define CGCONFIG_CONF_FILES_LIST_MINIMUM_SIZE   4
> +#define CGCONFIG_CONF_DIR               "/etc/cgconfig.d"
>  
>  #define CGRULES_CONF_FILE       "/etc/cgrules.conf"
>  #define CGRULES_MAX_FIELDS_PER_LINE          3
> diff --git a/src/tools/tools-common.h b/src/tools/tools-common.h
> index e05465f..c723eb4 100644
> --- a/src/tools/tools-common.h
> +++ b/src/tools/tools-common.h
> @@ -20,7 +20,7 @@
>  
>  #include "config.h"
>  #include <libcgroup.h>
> -#include <libcgroup-internal.h>
> +#include "../libcgroup-internal.h"
>  
>  #define cgroup_err(x...) cgroup_log(CGROUP_LOG_ERROR, x)
>  #define cgroup_warn(x...) cgroup_log(CGROUP_LOG_WARNING, x)
> 
> 

------------------------------------------------------------------------------
The best possible search technologies are now affordable for all companies.
Download your FREE open source Enterprise Search Engine today!
Our experts will assist you in its installation for $59/mo, no commitment.
Test it for FREE on our Cloud platform anytime!
http://pubads.g.doubleclick.net/gampad/clk?id=145328191&iu=/4140/ostg.clktrk
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to