[sheepdog-users] [PATCH stable-0.7 4/5] dog: permit two or more depth of subcommands

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Thu Dec 12 10:46:44 CET 2013


From: Hitoshi Mitake <mitake.hitoshi at gmail.com>

Current dog command dies when user invokes "dog node log level set" without any
arguments because of its subcommand design. This patch removes this limitation.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 dog/common.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/dog/common.c b/dog/common.c
index c6e85e8..aa99049 100644
--- a/dog/common.c
+++ b/dog/common.c
@@ -218,7 +218,9 @@ int send_light_req(struct sd_req *hdr, const uint8_t *addr, int port)
 int do_generic_subcommand(struct subcommand *sub, int argc, char **argv)
 {
 	int i, ret;
+	static int depth = -1;
 
+	depth++;
 	for (i = 0; sub[i].name; i++) {
 		if (!strcmp(sub[i].name, argv[optind])) {
 			unsigned long flags = sub[i].flags;
@@ -231,7 +233,7 @@ int do_generic_subcommand(struct subcommand *sub, int argc, char **argv)
 				}
 			}
 
-			if (flags & CMD_NEED_ARG && argc < 5)
+			if (flags & CMD_NEED_ARG && argc < 5 + depth)
 				subcommand_usage(argv[1], argv[2], EXIT_USAGE);
 			optind++;
 			ret = sub[i].fn(argc, argv);
@@ -241,6 +243,7 @@ int do_generic_subcommand(struct subcommand *sub, int argc, char **argv)
 		}
 	}
 
+	depth--;
 	subcommand_usage(argv[1], argv[2], EXIT_FAILURE);
 	return EXIT_FAILURE;
 }
-- 
1.7.10.4




More information about the sheepdog-users mailing list