On Sat, Nov 29, 2008 at 12:23 PM, Sripathi Kodi <[EMAIL PROTECTED]> wrote:
> Hi,
>
> The following patch improves cgconfigparser's parameter checking and
> usage(). It provides:
>
> 1) Support for long options. Not really needed now, but good to have.
> 2) Improved usage() functionality.
>
> Thanks,
> Sripathi.
>
> Signed-off-by: Sripathi Kodi <[EMAIL PROTECTED]>
>

Thanks sripathi. I will merge this patch in.

> Index: libcg/cgconfig.c
> ===================================================================
> --- libcg/cgconfig.c    (revision 225)
> +++ libcg/cgconfig.c    (working copy)
> @@ -23,21 +23,38 @@
>  #include <stdlib.h>
>  #include <string.h>
>  #include <errno.h>
> +#include <getopt.h>
>
> +
> +static void usage(char *progname)
> +{
> +       printf("Usage: %s [OPTION] [FILE]\n", basename(progname));
> +       printf("Parse and load the specified cgroups configuration file\n");
> +       printf("\n");
> +       printf("  -h, --help            Display this help\n");
> +       printf("  -l, --load=FILE       Parse and load the cgroups 
> configuration file\n");
> +       exit(2);
> +}
> +
>  int main(int argc, char *argv[])
>  {
>        int c;
>        char filename[PATH_MAX];
>        int ret;
> +       static struct option options[] = {
> +               {"help", 0, 0, 'h'},
> +               {"load", 1, 0, 'l'},
> +               {0, 0, 0, 0}
> +       };
>
> -       if (argc < 2) {
> -               fprintf(stderr, "usage is %s <option> <config file>\n",
> -                       argv[0]);
> -               exit(2);
> -       }
> +       if (argc < 2)
> +               usage(argv[0]); /* usage() exits */
>
> -       while ((c = getopt(argc, argv, "l:")) > 0) {
> +       while ((c = getopt_long(argc, argv, "hl:", options, NULL)) > 0) {
>                switch (c) {
> +               case 'h':
> +                       usage(argv[0]);
> +                       break;
>                case 'l':
>                        strncpy(filename, optarg, PATH_MAX);
>                        ret = cgroup_config_load_config(filename);
> @@ -50,11 +67,9 @@
>                        }
>                        return 0;
>                default:
> -                       fprintf(stderr, "Invalid command line option\n");
> +                       usage(argv[0]);
>                        break;
>                }
>        }
> -       fprintf(stderr, "usage is %s <option> <config file>\n",
> -               argv[0]);
>        return 0;
>  }
>

-- 

Woody Allen  - "I will not eat oysters. I want my food dead. Not sick.
Not wounded. Dead."

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to