diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2012-02-25 17:10:57 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2012-02-27 19:53:47 +0100 |
commit | aed0e6ba0396dc34a7b7af8a342b6682d9cd1ed0 (patch) | |
tree | 0148e7d1d1353c8ba5b622a3dad7589c14f315fc /common/command.c | |
parent | 2034ee47b1a0dfb3988cf159094d73c3ec623597 (diff) | |
download | barebox-aed0e6ba0396dc34a7b7af8a342b6682d9cd1ed0.tar.gz barebox-aed0e6ba0396dc34a7b7af8a342b6682d9cd1ed0.tar.xz |
getopt: save and restore context
execute_command is the single point where commands are executed and thus a new
getopt context is needed. currently we call getopt_reset here to reset the
context. This breaks though when a command tries to run a command itself by
calling execute_command or run_command. In this case we have to store the
context and restore it afterwards. The same is necessary in builtin_getopt.
Currently noone does this so this one shouldn't fix a bug, but merely allows
us to do such things later.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/command.c')
-rw-r--r-- | common/command.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/common/command.c b/common/command.c index ab02ed5322..de2c3a9cdf 100644 --- a/common/command.c +++ b/common/command.c @@ -91,8 +91,9 @@ int execute_command(int argc, char **argv) { struct command *cmdtp; int ret; + struct getopt_context gc; - getopt_reset(); + getopt_context_store(&gc); /* Look up command in command table */ if ((cmdtp = find_cmd(argv[0]))) { @@ -100,17 +101,20 @@ int execute_command(int argc, char **argv) ret = cmdtp->cmd(cmdtp, argc, argv); if (ret == COMMAND_ERROR_USAGE) { barebox_cmd_usage(cmdtp); - return COMMAND_ERROR; + ret = COMMAND_ERROR; } - return ret; } else { #ifdef CONFIG_CMD_HELP printf ("Unknown command '%s' - try 'help'\n", argv[0]); #else printf ("Unknown command '%s'\n", argv[0]); #endif - return -1; /* give up after bad command */ + ret = -1; /* give up after bad command */ } + + getopt_context_restore(&gc); + + return ret; } int register_command(struct command *cmd) |