]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
Add -h option to cgdelete tool
authorIvana Hutarova Varekova <varekova@redhat.com>
Thu, 28 Apr 2011 08:25:10 +0000 (10:25 +0200)
committerJan Safranek <jsafrane@redhat.com>
Thu, 28 Apr 2011 11:32:26 +0000 (13:32 +0200)
This patch adds option -h to cgdelete tool

Signed-off-by: Ivana Hutarova Varekova <varekova@redhat.com>
Signed-off-by: Jan Safranek <jsafrane@redhat.com>
doc/man/cgdelete.1
src/tools/cgdelete.c

index 73d29241977c191abd0767c57d2d7e5fb70c5b86..f1e17a7be06739829ef97bb2a2c1e4b092c1b145 100644 (file)
@@ -7,7 +7,7 @@
 cgdelete \- remove control group(s)
 
 .SH SYNOPSIS
-\fBcgdelete\fR [\fB-r\fR] [<\fIcontrollers\fR>:\fI<path\fR>] ...
+\fBcgdelete\fR [\fB-h\fR] [\fB-r\fR] [<\fIcontrollers\fR>:\fI<path\fR>] ...
 
 .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
index 7da6ab40bc1879e98d1150162502bfd3a4ace895..ba8e75f9fa3698c2c05ea408d5deee3ecc97dcb9 100644 (file)
 #include <string.h>
 #include <errno.h>
 #include <unistd.h>
+#include <getopt.h>
 
 #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 ]  [<controllers>:<path>] ...\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] "
-                       "<list of controllers>:<relative path to cgroup> "
-                       "[...]\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;
        }