{
{"recursive", no_argument, NULL, 'r'},
{"help", no_argument, NULL, 'h'},
+ {"group", required_argument, NULL, 'g'},
{NULL, 0, NULL, 0}
};
" try %s --help' for more information.\n",
program_name);
else {
- printf("Usage: %s [-h ] [-r ] [<controllers>:<path>] ...\n",
+ printf("Usage: %s [-h ] [-r ] "
+ "\[[-g] <controllers>:<path>] ...\n",
program_name);
}
}
int c;
int flags = 0;
int final_ret = 0;
- int capacity = 0;
struct cgroup_group_spec **cgroup_list = NULL;
struct cgroup *cgroup;
struct cgroup_controller *cgc;
- if (argc < 2) {
- usage(1, argv[0]);
- return -1;
+ /* initialize libcg */
+ ret = cgroup_init();
+ if (ret) {
+ fprintf(stderr, "%s: "
+ "libcgroup initialization failed: %s\n",
+ argv[0], cgroup_strerror(ret));
+ goto err;
+ }
+
+ cgroup_list = calloc(argc, sizeof(struct cgroup_group_spec *));
+ if (cgroup_list == NULL) {
+ fprintf(stderr, "%s: out of memory\n", argv[0]);
+ ret = -1;
+ goto err;
}
/*
* Parse arguments
*/
- while ((c = getopt_long(argc, argv, "rh",
+ while ((c = getopt_long(argc, argv, "rhg:",
long_options, NULL)) > 0) {
switch (c) {
case 'r':
flags |= CGFLAG_DELETE_RECURSIVE;
break;
+ case 'g':
+ ret = parse_cgroup_spec(cgroup_list, optarg, argc);
+ if (ret != 0) {
+ fprintf(stderr,
+ "%s: error parsing cgroup '%s'\n",
+ argv[0], optarg);
+ ret = -1;
+ goto err;
+ }
+ break;
case 'h':
usage(0, argv[0]);
ret = 0;
}
}
- if (optind >= argc) {
- usage(1, argv[0]);
- ret = -1;
- goto err;
- }
-
- /* initialize libcg */
- ret = cgroup_init();
- if (ret) {
- fprintf(stderr, "%s: "
- "libcgroup initialization failed: %s\n",
- argv[0], cgroup_strerror(ret));
- goto err;
- }
-
- capacity = argc - optind;
- cgroup_list = calloc(capacity, sizeof(struct cgroup_group_spec *));
- if (cgroup_list == NULL) {
- fprintf(stderr, "%s: out of memory\n", argv[0]);
- ret = -1;
- goto err;
- }
-
/* parse groups on command line */
for (i = optind; i < argc; i++) {
- ret = parse_cgroup_spec(cgroup_list, argv[i], capacity);
+ ret = parse_cgroup_spec(cgroup_list, argv[i], argc);
if (ret != 0) {
fprintf(stderr, "%s: error parsing cgroup '%s'\n",
argv[0], argv[i]);
}
}
- /* for each cgroup to delete */
- for (i = 0; i < capacity; i++) {
+ /* for each cgroup to be deleted */
+ for (i = 0; i < argc; i++) {
if (!cgroup_list[i])
break;
ret = final_ret;
err:
if (cgroup_list) {
- for (i = 0; i < capacity; i++) {
+ for (i = 0; i < argc; i++) {
if (cgroup_list[i])
cgroup_free_group_spec(cgroup_list[i]);
}