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.
This patch depends on [PATCH 1/4] Signed-off-by: Jan Chaloupka<jchal...@redhat.com> --- src/daemon/cgrulesengd.c | 36 +++++++++++++++++++++++++++++++++++- src/libcgroup-internal.h | 3 +++ src/tools/tools-common.h | 2 +- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/daemon/cgrulesengd.c b/src/daemon/cgrulesengd.c index 170837a..d82cbdf 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/ */ +static struct cgroup_string_list template_files; + /* Log file, NULL if logging to file is disabled */ FILE* logfile; @@ -1179,7 +1183,21 @@ int main(int argc, char *argv[]) goto finished; } - /* Ask libcgroup to load the configuration rules. */ + /* Ask libcgroup to load the configuration rules. */ + ret = cgroup_string_list_init(&template_files, CGCONFIG_CONF_FILES_LIST_MINIMUM_SIZE); + if (ret) + 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,6 +1206,20 @@ int main(int argc, char *argv[]) } /* ask libcgroup to load template rules as well */ + cgroup_templates_cache_set_source_files(&template_files); + int fileindex; + ret = cgroup_init_templates_cache_from_files(&fileindex); + if (ret != 0) { + if (fileindex < 0) { + fprintf(stderr, "Error: Template source files have not been set\n"); + } else { + fprintf(stderr, "Error: libcgroup failed to initialize template "\ + "rules from %s. %s\n", template_files.items[fileindex], + cgroup_strerror(ret)); + } + goto finished; + } + ret = cgroup_init_templates_cache(CGCONFIG_CONF_FILE); if (ret != 0) { fprintf(stderr, "Error: libcgroup failed to initialize teplate"\ @@ -1262,5 +1294,7 @@ finished: if (logfile && logfile != stdout) fclose(logfile); + cgroup_string_list_free(&template_files); + 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) -- 1.9.0 ------------------------------------------------------------------------------ Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. Written by three acclaimed leaders in the field, this first edition is now available. Download your free book today! http://p.sf.net/sfu/NeoTech _______________________________________________ Libcg-devel mailing list Libcg-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libcg-devel