summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDhaval Giani <dhaval@linux.vnet.ibm.com>2008-12-09 11:14:24 +0000
committerDhaval Giani <dhaval@linux.vnet.ibm.com>2008-12-09 11:14:24 +0000
commit50dce522e4a5a09d43012b1d3d18ac80a5c16863 (patch)
treee4e0300a18c1823a527e313367022bf4aa6c1162
parentc2222a666db14f0b2fc138d05f18829fe1b357d3 (diff)
downloadlibcg-50dce522e4a5a09d43012b1d3d18ac80a5c16863.tar.gz
libcg-50dce522e4a5a09d43012b1d3d18ac80a5c16863.tar.xz
libcg-50dce522e4a5a09d43012b1d3d18ac80a5c16863.zip
libcgroup: Improve parameter checking and usage in cgconfigparser
From: Sripathi Kodi <sripathik@in.ibm.com> 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. Signed-off-by: Sripathi Kodi <sripathik@in.ibm.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@227 4f4bb910-9a46-0410-90c8-c897d4f1cd53
-rw-r--r--cgconfig.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/cgconfig.c b/cgconfig.c
index 16ff63b..fab3a72 100644
--- a/cgconfig.c
+++ b/cgconfig.c
@@ -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 @@ int main(int argc, char *argv[])
}
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;
}