On 04/28/2011 10:25 AM, Ivana Hutarova Varekova wrote:
> This patch adds option -h to cgdelete tool
> 
> 
> Signed-off-by: Ivana Hutarova Varekova <varek...@redhat.com>

Acked-By: Jan Safranek <jsafr...@redhat.com>
+ merged and pushed, thanks!

> ---
> 
>  src/tools/cgdelete.c |   45 ++++++++++++++++++++++++++++++++-------------
>  1 files changed, 32 insertions(+), 13 deletions(-)
> 
> diff --git a/doc/man/cgdelete.1 b/doc/man/cgdelete.1
> index 73d2924..f1e17a7 100644
> --- a/doc/man/cgdelete.1
> +++ b/doc/man/cgdelete.1
> @@ -7,7 +7,7 @@
>  cgdelete \- remove control group(s)
>  
>  .SH SYNOPSIS
> -\fBcgdelete\fR [\fB-r\fR] [<\fIcontrollers\fR>:\fI<path\fR>] ...
> +\fBcgdelete\fR [\fB-h\fR] [\fB-r\fR] [<\fIcontrollers\fR>:\fI<path\fR>] ...
>  
>  .SH DESCRIPTION
>  The \fBcgdelete\fR
> @@ -19,7 +19,11 @@ Defines control group to delete. There can be multiple 
> control
>  groups specified.
>  
>  .TP
> -.B -r
> +.B -h, --help
> +Display this help and exit.
> +
> +.TP
> +.B -r, --recursive
>  Recursively remove all subgroups.
>  
>  .SH SEE ALSO
> diff --git a/src/tools/cgdelete.c b/src/tools/cgdelete.c
> index 7da6ab4..ba8e75f 100644
> --- a/src/tools/cgdelete.c
> +++ b/src/tools/cgdelete.c
> @@ -21,9 +21,30 @@
>  #include <string.h>
>  #include <errno.h>
>  #include <unistd.h>
> +#include <getopt.h>
>  
>  #include "tools-common.h"
>  
> +static struct option const long_options[] =
> +{
> +     {"recursive", no_argument, NULL, 'r'},
> +     {"help", no_argument, NULL, 'h'},
> +     {NULL, 0, NULL, 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 ] [-r ]  [<controllers>:<path>] ...\n",
> +                     program_name);
> +     }
> +}
> +
> +
>  int main(int argc, char *argv[])
>  {
>       int ret = 0;
> @@ -38,34 +59,32 @@ int main(int argc, char *argv[])
>       struct cgroup_controller *cgc;
>  
>       if (argc < 2) {
> -             fprintf(stderr, "Usage is %s [-r] "
> -                     "<list of controllers>:<relative path to cgroup> "
> -                     "[...]\n",
> -                     argv[0]);
> +             usage(1, argv[0]);
>               return -1;
>       }
>  
>       /*
>        * Parse arguments
>        */
> -     while ((c = getopt(argc, argv, "r")) > 0) {
> +     while ((c = getopt_long(argc, argv, "rh",
> +             long_options, NULL)) > 0) {
>               switch (c) {
>               case 'r':
>                       flags |= CGFLAG_DELETE_RECURSIVE;
>                       break;
> +             case 'h':
> +                     usage(0, argv[0]);
> +                     ret = 0;
> +                     goto err;
>               default:
> -                     fprintf(stderr, "%s: "
> -                             "invalid command line option\n",
> -                             argv[0]);
> -                     return -1;
> -                     break;
> +                     usage(1, argv[0]);
> +                     ret = -1;
> +                     goto err;
>               }
>       }
>  
>       if (optind >= argc) {
> -             fprintf(stderr, "%s: "
> -                     "no groups to delete\n",
> -                     argv[0]);
> +             usage(1, argv[0]);
>               ret = -1;
>               goto err;
>       }
> 
> 
> ------------------------------------------------------------------------------
> WhatsUp Gold - Download Free Network Management Software
> The most intuitive, comprehensive, and cost-effective network 
> management toolset available today.  Delivers lowest initial 
> acquisition cost and overall TCO of any competing solution.
> http://p.sf.net/sfu/whatsupgold-sd
> _______________________________________________
> Libcg-devel mailing list
> Libcg-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/libcg-devel


------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to