hush: implement "command" builtin (no options are supported yet)

function                                             old     new   delta
pseudo_exec_argv                                     194     231     +37

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2018-01-11 18:05:05 +01:00
parent 1f1911239c
commit 3bb3e1d0a1

View File

@ -58,6 +58,7 @@
* (can use this to override standalone shell as well) * (can use this to override standalone shell as well)
* -p: use default $PATH * -p: use default $PATH
* command BLTIN: disables special-ness (e.g. errors do not abort) * command BLTIN: disables special-ness (e.g. errors do not abort)
* NB: so far, only naked "command CMD" is implemented.
* fc -l[nr] [BEG] [END]: list range of commands in history * fc -l[nr] [BEG] [END]: list range of commands in history
* fc [-e EDITOR] [BEG] [END]: edit/rerun range of commands * fc [-e EDITOR] [BEG] [END]: edit/rerun range of commands
* fc -s [PAT=REP] [CMD]: rerun CMD, replacing PAT with REP * fc -s [PAT=REP] [CMD]: rerun CMD, replacing PAT with REP
@ -253,6 +254,11 @@
//config: default y //config: default y
//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH //config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
//config: //config:
//config:config HUSH_COMMAND
//config: bool "command builtin"
//config: default y
//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
//config:
//config:config HUSH_TRAP //config:config HUSH_TRAP
//config: bool "trap builtin" //config: bool "trap builtin"
//config: default y //config: default y
@ -7406,11 +7412,20 @@ static NOINLINE void pseudo_exec_argv(nommu_save_t *nommu_save,
* if this is one of those cases. * if this is one of those cases.
*/ */
{ {
const struct built_in_command *x;
#if ENABLE_HUSH_COMMAND
/* This loop effectively makes "command BAR" run BAR without
* looking it up among functions.
*/
while (strcmp(argv[0], "command") == 0 && argv[1])
argv++;
//TODO: implement -Vvp and "disable dying if BAR is a builtin" behavior
#endif
/* On NOMMU, it is more expensive to re-execute shell /* On NOMMU, it is more expensive to re-execute shell
* just in order to run echo or test builtin. * just in order to run echo or test builtin.
* It's better to skip it here and run corresponding * It's better to skip it here and run corresponding
* non-builtin later. */ * non-builtin later. */
const struct built_in_command *x;
x = BB_MMU ? find_builtin(argv[0]) : find_builtin1(argv[0]); x = BB_MMU ? find_builtin(argv[0]) : find_builtin1(argv[0]);
if (x) { if (x) {
exec_builtin(&nommu_save->argv_from_re_execing, x, argv); exec_builtin(&nommu_save->argv_from_re_execing, x, argv);