mirror of
https://github.com/sheumann/hush.git
synced 2024-06-01 00:41:33 +00:00
ash: make shellexec capable of using separate argv[0] and filename to exec
function old new delta execcmd 71 78 +7 shellexec 221 224 +3 evalcommand 1158 1161 +3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 13/0) Total: 13 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
352ddd3d21
commit
e139ae307e
21
shell/ash.c
21
shell/ash.c
|
@ -7744,9 +7744,8 @@ tryexec(IF_FEATURE_SH_STANDALONE(int applet_no,) char *cmd, char **argv, char **
|
||||||
* have to change the find_command routine as well.
|
* have to change the find_command routine as well.
|
||||||
* argv[-1] must exist and be writable! See tryexec() for why.
|
* argv[-1] must exist and be writable! See tryexec() for why.
|
||||||
*/
|
*/
|
||||||
static void shellexec(char **, const char *, int) NORETURN;
|
static void shellexec(char *prog, char **argv, const char *path, int idx) NORETURN;
|
||||||
static void
|
static void shellexec(char *prog, char **argv, const char *path, int idx)
|
||||||
shellexec(char **argv, const char *path, int idx)
|
|
||||||
{
|
{
|
||||||
char *cmdname;
|
char *cmdname;
|
||||||
int e;
|
int e;
|
||||||
|
@ -7755,12 +7754,12 @@ shellexec(char **argv, const char *path, int idx)
|
||||||
int applet_no = -1; /* used only by FEATURE_SH_STANDALONE */
|
int applet_no = -1; /* used only by FEATURE_SH_STANDALONE */
|
||||||
|
|
||||||
envp = listvars(VEXPORT, VUNSET, /*end:*/ NULL);
|
envp = listvars(VEXPORT, VUNSET, /*end:*/ NULL);
|
||||||
if (strchr(argv[0], '/') != NULL
|
if (strchr(prog, '/') != NULL
|
||||||
#if ENABLE_FEATURE_SH_STANDALONE
|
#if ENABLE_FEATURE_SH_STANDALONE
|
||||||
|| (applet_no = find_applet_by_name(argv[0])) >= 0
|
|| (applet_no = find_applet_by_name(prog)) >= 0
|
||||||
#endif
|
#endif
|
||||||
) {
|
) {
|
||||||
tryexec(IF_FEATURE_SH_STANDALONE(applet_no,) argv[0], argv, envp);
|
tryexec(IF_FEATURE_SH_STANDALONE(applet_no,) prog, argv, envp);
|
||||||
if (applet_no >= 0) {
|
if (applet_no >= 0) {
|
||||||
/* We tried execing ourself, but it didn't work.
|
/* We tried execing ourself, but it didn't work.
|
||||||
* Maybe /proc/self/exe doesn't exist?
|
* Maybe /proc/self/exe doesn't exist?
|
||||||
|
@ -7772,7 +7771,7 @@ shellexec(char **argv, const char *path, int idx)
|
||||||
} else {
|
} else {
|
||||||
try_PATH:
|
try_PATH:
|
||||||
e = ENOENT;
|
e = ENOENT;
|
||||||
while ((cmdname = path_advance(&path, argv[0])) != NULL) {
|
while ((cmdname = path_advance(&path, prog)) != NULL) {
|
||||||
if (--idx < 0 && pathopt == NULL) {
|
if (--idx < 0 && pathopt == NULL) {
|
||||||
tryexec(IF_FEATURE_SH_STANDALONE(-1,) cmdname, argv, envp);
|
tryexec(IF_FEATURE_SH_STANDALONE(-1,) cmdname, argv, envp);
|
||||||
if (errno != ENOENT && errno != ENOTDIR)
|
if (errno != ENOENT && errno != ENOTDIR)
|
||||||
|
@ -7796,8 +7795,8 @@ shellexec(char **argv, const char *path, int idx)
|
||||||
}
|
}
|
||||||
exitstatus = exerrno;
|
exitstatus = exerrno;
|
||||||
TRACE(("shellexec failed for %s, errno %d, suppress_int %d\n",
|
TRACE(("shellexec failed for %s, errno %d, suppress_int %d\n",
|
||||||
argv[0], e, suppress_int));
|
prog, e, suppress_int));
|
||||||
ash_msg_and_raise(EXEXIT, "%s: %s", argv[0], errmsg(e, "not found"));
|
ash_msg_and_raise(EXEXIT, "%s: %s", prog, errmsg(e, "not found"));
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9371,7 +9370,7 @@ execcmd(int argc UNUSED_PARAM, char **argv)
|
||||||
/*setsignal(SIGTSTP); - unnecessary because of mflag=0 */
|
/*setsignal(SIGTSTP); - unnecessary because of mflag=0 */
|
||||||
/*setsignal(SIGTTOU); - unnecessary because of mflag=0 */
|
/*setsignal(SIGTTOU); - unnecessary because of mflag=0 */
|
||||||
|
|
||||||
shellexec(argv + 1, pathval(), 0);
|
shellexec(argv[1], argv + 1, pathval(), 0);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -9773,7 +9772,7 @@ evalcommand(union node *cmd, int flags)
|
||||||
/* fall through to exec'ing external program */
|
/* fall through to exec'ing external program */
|
||||||
}
|
}
|
||||||
listsetvar(varlist.list, VEXPORT|VSTACK);
|
listsetvar(varlist.list, VEXPORT|VSTACK);
|
||||||
shellexec(argv, path, cmdentry.u.index);
|
shellexec(argv[0], argv, path, cmdentry.u.index);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
} /* default */
|
} /* default */
|
||||||
case CMDBUILTIN:
|
case CMDBUILTIN:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user