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
\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
#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;
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,
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);
}