]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
This patch adds help option to cgcreate tool
authorIvana Hutarova Varekova <varekova@redhat.com>
Wed, 10 Nov 2010 15:08:20 +0000 (16:08 +0100)
committerJan Safranek <jsafrane@redhat.com>
Wed, 10 Nov 2010 15:08:20 +0000 (16:08 +0100)
and unified the cgget error messages

CHANGELOG v1:
* fix the typo (thanks jsafrane)

Signed-off-by: Ivana Hutarova Varekova<varekova@redhat.com>
Acked-by: Dhaval Giani <dhaval.giani@gmail.com>
Signed-off-by: Jan Safranek <jsafrane@redhat.com>
doc/man/cgcreate.1
src/tools/cgcreate.c

index 2d444ef4bd349994f283abf5daa61809fad7ea83..d8e0449d9d1e8c12258e0dd545cc7e525eb56f0f 100644 (file)
@@ -5,8 +5,8 @@
 cgcreate \- create new cgroup(s)
 
 .SH SYNOPSIS
-\fBcgcreate\fR [\fB-t\fR <\fItuid>:<tgid\fR>] [\fB-a\fR <\fIagid>:<auid\fR>] 
-\fB-g\fR <\fIcontrollers>:<path\fR> [-g ...]
+\fBcgcreate\fR [\fB-h\fR] [\fB-t\fR <\fItuid>:<tgid\fR>]
+[\fB-a\fR <\fIagid>:<auid\fR>] \fB-g\fR <\fIcontrollers>:<path\fR> [-g ...]
 
 .SH DESCRIPTION
 The command creates new cgroup(s) defined by option 
@@ -34,6 +34,9 @@ defines control groups which will be added.
 in the given controllers list. This option can be specified
 multiple times.
 
+.TP
+.B -h, --help
+display this help and exit
 
 .SH FILES
 
index 435df4a02b5c9791218945cfa9710bddf4937a2c..c79183eed08ba1aee444f159ae94136dfc658806 100644 (file)
 #include <errno.h>
 #include <unistd.h>
 #include <grp.h>
+#include <getopt.h>
 
 #include "tools-common.h"
+/*
+ * Display the usage
+ */
+static void usage(int status, const char *program_name)
+{
+       if (status != 0) {
+               fprintf(stderr, "Wrong input parameters,"
+                       " try %s -h' for more information.\n",
+                       program_name);
+       } else {
+               fprintf(stdout, "Usage: %s [-h] [-t <tuid>:<tgid>] "\
+                       "[-a <agid>:<auid>] -g <controllers>:<path> [-g ...]\n",
+                       program_name);
+               fprintf(stdout, "  -t <tuid>:<tgid>             Set "\
+                       "the task permission\n");
+               fprintf(stdout, "  -a <tuid>:<tgid>             Set "\
+                       "the admin permission\n");
+               fprintf(stdout, "  -g <controllers>:<path>      Control "\
+                       "group which should be added\n");
+               fprintf(stdout, "  -h,--help                    Display "\
+                       "this help\n");
+       }
+}
+
 
 int main(int argc, char *argv[])
 {
@@ -33,6 +58,14 @@ int main(int argc, char *argv[])
        int i, j;
        int c;
 
+       static struct option long_opts[] = {
+               {"help", no_argument, NULL, 'h'},
+               {"task", required_argument, NULL, 't'},
+               {"admin", required_argument, NULL, 'a'},
+               {"", required_argument, NULL, 'g'},
+               {0, 0, 0, 0},
+       };
+
        /* Structure to get GID from group name */
        struct group *grp = NULL;
        char *grp_string = NULL;
@@ -53,10 +86,7 @@ int main(int argc, char *argv[])
 
        /* no parametr on input */
        if (argc < 2) {
-               fprintf(stderr, "Usage is %s "
-                       "-t <tuid>:<tgid> -a <agid>:<auid> "
-                       "-g <list of controllers>:<relative path to cgroup>\n",
-                       argv[0]);
+               usage(1, argv[0]);
                return -1;
        }
        cgroup_list = calloc(capacity, sizeof(struct cgroup_group_spec *));
@@ -66,8 +96,11 @@ int main(int argc, char *argv[])
        }
 
        /* parse arguments */
-       while ((c = getopt(argc, argv, "a:t:g:")) > 0) {
+       while ((c = getopt_long(argc, argv, "a:t:g:h", long_opts, NULL)) > 0) {
                switch (c) {
+               case 'h':
+                       usage(0, argv[0]);
+                       return 0;
                case 'a':
                        /* set admin uid/gid */
                        if (optarg[0] == ':')
@@ -146,9 +179,7 @@ int main(int argc, char *argv[])
                        }
                        break;
                default:
-                       fprintf(stderr, "%s: "
-                               "invalid command line option\n",
-                               argv[0]);
+                       usage(1, argv[0]);
                        return -1;
                        break;
                }