[Sheepdog] [PATCH] shepherd: fix commands requiring the third argument

FUJITA Tomonori fujita.tomonori at lab.ntt.co.jp
Mon May 10 04:08:10 CEST 2010


Signed-off-by: FUJITA Tomonori <fujita.tomonori at lab.ntt.co.jp>
---
 shepherd/shepherd.c |   23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/shepherd/shepherd.c b/shepherd/shepherd.c
index a63788e..9ea0045 100644
--- a/shepherd/shepherd.c
+++ b/shepherd/shepherd.c
@@ -1079,11 +1079,11 @@ static int (*command_parser)(int, char *);
 static int (*command_fn)(int, char **);
 static void (*command_help)(void);
 
-static void setup_command(char *cmd, char *subcmd)
+static unsigned long setup_command(char *cmd, char *subcmd)
 {
 	int i, found = 0;
 	struct subcommand *s;
-	unsigned long flags;
+	unsigned long flags = 0;
 
 	for (i = 0; i < ARRAY_SIZE(commands); i++) {
 		if (!strncmp(commands[i].name, cmd, strlen(commands[i].name))) {
@@ -1118,19 +1118,14 @@ static void setup_command(char *cmd, char *subcmd)
 		exit(1);
 	}
 
-	if (flags & SUBCMD_FLAG_NEED_THIRD_ARG) {
-		fprintf(stderr, "'%s %s' needs the third argument\n", cmd, subcmd);
-		exit(1);
-	}
-
-	if (flags & SUBCMD_FLAG_NEED_NOEDLIST)
-		update_node_list(SD_MAX_NODES, 0);
+	return flags;
 }
 
 int main(int argc, char **argv)
 {
 	int ch, longindex;
 	char termcap_area[1024];
+	unsigned long flags;
 
 	if (getenv("TERM"))
 		tgetent(termcap_area, getenv("TERM"));
@@ -1138,7 +1133,10 @@ int main(int argc, char **argv)
 	if (argc < 3)
 		usage(0);
 
-	setup_command(argv[1], argv[2]);
+	flags = setup_command(argv[1], argv[2]);
+
+	if (flags & SUBCMD_FLAG_NEED_NOEDLIST)
+		update_node_list(SD_MAX_NODES, 0);
 
 	optind = 3;
 
@@ -1165,5 +1163,10 @@ int main(int argc, char **argv)
 		}
 	}
 
+	if (flags & SUBCMD_FLAG_NEED_THIRD_ARG && argc == optind) {
+		fprintf(stderr, "'%s %s' needs the third argument\n", argv[1], argv[2]);
+		exit(1);
+	}
+
 	return command_fn(argc, argv);
 }
-- 
1.6.5




More information about the sheepdog mailing list