Most of the tools use <controllers>:<path> together with -g option
(cgcreate, cgget and cgclassify), this patch adds this option to
cgdelete.
Signed-off-by: Ivana Hutarova Varekova <[email protected]>
---
doc/man/cgdelete.1 | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/doc/man/cgdelete.1 b/doc/man/cgdelete.1
index f1e17a7..a6adf1f 100644
--- a/doc/man/cgdelete.1
+++ b/doc/man/cgdelete.1
@@ -7,16 +7,19 @@
cgdelete \- remove control group(s)
.SH SYNOPSIS
-\fBcgdelete\fR [\fB-h\fR] [\fB-r\fR] [<\fIcontrollers\fR>:\fI<path\fR>] ...
+\fBcgdelete\fR [\fB-h\fR] [\fB-r\fR] [[\fB-g\fR]
+<\fIcontrollers\fR>:\fI<path\fR>] ...
.SH DESCRIPTION
The \fBcgdelete\fR
program removes all specified control groups.
.TP
-.B <controllers>:<path>
+.B [-g] <controllers>:<path>
Defines control group to delete. There can be multiple control
groups specified.
+.B -g
+is optional.
.TP
.B -h, --help
diff --git a/src/tools/cgdelete.c b/src/tools/cgdelete.c
index ba8e75f..c7b4721 100644
--- a/src/tools/cgdelete.c
+++ b/src/tools/cgdelete.c
@@ -29,6 +29,7 @@ static struct option const long_options[] =
{
{"recursive", no_argument, NULL, 'r'},
{"help", no_argument, NULL, 'h'},
+ {"group", required_argument, NULL, 'g'},
{NULL, 0, NULL, 0}
};
@@ -39,7 +40,8 @@ static void usage(int status, const char *program_name)
" 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);
}
}
@@ -52,26 +54,46 @@ int main(int argc, char *argv[])
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;
@@ -83,32 +105,9 @@ int main(int argc, char *argv[])
}
}
- 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]);
@@ -117,8 +116,8 @@ int main(int argc, char *argv[])
}
}
- /* 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;
@@ -164,7 +163,7 @@ int main(int argc, char *argv[])
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]);
}
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today. Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel