aboutsummaryrefslogtreecommitdiff
path: root/shell/ash.c
diff options
context:
space:
mode:
Diffstat (limited to 'shell/ash.c')
-rw-r--r--shell/ash.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 7131609e4..1b40e3407 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -208,6 +208,11 @@
208#include <sys/times.h> 208#include <sys/times.h>
209#include <sys/utsname.h> /* for setting $HOSTNAME */ 209#include <sys/utsname.h> /* for setting $HOSTNAME */
210#include "busybox.h" /* for applet_names */ 210#include "busybox.h" /* for applet_names */
211#if ENABLE_FEATURE_SH_EMBEDDED_SCRIPTS
212# include "embedded_scripts.h"
213#else
214# define NUM_SCRIPTS 0
215#endif
211 216
212/* So far, all bash compat is controlled by one config option */ 217/* So far, all bash compat is controlled by one config option */
213/* Separate defines document which part of code implements what */ 218/* Separate defines document which part of code implements what */
@@ -2503,13 +2508,12 @@ setvar(const char *name, const char *val, int flags)
2503 } 2508 }
2504 2509
2505 INT_OFF; 2510 INT_OFF;
2506 nameeq = ckmalloc(namelen + vallen + 2); 2511 nameeq = ckzalloc(namelen + vallen + 2);
2507 p = mempcpy(nameeq, name, namelen); 2512 p = mempcpy(nameeq, name, namelen);
2508 if (val) { 2513 if (val) {
2509 *p++ = '='; 2514 *p++ = '=';
2510 p = mempcpy(p, val, vallen); 2515 memcpy(p, val, vallen);
2511 } 2516 }
2512 *p = '\0';
2513 vp = setvareq(nameeq, flags | VNOSAVE); 2517 vp = setvareq(nameeq, flags | VNOSAVE);
2514 INT_ON; 2518 INT_ON;
2515 2519
@@ -8420,6 +8424,7 @@ tryexec(IF_FEATURE_SH_STANDALONE(int applet_no,) const char *cmd, char **argv, c
8420#else 8424#else
8421 execve(cmd, argv, envp); 8425 execve(cmd, argv, envp);
8422#endif 8426#endif
8427
8423 if (cmd != bb_busybox_exec_path && errno == ENOEXEC) { 8428 if (cmd != bb_busybox_exec_path && errno == ENOEXEC) {
8424 /* Run "cmd" as a shell script: 8429 /* Run "cmd" as a shell script:
8425 * http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html 8430 * http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
@@ -13459,6 +13464,7 @@ parseheredoc(void)
13459 heredoclist = NULL; 13464 heredoclist = NULL;
13460 13465
13461 while (here) { 13466 while (here) {
13467 tokpushback = 0;
13462 setprompt_if(needprompt, 2); 13468 setprompt_if(needprompt, 2);
13463 readtoken1(pgetc(), here->here->type == NHERE ? SQSYNTAX : DQSYNTAX, 13469 readtoken1(pgetc(), here->here->type == NHERE ? SQSYNTAX : DQSYNTAX,
13464 here->eofmark, here->striptabs); 13470 here->eofmark, here->striptabs);
@@ -14662,12 +14668,16 @@ procargs(char **argv)
14662 14668
14663 xargv = argv; 14669 xargv = argv;
14664 login_sh = xargv[0] && xargv[0][0] == '-'; 14670 login_sh = xargv[0] && xargv[0][0] == '-';
14671#if NUM_SCRIPTS > 0
14672 if (minusc)
14673 goto setarg0;
14674#endif
14665 arg0 = xargv[0]; 14675 arg0 = xargv[0];
14666 /* if (xargv[0]) - mmm, this is always true! */ 14676 /* if (xargv[0]) - mmm, this is always true! */
14667 xargv++; 14677 xargv++;
14678 argptr = xargv;
14668 for (i = 0; i < NOPTS; i++) 14679 for (i = 0; i < NOPTS; i++)
14669 optlist[i] = 2; 14680 optlist[i] = 2;
14670 argptr = xargv;
14671 if (options(/*cmdline:*/ 1, &login_sh)) { 14681 if (options(/*cmdline:*/ 1, &login_sh)) {
14672 /* it already printed err message */ 14682 /* it already printed err message */
14673 raise_exception(EXERROR); 14683 raise_exception(EXERROR);
@@ -14772,7 +14782,12 @@ extern int etext();
14772 * is used to figure out how far we had gotten. 14782 * is used to figure out how far we had gotten.
14773 */ 14783 */
14774int ash_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 14784int ash_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
14785#if NUM_SCRIPTS > 0
14786int ash_main(int argc, char **argv)
14787#else
14775int ash_main(int argc UNUSED_PARAM, char **argv) 14788int ash_main(int argc UNUSED_PARAM, char **argv)
14789#endif
14790/* note: 'argc' is used only if embedded scripts are enabled */
14776{ 14791{
14777 volatile smallint state; 14792 volatile smallint state;
14778 struct jmploc jmploc; 14793 struct jmploc jmploc;
@@ -14839,6 +14854,12 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
14839 bb_error_msg_and_die("forkshell failed"); 14854 bb_error_msg_and_die("forkshell failed");
14840 } 14855 }
14841#endif 14856#endif
14857
14858#if NUM_SCRIPTS > 0
14859 if (argc < 0)
14860 /* Non-NULL minusc tells procargs that an embedded script is being run */
14861 minusc = get_script_content(-argc - 1);
14862#endif
14842 login_sh = procargs(argv); 14863 login_sh = procargs(argv);
14843#if DEBUG 14864#if DEBUG
14844 TRACE(("Shell args: ")); 14865 TRACE(("Shell args: "));