diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2012-09-05 12:59:29 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2012-09-05 12:59:29 +0200 |
commit | 4c9d8da6fea91a49476b86bb92996a0480478537 (patch) | |
tree | bab82f82e57b8be39426d2b338796495b6649457 /common | |
parent | 978b0739dc9289e663283b2f275a5c0eed9ce01f (diff) | |
parent | 4d902142a5691cd9641b2ad468eb5407c897b433 (diff) | |
download | barebox-4c9d8da6fea91a49476b86bb92996a0480478537.tar.gz barebox-4c9d8da6fea91a49476b86bb92996a0480478537.tar.xz |
Merge branch 'for-next/hush'
Diffstat (limited to 'common')
-rw-r--r-- | common/command.c | 20 | ||||
-rw-r--r-- | common/hush.c | 45 |
2 files changed, 38 insertions, 27 deletions
diff --git a/common/command.c b/common/command.c index c18998c129..2bfc5117e8 100644 --- a/common/command.c +++ b/common/command.c @@ -38,26 +38,6 @@ LIST_HEAD(command_list); EXPORT_SYMBOL(command_list); -#ifdef CONFIG_SHELL_HUSH - -static int do_exit(int argc, char *argv[]) -{ - int r; - - r = 0; - if (argc > 1) - r = simple_strtoul(argv[1], NULL, 0); - - return -r - 2; -} - -BAREBOX_CMD_START(exit) - .cmd = do_exit, - .usage = "exit script", -BAREBOX_CMD_END - -#endif - void barebox_cmd_usage(struct command *cmdtp) { #ifdef CONFIG_LONGHELP diff --git a/common/hush.c b/common/hush.c index 8200931387..61aac13d1b 100644 --- a/common/hush.c +++ b/common/hush.c @@ -557,6 +557,18 @@ static int builtin_getopt(struct p_context *ctx, struct child_prog *child, } #endif +static int builtin_exit(struct p_context *ctx, struct child_prog *child, + int argc, char *argv[]) +{ + int r; + + r = last_return_code; + if (argc > 1) + r = simple_strtoul(argv[1], NULL, 0); + + return -r - 2; +} + static void remove_quotes_in_str(char *src) { char *trg = src; @@ -773,10 +785,17 @@ static int run_pipe_real(struct p_context *ctx, struct pipe *pi) remove_quotes(globbuf.gl_pathc, globbuf.gl_pathv); - if (!strcmp(globbuf.gl_pathv[0], "getopt")) + if (!strcmp(globbuf.gl_pathv[0], "getopt")) { ret = builtin_getopt(ctx, child, globbuf.gl_pathc, globbuf.gl_pathv); - else + } else if (!strcmp(globbuf.gl_pathv[0], "exit")) { + ret = builtin_exit(ctx, child, globbuf.gl_pathc, globbuf.gl_pathv); + } else { ret = execute_binfmt(globbuf.gl_pathc, globbuf.gl_pathv); + if (ret < 0) { + printf("%s: %s\n", globbuf.gl_pathv[0], strerror(-ret)); + ret = 127; + } + } globfree(&globbuf); @@ -1885,16 +1904,28 @@ BAREBOX_CMD_START(source) BAREBOX_CMD_HELP(cmd_source_help) BAREBOX_CMD_END -#ifdef CONFIG_HUSH_GETOPT -static int do_getopt(int argc, char *argv[]) +static int do_dummy_command(int argc, char *argv[]) { /* - * This function is never reached. The 'getopt' command is - * only here to provide a help text for the getopt builtin. + * This function is never reached. These commands are only here to + * provide help texts for the builtins. */ return 0; } +static const __maybe_unused char cmd_exit_help[] = +"Usage: exit [n]\n" +"\n" +"exit script with a status of n. If n is omitted, the exit status is that\n" +"of the last command executed\n"; + +BAREBOX_CMD_START(exit) + .cmd = do_dummy_command, + .usage = "exit script", + BAREBOX_CMD_HELP(cmd_exit_help) +BAREBOX_CMD_END + +#ifdef CONFIG_HUSH_GETOPT static const __maybe_unused char cmd_getopt_help[] = "Usage: getopt <optstring> <var>\n" "\n" @@ -1905,7 +1936,7 @@ static const __maybe_unused char cmd_getopt_help[] = "can be accessed starting from $1\n"; BAREBOX_CMD_START(getopt) - .cmd = do_getopt, + .cmd = do_dummy_command, .usage = "getopt <optstring> <var>", BAREBOX_CMD_HELP(cmd_getopt_help) BAREBOX_CMD_END |