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: Jan Chaloupka <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 170837a..83da66f 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;

@@ -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;
+    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"
+            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);
+
      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


------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to