]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
Add -h option to cgexec tool
authorIvana Hutarova Varekova <varekova@redhat.com>
Thu, 28 Apr 2011 08:25:17 +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 cgexec tool

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

index bf197bdbfba31b84f89e5f9851427e243bde3fc2..e9d38d20d414d98f7060772d466b6b380982c6f8 100644 (file)
@@ -7,7 +7,7 @@
 cgexec \- run the task in given control groups
 
 .SH SYNOPSIS
-\fBcgexec\fR [\fB-g\fR <\fIcontrollers>:<path\fR>] [--sticky] \fBcommand\fR [\fIarguments\fR]
+\fBcgexec\fR [\fB-h\fR] [\fB-g\fR <\fIcontrollers>:<path\fR>] [--sticky] \fBcommand\fR [\fIarguments\fR]
 
 .SH DESCRIPTION
 The \fBcgexec\fR
@@ -31,6 +31,10 @@ If this option is not used then
 \fBcgexec\fR will automatically place the task to the right
 cgroup based on \fB/etc/cgrules.conf\fR.
 
+.TP
+.B -h, --help
+Display this help and exit.
+
 .TP
 .B --sticky
 If running the task \fBcommand\fR with this option, the daemon of
index 8e0b4d8cdbe44c23c32577e518f7726e56a3ef2d..f03f1fa031c95943fb3b059782bc6c89840d29e3 100644 (file)
 #include "tools-common.h"
 
 static struct option longopts[] = {
-       {"sticky", no_argument, NULL, 's'}, 
+       {"sticky", no_argument, NULL, 's'},
+       {"help", no_argument, NULL, 'h'},
        {0, 0, 0, 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] [-g <controllers>:<path>] "
+                       "[--sticky] command [arguments] ...\n",
+                       program_name);
+       }
+}
+
+
 int main(int argc, char *argv[])
 {
        int ret = 0, i;
@@ -50,17 +65,9 @@ int main(int argc, char *argv[])
        int c;
        struct cgroup_group_spec *cgroup_list[CG_HIER_MAX];
 
-       if (argc < 2) {
-               fprintf(stderr, "Usage is %s"
-                       " [-g <list of controllers>:<relative path to cgroup>]"
-                       " [--sticky] command [arguments]  \n",
-                       argv[0]);
-               exit(2);
-       }
-
        memset(cgroup_list, 0, sizeof(cgroup_list));
 
-       while ((c = getopt_long(argc, argv, "+g:s", longopts, NULL)) > 0) {
+       while ((c = getopt_long(argc, argv, "+g:sh", longopts, NULL)) > 0) {
                switch (c) {
                case 'g':
                        ret = parse_cgroup_spec(cgroup_list, optarg,
@@ -75,16 +82,18 @@ int main(int argc, char *argv[])
                case 's':
                        flag_child |= CGROUP_DAEMON_UNCHANGE_CHILDREN;
                        break;
+               case 'h':
+                       usage(0, argv[0]);
+                       exit(0);
                default:
-                       fprintf(stderr, "Invalid command line option\n");
+                       usage(1, argv[0]);
                        exit(1);
-                       break;
                }
        }
 
        /* Executable name */
        if (!argv[optind]) {
-               fprintf(stderr, "No command specified\n");
+               usage(1, argv[0]);
                exit(1);
        }