hush: implement "command" builtin (no options are supported yet)
authorDenys Vlasenko <vda.linux@googlemail.com>
Thu, 11 Jan 2018 17:05:05 +0000 (18:05 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 11 Jan 2018 17:05:05 +0000 (18:05 +0100)
function                                             old     new   delta
pseudo_exec_argv                                     194     231     +37

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/hush.c

index c2b987f49e51f6f705f67f2709ebf209e0eef03c..93779ba1ebbed8d755a6a6a24ba727c180a7ad85 100644 (file)
@@ -58,6 +58,7 @@
  *              (can use this to override standalone shell as well)
  *              -p: use default $PATH
  *          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 [-e EDITOR] [BEG] [END]: edit/rerun range of commands
  *          fc -s [PAT=REP] [CMD]: rerun CMD, replacing PAT with REP
 //config:      default y
 //config:      depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
 //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:      bool "trap builtin"
 //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.
         */
        {
+               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
                 * just in order to run echo or test builtin.
                 * It's better to skip it here and run corresponding
                 * non-builtin later. */
-               const struct built_in_command *x;
                x = BB_MMU ? find_builtin(argv[0]) : find_builtin1(argv[0]);
                if (x) {
                        exec_builtin(&nommu_save->argv_from_re_execing, x, argv);