[PATCH] ash: simplify handling of local PATH assignment
Ron Yorston
rmy at pobox.com
Sun Dec 16 09:58:55 UTC 2018
dash commit cbb71a8 'eval: Add assignment built-in support again'
is large and intrusive. It hasn't (yet) been imported into BusyBox
ash.
One element of this patch is useful in its own right: a simplification
of the treatment of local assignments to PATH.
function old new delta
evalcommand 1724 1684 -40
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-40) Total: -40 bytes
Signed-off-by: Ron Yorston <rmy at pobox.com>
---
shell/ash.c | 25 ++++++-------------------
1 file changed, 6 insertions(+), 19 deletions(-)
diff --git a/shell/ash.c b/shell/ash.c
index a01c8fa8b..e6ce67ed2 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -10004,6 +10004,10 @@ evalcommand(union node *cmd, int flags)
arglist.lastp = &arglist.list;
*arglist.lastp = NULL;
+ cmd_is_exec = 0;
+ spclbltin = -1;
+ path = NULL;
+
argc = 0;
if (cmd->ncmd.args) {
struct builtincmd *bcmd;
@@ -10053,23 +10057,13 @@ evalcommand(union node *cmd, int flags)
}
status = redirectsafe(cmd->ncmd.redirect, REDIR_PUSH | REDIR_SAVEFD2);
- path = vpath.var_text;
for (argp = cmd->ncmd.assign; argp; argp = argp->narg.next) {
struct strlist **spp;
- char *p;
spp = varlist.lastp;
expandarg(argp, &varlist, EXP_VARTILDE);
mklocal((*spp)->text);
-
- /*
- * Modify the command lookup path, if a PATH= assignment
- * is present
- */
- p = (*spp)->text;
- if (varcmp(p, path) == 0)
- path = p;
}
/* Print the command if xflag is set. */
@@ -10108,18 +10102,11 @@ evalcommand(union node *cmd, int flags)
safe_write(preverrout_fd, "\n", 1);
}
- cmd_is_exec = 0;
- spclbltin = -1;
-
/* Now locate the command. */
if (argc) {
int cmd_flag = DO_ERR;
-#if ENABLE_ASH_CMDCMD
- const char *oldpath = path + 5;
-#endif
- path += 5;
for (;;) {
- find_command(argv[0], &cmdentry, cmd_flag, path);
+ find_command(argv[0], &cmdentry, cmd_flag, path ? path : pathval());
if (cmdentry.cmdtype == CMDUNKNOWN) {
flush_stdout_stderr();
status = 127;
@@ -10135,7 +10122,6 @@ evalcommand(union node *cmd, int flags)
cmd_is_exec = 1;
#if ENABLE_ASH_CMDCMD
if (cmdentry.u.cmd == COMMANDCMD) {
- path = oldpath;
nargv = parse_command_args(argv, &path);
if (!nargv)
break;
@@ -10226,6 +10212,7 @@ evalcommand(union node *cmd, int flags)
/* fall through to exec'ing external program */
}
listsetvar(varlist.list, VEXPORT|VSTACK);
+ path = path ? path : pathval();
shellexec(argv[0], argv, path, cmdentry.u.index);
/* NOTREACHED */
} /* default */
--
2.19.2
More information about the busybox
mailing list