On 11/02/2010 02:29 PM, Ivana Hutarova Varekova wrote:
> From: Your Name<[email protected]>
>
> This patch adds help option to cgcreate tool
> and unified the cgget error messages
>
> Signed-off-by: Ivana Hutarova Varekova<[email protected]>
> ---
>
> doc/man/cgcreate.1 | 7 +++++--
> src/tools/cgcreate.c | 47 +++++++++++++++++++++++++++++++++++++++--------
> 2 files changed, 44 insertions(+), 10 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..d440d50 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> Controll "\
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;
> }
>
>
> ------------------------------------------------------------------------------
> Nokia and AT&T present the 2010 Calling All Innovators-North America contest
> Create new apps& games for the Nokia N8 for consumers in U.S. and Canada
> $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
> Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
> http://p.sf.net/sfu/nokia-dev2dev
> _______________________________________________
> Libcg-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/libcg-devel
------------------------------------------------------------------------------
Achieve Improved Network Security with IP and DNS Reputation.
Defend against bad network traffic, including botnets, malware,
phishing sites, and compromised hosts - saving your company time,
money, and embarrassment. Learn More!
http://p.sf.net/sfu/hpdev2dev-nov
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel