hush: allow hush to run embedded scripts

Embedded scripts require a shell to be present in the BusyBox
binary.  Allow either ash or hush to be used for this purpose.
If both are enabled ash takes precedence.

The size of the binary is unchanged in the default configuration:
both ash and hush are present but support for embedded scripts
isn't compiled into hush.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Ron Yorston
2018-11-27 14:34:25 +00:00
committed by Denys Vlasenko
parent f4709d78cb
commit 71df2d3589
10 changed files with 62 additions and 32 deletions

View File

@ -367,6 +367,11 @@
# define PIPE_BUF 4096 /* amount of buffering in a pipe */
#endif
#if ENABLE_FEATURE_SH_EMBEDDED_SCRIPTS && !(ENABLE_ASH || ENABLE_SH_IS_ASH || ENABLE_BASH_IS_ASH)
# include "embedded_scripts.h"
#else
# define NUM_SCRIPTS 0
#endif
/* So far, all bash compat is controlled by one config option */
/* Separate defines document which part of code implements what */
@ -9951,6 +9956,14 @@ int hush_main(int argc, char **argv)
/* http://www.opengroup.org/onlinepubs/9699919799/utilities/sh.html */
flags = (argv[0] && argv[0][0] == '-') ? OPT_login : 0;
builtin_argc = 0;
#if NUM_SCRIPTS > 0
if (argc < 0) {
optarg = get_script_content(-argc - 1);
optind = 0;
argc = string_array_len(argv);
goto run_script;
}
#endif
while (1) {
int opt = getopt(argc, argv, "+c:exinsl"
#if !BB_MMU
@ -9974,6 +9987,9 @@ int hush_main(int argc, char **argv)
* Note: the form without ARG0 never happens:
* sh ... -c 'builtin' BARGV... ""
*/
#if NUM_SCRIPTS > 0
run_script:
#endif
if (!G.root_pid) {
G.root_pid = getpid();
G.root_ppid = getppid();