aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-04-12 21:02:33 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-04-12 21:02:33 +0200
commite139ae307e4fd9eb3b86a6fc2e97b4e212925199 (patch)
treedf7c2706fda186ae84ddd2c1fcca17b69226c915
parent352ddd3d216131757ac278e97a09ce2f4d7f53f0 (diff)
downloadbusybox-w32-e139ae307e4fd9eb3b86a6fc2e97b4e212925199.tar.gz
busybox-w32-e139ae307e4fd9eb3b86a6fc2e97b4e212925199.tar.bz2
busybox-w32-e139ae307e4fd9eb3b86a6fc2e97b4e212925199.zip
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>
-rw-r--r--shell/ash.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 983f7b108..044f166be 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -7744,9 +7744,8 @@ tryexec(IF_FEATURE_SH_STANDALONE(int applet_no,) char *cmd, char **argv, char **
7744 * have to change the find_command routine as well. 7744 * have to change the find_command routine as well.
7745 * argv[-1] must exist and be writable! See tryexec() for why. 7745 * argv[-1] must exist and be writable! See tryexec() for why.
7746 */ 7746 */
7747static void shellexec(char **, const char *, int) NORETURN; 7747static void shellexec(char *prog, char **argv, const char *path, int idx) NORETURN;
7748static void 7748static void shellexec(char *prog, char **argv, const char *path, int idx)
7749shellexec(char **argv, const char *path, int idx)
7750{ 7749{
7751 char *cmdname; 7750 char *cmdname;
7752 int e; 7751 int e;
@@ -7755,12 +7754,12 @@ shellexec(char **argv, const char *path, int idx)
7755 int applet_no = -1; /* used only by FEATURE_SH_STANDALONE */ 7754 int applet_no = -1; /* used only by FEATURE_SH_STANDALONE */
7756 7755
7757 envp = listvars(VEXPORT, VUNSET, /*end:*/ NULL); 7756 envp = listvars(VEXPORT, VUNSET, /*end:*/ NULL);
7758 if (strchr(argv[0], '/') != NULL 7757 if (strchr(prog, '/') != NULL
7759#if ENABLE_FEATURE_SH_STANDALONE 7758#if ENABLE_FEATURE_SH_STANDALONE
7760 || (applet_no = find_applet_by_name(argv[0])) >= 0 7759 || (applet_no = find_applet_by_name(prog)) >= 0
7761#endif 7760#endif
7762 ) { 7761 ) {
7763 tryexec(IF_FEATURE_SH_STANDALONE(applet_no,) argv[0], argv, envp); 7762 tryexec(IF_FEATURE_SH_STANDALONE(applet_no,) prog, argv, envp);
7764 if (applet_no >= 0) { 7763 if (applet_no >= 0) {
7765 /* We tried execing ourself, but it didn't work. 7764 /* We tried execing ourself, but it didn't work.
7766 * Maybe /proc/self/exe doesn't exist? 7765 * Maybe /proc/self/exe doesn't exist?
@@ -7772,7 +7771,7 @@ shellexec(char **argv, const char *path, int idx)
7772 } else { 7771 } else {
7773 try_PATH: 7772 try_PATH:
7774 e = ENOENT; 7773 e = ENOENT;
7775 while ((cmdname = path_advance(&path, argv[0])) != NULL) { 7774 while ((cmdname = path_advance(&path, prog)) != NULL) {
7776 if (--idx < 0 && pathopt == NULL) { 7775 if (--idx < 0 && pathopt == NULL) {
7777 tryexec(IF_FEATURE_SH_STANDALONE(-1,) cmdname, argv, envp); 7776 tryexec(IF_FEATURE_SH_STANDALONE(-1,) cmdname, argv, envp);
7778 if (errno != ENOENT && errno != ENOTDIR) 7777 if (errno != ENOENT && errno != ENOTDIR)
@@ -7796,8 +7795,8 @@ shellexec(char **argv, const char *path, int idx)
7796 } 7795 }
7797 exitstatus = exerrno; 7796 exitstatus = exerrno;
7798 TRACE(("shellexec failed for %s, errno %d, suppress_int %d\n", 7797 TRACE(("shellexec failed for %s, errno %d, suppress_int %d\n",
7799 argv[0], e, suppress_int)); 7798 prog, e, suppress_int));
7800 ash_msg_and_raise(EXEXIT, "%s: %s", argv[0], errmsg(e, "not found")); 7799 ash_msg_and_raise(EXEXIT, "%s: %s", prog, errmsg(e, "not found"));
7801 /* NOTREACHED */ 7800 /* NOTREACHED */
7802} 7801}
7803 7802
@@ -9371,7 +9370,7 @@ execcmd(int argc UNUSED_PARAM, char **argv)
9371 /*setsignal(SIGTSTP); - unnecessary because of mflag=0 */ 9370 /*setsignal(SIGTSTP); - unnecessary because of mflag=0 */
9372 /*setsignal(SIGTTOU); - unnecessary because of mflag=0 */ 9371 /*setsignal(SIGTTOU); - unnecessary because of mflag=0 */
9373 9372
9374 shellexec(argv + 1, pathval(), 0); 9373 shellexec(argv[1], argv + 1, pathval(), 0);
9375 /* NOTREACHED */ 9374 /* NOTREACHED */
9376 } 9375 }
9377 return 0; 9376 return 0;
@@ -9773,7 +9772,7 @@ evalcommand(union node *cmd, int flags)
9773 /* fall through to exec'ing external program */ 9772 /* fall through to exec'ing external program */
9774 } 9773 }
9775 listsetvar(varlist.list, VEXPORT|VSTACK); 9774 listsetvar(varlist.list, VEXPORT|VSTACK);
9776 shellexec(argv, path, cmdentry.u.index); 9775 shellexec(argv[0], argv, path, cmdentry.u.index);
9777 /* NOTREACHED */ 9776 /* NOTREACHED */
9778 } /* default */ 9777 } /* default */
9779 case CMDBUILTIN: 9778 case CMDBUILTIN: