#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;
}