diff options
author | Ron Yorston <rmy@pobox.com> | 2018-11-28 10:28:18 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-11-28 10:28:18 +0000 |
commit | 2a69a2200a141c1504b662eca64b802cdab71b12 (patch) | |
tree | eab0cc01852db237a26052a83c8f582ed92b7cd9 /shell | |
parent | 97ca1f4b955f486cd26461cb09185335483d2921 (diff) | |
parent | 572dfb8e78323b9837f7c5e3369ee233a440b8f2 (diff) | |
download | busybox-w32-2a69a2200a141c1504b662eca64b802cdab71b12.tar.gz busybox-w32-2a69a2200a141c1504b662eca64b802cdab71b12.tar.bz2 busybox-w32-2a69a2200a141c1504b662eca64b802cdab71b12.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'shell')
-rw-r--r-- | shell/Config.src | 14 | ||||
-rw-r--r-- | shell/ash.c | 29 | ||||
-rw-r--r-- | shell/hush.c | 18 |
3 files changed, 56 insertions, 5 deletions
diff --git a/shell/Config.src b/shell/Config.src index 959d3cb42..bc7218fe5 100644 --- a/shell/Config.src +++ b/shell/Config.src | |||
@@ -161,6 +161,20 @@ config FEATURE_SH_HISTFILESIZE | |||
161 | to set shell history size. Note that its max value is capped | 161 | to set shell history size. Note that its max value is capped |
162 | by "History size" setting in library tuning section. | 162 | by "History size" setting in library tuning section. |
163 | 163 | ||
164 | config FEATURE_SH_EMBEDDED_SCRIPTS | ||
165 | bool "Embed scripts in the binary" | ||
166 | default y | ||
167 | depends on ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH | ||
168 | help | ||
169 | Allow scripts to be compressed and embedded in the busybox | ||
170 | binary. The scripts should be placed in the 'embed' directory | ||
171 | at build time. Like applets, scripts can be run as | ||
172 | 'busybox SCRIPT ...' or by linking their name to the binary. | ||
173 | |||
174 | This also allows applets to be implemented as scripts: place | ||
175 | the script in 'applets_sh' and a stub C file containing | ||
176 | configuration in the appropriate subsystem directory. | ||
177 | |||
164 | endif # Options common to all shells | 178 | endif # Options common to all shells |
165 | 179 | ||
166 | endmenu | 180 | endmenu |
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 | */ |
14774 | int ash_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 14784 | int ash_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
14785 | #if NUM_SCRIPTS > 0 | ||
14786 | int ash_main(int argc, char **argv) | ||
14787 | #else | ||
14775 | int ash_main(int argc UNUSED_PARAM, char **argv) | 14788 | int 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: ")); |
diff --git a/shell/hush.c b/shell/hush.c index 881331c5b..90191408d 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -157,7 +157,7 @@ | |||
157 | //config: but no separate process group is formed. | 157 | //config: but no separate process group is formed. |
158 | //config: | 158 | //config: |
159 | //config:config HUSH_TICK | 159 | //config:config HUSH_TICK |
160 | //config: bool "Support process substitution" | 160 | //config: bool "Support command substitution" |
161 | //config: default y | 161 | //config: default y |
162 | //config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH | 162 | //config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH |
163 | //config: help | 163 | //config: help |
@@ -367,6 +367,11 @@ | |||
367 | # define PIPE_BUF 4096 /* amount of buffering in a pipe */ | 367 | # define PIPE_BUF 4096 /* amount of buffering in a pipe */ |
368 | #endif | 368 | #endif |
369 | 369 | ||
370 | #if ENABLE_FEATURE_SH_EMBEDDED_SCRIPTS && !(ENABLE_ASH || ENABLE_SH_IS_ASH || ENABLE_BASH_IS_ASH) | ||
371 | # include "embedded_scripts.h" | ||
372 | #else | ||
373 | # define NUM_SCRIPTS 0 | ||
374 | #endif | ||
370 | 375 | ||
371 | /* So far, all bash compat is controlled by one config option */ | 376 | /* So far, all bash compat is controlled by one config option */ |
372 | /* Separate defines document which part of code implements what */ | 377 | /* Separate defines document which part of code implements what */ |
@@ -9951,6 +9956,14 @@ int hush_main(int argc, char **argv) | |||
9951 | /* http://www.opengroup.org/onlinepubs/9699919799/utilities/sh.html */ | 9956 | /* http://www.opengroup.org/onlinepubs/9699919799/utilities/sh.html */ |
9952 | flags = (argv[0] && argv[0][0] == '-') ? OPT_login : 0; | 9957 | flags = (argv[0] && argv[0][0] == '-') ? OPT_login : 0; |
9953 | builtin_argc = 0; | 9958 | builtin_argc = 0; |
9959 | #if NUM_SCRIPTS > 0 | ||
9960 | if (argc < 0) { | ||
9961 | optarg = get_script_content(-argc - 1); | ||
9962 | optind = 0; | ||
9963 | argc = string_array_len(argv); | ||
9964 | goto run_script; | ||
9965 | } | ||
9966 | #endif | ||
9954 | while (1) { | 9967 | while (1) { |
9955 | int opt = getopt(argc, argv, "+c:exinsl" | 9968 | int opt = getopt(argc, argv, "+c:exinsl" |
9956 | #if !BB_MMU | 9969 | #if !BB_MMU |
@@ -9974,6 +9987,9 @@ int hush_main(int argc, char **argv) | |||
9974 | * Note: the form without ARG0 never happens: | 9987 | * Note: the form without ARG0 never happens: |
9975 | * sh ... -c 'builtin' BARGV... "" | 9988 | * sh ... -c 'builtin' BARGV... "" |
9976 | */ | 9989 | */ |
9990 | #if NUM_SCRIPTS > 0 | ||
9991 | run_script: | ||
9992 | #endif | ||
9977 | if (!G.root_pid) { | 9993 | if (!G.root_pid) { |
9978 | G.root_pid = getpid(); | 9994 | G.root_pid = getpid(); |
9979 | G.root_ppid = getppid(); | 9995 | G.root_ppid = getppid(); |