On 11/05/2010 02:56 PM, Ivana Hutarova Varekova wrote: > From: Your Name<[email protected]> > > This patch adds help option to cgcreate tool > and unified the cgget error messages > > CHANGELOG v1: > * fix the typo (thanks jsafrane) > > Signed-off-by: Ivana Hutarova Varekova<[email protected]>
Acked-By: Jan Safranek <[email protected]> > --- > > src/tools/cgcreate.c | 47 +++++++++++++++++++++++++++++++++++++++-------- > 1 files changed, 39 insertions(+), 8 deletions(-) > > diff --git a/doc/man/cgcreate.1 b/doc/man/cgcreate.1 > index 2d444ef..d8e0449 100644 > --- a/doc/man/cgcreate.1 > +++ b/doc/man/cgcreate.1 > @@ -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 > > diff --git a/src/tools/cgcreate.c b/src/tools/cgcreate.c > index 435df4a..c79183e 100644 > --- a/src/tools/cgcreate.c > +++ b/src/tools/cgcreate.c > @@ -24,8 +24,33 @@ > #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; > } > > > ------------------------------------------------------------------------------ > The Next 800 Companies to Lead America's Growth: New Video Whitepaper > David G. Thomson, author of the best-selling book "Blueprint to a > Billion" shares his insights and actions to help propel your > business during the next growth cycle. Listen Now! > http://p.sf.net/sfu/SAP-dev2dev > _______________________________________________ > Libcg-devel mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/libcg-devel ------------------------------------------------------------------------------ The Next 800 Companies to Lead America's Growth: New Video Whitepaper David G. Thomson, author of the best-selling book "Blueprint to a Billion" shares his insights and actions to help propel your business during the next growth cycle. Listen Now! http://p.sf.net/sfu/SAP-dev2dev _______________________________________________ Libcg-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/libcg-devel
