diff options
-rw-r--r-- | archival/libarchive/Kbuild.src | 2 | ||||
-rw-r--r-- | docs/embedded-scripts.txt | 21 | ||||
-rw-r--r-- | include/libbb.h | 5 | ||||
-rw-r--r-- | libbb/appletlib.c | 8 | ||||
-rwxr-xr-x | scripts/embedded_scripts | 8 | ||||
-rwxr-xr-x | scripts/gen_build_files.sh | 2 | ||||
-rw-r--r-- | shell/Config.src | 14 | ||||
-rw-r--r-- | shell/ash.c | 16 | ||||
-rw-r--r-- | shell/hush.c | 16 | ||||
-rw-r--r-- | util-linux/nologin.c | 2 |
10 files changed, 62 insertions, 32 deletions
diff --git a/archival/libarchive/Kbuild.src b/archival/libarchive/Kbuild.src index 12e66a88b..d2f284b08 100644 --- a/archival/libarchive/Kbuild.src +++ b/archival/libarchive/Kbuild.src | |||
@@ -91,7 +91,7 @@ lib-$(CONFIG_FEATURE_SEAMLESS_LZMA) += open_transformer.o decompress_unlzma. | |||
91 | lib-$(CONFIG_FEATURE_SEAMLESS_XZ) += open_transformer.o decompress_unxz.o | 91 | lib-$(CONFIG_FEATURE_SEAMLESS_XZ) += open_transformer.o decompress_unxz.o |
92 | lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += open_transformer.o decompress_bunzip2.o | 92 | lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += open_transformer.o decompress_bunzip2.o |
93 | lib-$(CONFIG_FEATURE_COMPRESS_BBCONFIG) += open_transformer.o decompress_bunzip2.o | 93 | lib-$(CONFIG_FEATURE_COMPRESS_BBCONFIG) += open_transformer.o decompress_bunzip2.o |
94 | lib-$(CONFIG_ASH_EMBEDDED_SCRIPTS) += open_transformer.o decompress_bunzip2.o | 94 | lib-$(CONFIG_FEATURE_SH_EMBEDDED_SCRIPTS) += open_transformer.o decompress_bunzip2.o |
95 | 95 | ||
96 | ifneq ($(lib-y),) | 96 | ifneq ($(lib-y),) |
97 | lib-y += $(COMMON_FILES) | 97 | lib-y += $(COMMON_FILES) |
diff --git a/docs/embedded-scripts.txt b/docs/embedded-scripts.txt index 1b0c5b591..7a273d698 100644 --- a/docs/embedded-scripts.txt +++ b/docs/embedded-scripts.txt | |||
@@ -3,13 +3,9 @@ Embedded Shell Scripts in BusyBox | |||
3 | 3 | ||
4 | BusyBox allows applets to be implemented as shell scripts. Since | 4 | BusyBox allows applets to be implemented as shell scripts. Since |
5 | this obviously requires a shell to interpret the scripts the feature | 5 | this obviously requires a shell to interpret the scripts the feature |
6 | depends on having a shell (specifically, ash) built into the binary. | 6 | depends on having a shell built into the binary. Either ash or hush |
7 | Support for embedded scripts also has to be enabled. | 7 | will do. If both are present ash will be used. Support for embedded |
8 | 8 | scripts also has to be enabled. | |
9 | To embed scripts in BusyBox you must enable these configuration options: | ||
10 | |||
11 | ASH | ||
12 | ASH_EMBEDDED_SCRIPTS | ||
13 | 9 | ||
14 | It's unlikely that your applet will be implemented as a pure shell | 10 | It's unlikely that your applet will be implemented as a pure shell |
15 | script: it will probably need some external commands. If these are | 11 | script: it will probably need some external commands. If these are |
@@ -75,10 +71,9 @@ code for the native applet: | |||
75 | 71 | ||
76 | The only difference is that the applet is specified as being of type | 72 | The only difference is that the applet is specified as being of type |
77 | APPLET_SCRIPTED. It would also be useful to include details of any | 73 | APPLET_SCRIPTED. It would also be useful to include details of any |
78 | dependencies the script has. We can assume that ash is available. | 74 | dependencies the script has. No external commands are used by our mu |
79 | No external commands are used by our mu script, but it does depend on | 75 | script, but it does depend on optional shell features. We can ensure |
80 | optional shell features. We can ensure these are selected by adding | 76 | these are selected by adding this to the configuration: |
81 | this to the configuration: | ||
82 | 77 | ||
83 | //config:config MU_DEPENDENCIES | 78 | //config:config MU_DEPENDENCIES |
84 | //config: bool "Enable dependencies for mu" | 79 | //config: bool "Enable dependencies for mu" |
@@ -87,8 +82,8 @@ this to the configuration: | |||
87 | //config: select ASH_RANDOM_SUPPORT | 82 | //config: select ASH_RANDOM_SUPPORT |
88 | //config: select FEATURE_SH_MATH | 83 | //config: select FEATURE_SH_MATH |
89 | //config: help | 84 | //config: help |
90 | //config: mu is implemented as a shell script. It requires ash | 85 | //config: mu is implemented as a shell script. It requires support |
91 | //config: support for $RANDOM and arithmetic. | 86 | //config: for $RANDOM and arithmetic. |
92 | 87 | ||
93 | The configuration data should be placed in a C file in an appropriate | 88 | The configuration data should be placed in a C file in an appropriate |
94 | subdirectory. There isn't any C code, though! In this case the file | 89 | subdirectory. There isn't any C code, though! In this case the file |
diff --git a/include/libbb.h b/include/libbb.h index ebd090e18..b560cc2eb 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -1348,6 +1348,11 @@ int ash_main(int argc, char** argv) | |||
1348 | MAIN_EXTERNALLY_VISIBLE | 1348 | MAIN_EXTERNALLY_VISIBLE |
1349 | #endif | 1349 | #endif |
1350 | ; | 1350 | ; |
1351 | int hush_main(int argc, char** argv) | ||
1352 | #if ENABLE_HUSH || ENABLE_SH_IS_HUSH || ENABLE_BASH_IS_HUSH | ||
1353 | MAIN_EXTERNALLY_VISIBLE | ||
1354 | #endif | ||
1355 | ; | ||
1351 | /* If shell needs them, they exist even if not enabled as applets */ | 1356 | /* If shell needs them, they exist even if not enabled as applets */ |
1352 | int echo_main(int argc, char** argv) IF_ECHO(MAIN_EXTERNALLY_VISIBLE); | 1357 | int echo_main(int argc, char** argv) IF_ECHO(MAIN_EXTERNALLY_VISIBLE); |
1353 | int printf_main(int argc, char **argv) IF_PRINTF(MAIN_EXTERNALLY_VISIBLE); | 1358 | int printf_main(int argc, char **argv) IF_PRINTF(MAIN_EXTERNALLY_VISIBLE); |
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index a79a37efb..cd09b620c 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
@@ -50,7 +50,7 @@ | |||
50 | 50 | ||
51 | #include "usage_compressed.h" | 51 | #include "usage_compressed.h" |
52 | 52 | ||
53 | #if ENABLE_ASH_EMBEDDED_SCRIPTS | 53 | #if ENABLE_FEATURE_SH_EMBEDDED_SCRIPTS |
54 | # define DEFINE_SCRIPT_DATA 1 | 54 | # define DEFINE_SCRIPT_DATA 1 |
55 | # include "embedded_scripts.h" | 55 | # include "embedded_scripts.h" |
56 | #else | 56 | #else |
@@ -774,7 +774,13 @@ int scripted_main(int argc UNUSED_PARAM, char **argv) | |||
774 | { | 774 | { |
775 | int script = find_script_by_name(applet_name); | 775 | int script = find_script_by_name(applet_name); |
776 | if (script >= 0) | 776 | if (script >= 0) |
777 | #if ENABLE_ASH || ENABLE_SH_IS_ASH || ENABLE_BASH_IS_ASH | ||
777 | exit(ash_main(-script - 1, argv)); | 778 | exit(ash_main(-script - 1, argv)); |
779 | #elif ENABLE_HUSH || ENABLE_SH_IS_HUSH || ENABLE_BASH_IS_HUSH | ||
780 | exit(hush_main(-script - 1, argv)); | ||
781 | #else | ||
782 | return 1; | ||
783 | #endif | ||
778 | return 0; | 784 | return 0; |
779 | } | 785 | } |
780 | 786 | ||
diff --git a/scripts/embedded_scripts b/scripts/embedded_scripts index 86ad44d1d..aa7bf3e8a 100755 --- a/scripts/embedded_scripts +++ b/scripts/embedded_scripts | |||
@@ -1,5 +1,7 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | 2 | ||
3 | . ./.config || exit 1 | ||
4 | |||
3 | target="$1" | 5 | target="$1" |
4 | custom_loc="$2" | 6 | custom_loc="$2" |
5 | applet_loc="$3" | 7 | applet_loc="$3" |
@@ -8,6 +10,12 @@ test "$target" || exit 1 | |||
8 | test "$SED" || SED=sed | 10 | test "$SED" || SED=sed |
9 | test "$DD" || DD=dd | 11 | test "$DD" || DD=dd |
10 | 12 | ||
13 | if [ x"$CONFIG_FEATURE_SH_EMBEDDED_SCRIPTS" != x"y" ] | ||
14 | then | ||
15 | printf '#define NUM_SCRIPTS 0\n' >"$target" | ||
16 | exit 0 | ||
17 | fi | ||
18 | |||
11 | # Some people were bitten by their system lacking a (proper) od | 19 | # Some people were bitten by their system lacking a (proper) od |
12 | od -v -b </dev/null >/dev/null | 20 | od -v -b </dev/null >/dev/null |
13 | if test $? != 0; then | 21 | if test $? != 0; then |
diff --git a/scripts/gen_build_files.sh b/scripts/gen_build_files.sh index 362632df3..92de681ac 100755 --- a/scripts/gen_build_files.sh +++ b/scripts/gen_build_files.sh | |||
@@ -25,7 +25,7 @@ custom_scripts() | |||
25 | then | 25 | then |
26 | for i in $(cd "$custom_loc"; ls * 2>/dev/null) | 26 | for i in $(cd "$custom_loc"; ls * 2>/dev/null) |
27 | do | 27 | do |
28 | printf "APPLET_SCRIPTED(%s, scripted, BB_DIR_USR_BIN, BB_SUID_DROP, scripted)\n" $i; | 28 | printf "IF_FEATURE_SH_EMBEDDED_SCRIPTS(APPLET_SCRIPTED(%s, scripted, BB_DIR_USR_BIN, BB_SUID_DROP, scripted))\n" $i; |
29 | done | 29 | done |
30 | fi | 30 | fi |
31 | } | 31 | } |
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 04e4006c8..9ce1d1a76 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -148,20 +148,6 @@ | |||
148 | //config: you to run the specified command or builtin, | 148 | //config: you to run the specified command or builtin, |
149 | //config: even when there is a function with the same name. | 149 | //config: even when there is a function with the same name. |
150 | //config: | 150 | //config: |
151 | //config:config ASH_EMBEDDED_SCRIPTS | ||
152 | //config: bool "Embed scripts in the binary" | ||
153 | //config: default y | ||
154 | //config: depends on ASH || SH_IS_ASH || BASH_IS_ASH | ||
155 | //config: help | ||
156 | //config: Allow scripts to be compressed and embedded in the busybox | ||
157 | //config: binary. The scripts should be placed in the 'embed' directory | ||
158 | //config: at build time. Like applets, scripts can be run as | ||
159 | //config: 'busybox SCRIPT ...' or by linking their name to the binary. | ||
160 | //config: | ||
161 | //config: This also allows applets to be implemented as scripts: place | ||
162 | //config: the script in 'applets_sh' and a stub C file containing | ||
163 | //config: configuration in the appropriate subsystem directory. | ||
164 | //config: | ||
165 | //config:endif # ash options | 151 | //config:endif # ash options |
166 | 152 | ||
167 | //applet:IF_ASH(APPLET(ash, BB_DIR_BIN, BB_SUID_DROP)) | 153 | //applet:IF_ASH(APPLET(ash, BB_DIR_BIN, BB_SUID_DROP)) |
@@ -195,7 +181,7 @@ | |||
195 | #include <sys/times.h> | 181 | #include <sys/times.h> |
196 | #include <sys/utsname.h> /* for setting $HOSTNAME */ | 182 | #include <sys/utsname.h> /* for setting $HOSTNAME */ |
197 | #include "busybox.h" /* for applet_names */ | 183 | #include "busybox.h" /* for applet_names */ |
198 | #if ENABLE_ASH_EMBEDDED_SCRIPTS | 184 | #if ENABLE_FEATURE_SH_EMBEDDED_SCRIPTS |
199 | # include "embedded_scripts.h" | 185 | # include "embedded_scripts.h" |
200 | #else | 186 | #else |
201 | # define NUM_SCRIPTS 0 | 187 | # define NUM_SCRIPTS 0 |
diff --git a/shell/hush.c b/shell/hush.c index 431010f09..90191408d 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -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(); |
diff --git a/util-linux/nologin.c b/util-linux/nologin.c index 0982fff3d..5e5e42305 100644 --- a/util-linux/nologin.c +++ b/util-linux/nologin.c | |||
@@ -1,7 +1,7 @@ | |||
1 | //config:config NOLOGIN | 1 | //config:config NOLOGIN |
2 | //config: bool "nologin" | 2 | //config: bool "nologin" |
3 | //config: default y | 3 | //config: default y |
4 | //config: depends on ASH_EMBEDDED_SCRIPTS | 4 | //config: depends on FEATURE_SH_EMBEDDED_SCRIPTS |
5 | //config: help | 5 | //config: help |
6 | //config: Politely refuse a login | 6 | //config: Politely refuse a login |
7 | //config: | 7 | //config: |