From: Ivana Hutarova Varekova Date: Thu, 28 Apr 2011 08:25:10 +0000 (+0200) Subject: Add -h option to cgdelete tool X-Git-Tag: v0.38~99 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d54dd06370297a656b54e9ead0c3c8724853de3b;p=thirdparty%2Flibcgroup.git Add -h option to cgdelete tool This patch adds option -h to cgdelete tool Signed-off-by: Ivana Hutarova Varekova Signed-off-by: Jan Safranek --- diff --git a/doc/man/cgdelete.1 b/doc/man/cgdelete.1 index 73d29241..f1e17a7b 100644 --- a/doc/man/cgdelete.1 +++ b/doc/man/cgdelete.1 @@ -7,7 +7,7 @@ cgdelete \- remove control group(s) .SH SYNOPSIS -\fBcgdelete\fR [\fB-r\fR] [<\fIcontrollers\fR>:\fI] ... +\fBcgdelete\fR [\fB-h\fR] [\fB-r\fR] [<\fIcontrollers\fR>:\fI] ... .SH DESCRIPTION The \fBcgdelete\fR @@ -19,7 +19,11 @@ Defines control group to delete. There can be multiple control groups specified. .TP -.B -r +.B -h, --help +Display this help and exit. + +.TP +.B -r, --recursive Recursively remove all subgroups. .SH SEE ALSO diff --git a/src/tools/cgdelete.c b/src/tools/cgdelete.c index 7da6ab40..ba8e75f9 100644 --- a/src/tools/cgdelete.c +++ b/src/tools/cgdelete.c @@ -21,9 +21,30 @@ #include #include #include +#include #include "tools-common.h" +static struct option const long_options[] = +{ + {"recursive", no_argument, NULL, 'r'}, + {"help", no_argument, NULL, 'h'}, + {NULL, 0, NULL, 0} +}; + +static void usage(int status, const char *program_name) +{ + if (status != 0) + fprintf(stderr, "Wrong input parameters," + " try %s --help' for more information.\n", + program_name); + else { + printf("Usage: %s [-h ] [-r ] [:] ...\n", + program_name); + } +} + + int main(int argc, char *argv[]) { int ret = 0; @@ -38,34 +59,32 @@ int main(int argc, char *argv[]) struct cgroup_controller *cgc; if (argc < 2) { - fprintf(stderr, "Usage is %s [-r] " - ": " - "[...]\n", - argv[0]); + usage(1, argv[0]); return -1; } /* * Parse arguments */ - while ((c = getopt(argc, argv, "r")) > 0) { + while ((c = getopt_long(argc, argv, "rh", + long_options, NULL)) > 0) { switch (c) { case 'r': flags |= CGFLAG_DELETE_RECURSIVE; break; + case 'h': + usage(0, argv[0]); + ret = 0; + goto err; default: - fprintf(stderr, "%s: " - "invalid command line option\n", - argv[0]); - return -1; - break; + usage(1, argv[0]); + ret = -1; + goto err; } } if (optind >= argc) { - fprintf(stderr, "%s: " - "no groups to delete\n", - argv[0]); + usage(1, argv[0]); ret = -1; goto err; }