summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvana Varekova <varekova@redhat.com>2009-06-19 17:08:35 +0200
committerDhaval Giani <dhaval@linux.vnet.ibm.com>2009-06-29 16:59:16 +0530
commitb70f033df1ef23a1f46c577c195979b6eed57bfc (patch)
treef6bd97af82808743e68c198d56728f6bc824a2b0
parent264acc5ddb7b0099b50772f89b93991f72290ea3 (diff)
downloadlibcg-b70f033df1ef23a1f46c577c195979b6eed57bfc.tar.gz
libcg-b70f033df1ef23a1f46c577c195979b6eed57bfc.tar.xz
libcg-b70f033df1ef23a1f46c577c195979b6eed57bfc.zip
cgset: Change the handling of options, add --help
Change the handling of options - add the possibility to use long options - add --help option - change the type of c (see man 3 getopt_long) Signed-off-by: Ivana Varekova <varekova@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
-rw-r--r--src/tools/cgset.c41
1 files changed, 35 insertions, 6 deletions
diff --git a/src/tools/cgset.c b/src/tools/cgset.c
index 071ffac..0c153eb 100644
--- a/src/tools/cgset.c
+++ b/src/tools/cgset.c
@@ -5,9 +5,18 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <getopt.h>
#include "tools-common.h"
+static struct option const long_options[] =
+{
+ {"rule", required_argument, NULL, 'r'},
+ {"help", no_argument, NULL, 'h'},
+ {NULL, 0, NULL, 0}
+};
+
+
struct cgroup *copy_name_value_from_rules(int nv_number,
struct control_value *name_value)
{
@@ -63,11 +72,24 @@ scgroup_err:
return NULL;
}
+void usage(int status, char *program_name)
+{
+ if (status != 0)
+ fprintf(stderr, "Wrong input parameters,"
+ " try %s --help' for more information.\n",
+ program_name);
+ else {
+ printf("Usage: %s [-r <name=value>] <cgroup_path> ...\n"
+ " or: %s --copy-from <source_cgrup_path> "
+ "<cgroup_path> ...\n",
+ program_name, program_name, program_name);
+ }
+}
int main(int argc, char *argv[])
{
int ret = 0;
- char c;
+ int c;
char *buf;
struct control_value *name_value = NULL;
@@ -86,8 +108,15 @@ int main(int argc, char *argv[])
}
/* parse arguments */
- while ((c = getopt(argc, argv, "r:")) > 0) {
+ while ((c = getopt_long (argc, argv,
+ "r:h", long_options, NULL)) != -1) {
switch (c) {
+ case 'h':
+ usage(0, argv[0]);
+ ret = 0;
+ goto err;
+ break;
+
case 'r':
/* add name-value pair to buffer
(= name_value variable) */
@@ -97,8 +126,9 @@ int main(int argc, char *argv[])
realloc(name_value,
nv_max * sizeof(struct control_value));
if (!name_value) {
- fprintf(stderr, "cgset: "
- "not enough memory\n");
+ fprintf(stderr, "%s: "
+ "not enough memory\n",
+ argv[0]);
ret = -1;
goto err;
}
@@ -133,8 +163,7 @@ int main(int argc, char *argv[])
nv_number++;
break;
default:
- fprintf(stderr, "%s: invalid command line option\n",
- argv[0]);
+ usage(1, argv[0]);
ret = -1;
goto err;
break;