cgconfigparser can now parse multiple config files, including
(alphabetitcally sorted) files from a directory.

Signed-off-by: Jan Safranek <jsafr...@redhat.com>
---

 src/tools/Makefile.am |    2 +-
 src/tools/cgconfig.c  |   53 +++++++++++++++++++++++++++++++++++--------------
 2 files changed, 39 insertions(+), 16 deletions(-)

diff --git a/src/tools/Makefile.am b/src/tools/Makefile.am
index b825dff..4cb02ff 100644
--- a/src/tools/Makefile.am
+++ b/src/tools/Makefile.am
@@ -18,7 +18,7 @@ cgset_SOURCES = cgset.c tools-common.c tools-common.h
 
 cgget_SOURCES = cgget.c tools-common.c tools-common.h
 
-cgconfigparser_SOURCES = cgconfig.c
+cgconfigparser_SOURCES = cgconfig.c tools-common.c tools-common.h
 
 cgclear_SOURCES = cgclear.c tools-common.c tools-common.h
 
diff --git a/src/tools/cgconfig.c b/src/tools/cgconfig.c
index e426b76..cc2a633 100644
--- a/src/tools/cgconfig.c
+++ b/src/tools/cgconfig.c
@@ -31,51 +31,74 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <getopt.h>
+#include "tools-common.h"
+
+static struct cgroup_string_list cfg_files;
 
 
 static void usage(char *progname)
 {
-       printf("Usage: %s [OPTION] [FILE]\n", basename(progname));
+       printf("Usage: %s [-l FILE] ...\n", basename(progname));
        printf("Parse and load the specified cgroups configuration file\n");
        printf("\n");
-       printf("  -h, --help            Display this help\n");
-       printf("  -l, --load=FILE       Parse and load the cgroups 
configuration file\n");
+       printf("  -h, --help                    Display this help\n");
+       printf("  -l, --load=FILE               Parse and load the cgroups"\
+                       " configuration file\n");
+       printf("  -L, --load-directory=DIR      Parse and load the cgroups"\
+                       " configuration files from a directory\n");
        exit(2);
 }
 
 int main(int argc, char *argv[])
 {
-       int c;
-       char filename[PATH_MAX];
-       int ret;
+       int c, i;
+       int ret, error = 0;
        static struct option options[] = {
                {"help", 0, 0, 'h'},
                {"load", 1, 0, 'l'},
+               {"load-directory", 1, 0, 'L'},
                {0, 0, 0, 0}
        };
 
        if (argc < 2)
                usage(argv[0]); /* usage() exits */
 
-       while ((c = getopt_long(argc, argv, "hl:", options, NULL)) > 0) {
+       ret = cgroup_string_list_init(&cfg_files, argc/2);
+
+       while ((c = getopt_long(argc, argv, "hl:L:", options, NULL)) > 0) {
                switch (c) {
                case 'h':
                        usage(argv[0]);
                        break;
                case 'l':
-                       strncpy(filename, optarg, PATH_MAX);
-                       ret = cgroup_config_load_config(filename);
+                       ret = cgroup_string_list_add_item(&cfg_files, optarg);
                        if (ret) {
-                               printf("Loading configuration file %s "
-                                       "failed\n%s\n", filename,
-                                       cgroup_strerror(ret));
-                               exit(3);
+                               fprintf(stderr, "%s: cannot add file to list,"\
+                                               " out of memory?\n", argv[0]);
+                               exit(1);
                        }
-                       return 0;
+                       break;
+               case 'L':
+                       cgroup_string_list_add_directory(&cfg_files, optarg,
+                                       argv[0]);
+                       break;
                default:
                        usage(argv[0]);
                        break;
                }
        }
-       return 0;
+
+       for (i = 0; i < cfg_files.count; i++) {
+               ret = cgroup_config_load_config(cfg_files.items[i]);
+               if (ret) {
+                       fprintf(stderr, "%s; error loading %s: %s\n", argv[0],
+                                       cfg_files.items[i],
+                                       cgroup_strerror(ret));
+                       if (!error)
+                               error = ret;
+               }
+       }
+
+       cgroup_string_list_free(&cfg_files);
+       return error;
 }


------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to