1 --- busybox.orig/scripts/defconfig
2 +++ busybox/scripts/defconfig
4 CONFIG_FEATURE_SUID_CONFIG=y
5 CONFIG_FEATURE_SUID_CONFIG_QUIET=y
6 # CONFIG_SELINUX is not set
7 -# CONFIG_FEATURE_PREFER_APPLETS is not set
8 -CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
9 +# CONFIG_FEATURE_APPLETS_FALLBACK is not set
10 +CONFIG_BUSYBOX_EXEC_PATH="/bin/busybox"
11 CONFIG_FEATURE_SYSLOG=y
12 CONFIG_FEATURE_HAVE_RPC=y
14 --- busybox.orig/shell/Config.in
15 +++ busybox/shell/Config.in
17 config FEATURE_SH_STANDALONE
18 bool "Standalone shell"
20 - depends on (MSH || LASH || HUSH || ASH) && FEATURE_PREFER_APPLETS
22 - This option causes busybox shells to use busybox applets
23 - in preference to executables in the PATH whenever possible. For
24 - example, entering the command 'ifconfig' into the shell would cause
25 - busybox to use the ifconfig busybox applet. Specifying the fully
26 - qualified executable name, such as '/sbin/ifconfig' will still
27 - execute the /sbin/ifconfig executable on the filesystem. This option
28 - is generally used when creating a statically linked version of busybox
29 - for use as a rescue shell, in the event that you screw up your system.
31 - This is implemented by re-execing /proc/self/exe (typically)
32 - with right parameters. Some selected applets ("NOFORK" applets)
33 - can even be executed without creating new process.
34 - Instead, busybox will call <applet>_main() internally.
36 - However, this causes problems in chroot jails without mounted /proc
37 - and with ps/top (command name can be shown as 'exe' for applets
40 -# Note that this will *also* cause applets to take precedence
41 -# over shell builtins of the same name. So turning this on will
42 -# eliminate any performance gained by turning on the builtin "echo"
43 -# and "test" commands in ash.
45 -# Note that when using this option, the shell will attempt to directly
46 -# run '/bin/busybox'. If you do not have the busybox binary sitting in
47 -# that exact location with that exact name, this option will not work at
49 + depends on (MSH || LASH || HUSH || ASH) && FEATURE_APPLETS_FALLBACK
53 --- busybox.orig/shell/ash.c
54 +++ busybox/shell/ash.c
55 @@ -6629,20 +6629,6 @@
59 -#if ENABLE_FEATURE_SH_STANDALONE
60 - if (strchr(cmd, '/') == NULL) {
61 - int a = find_applet_by_name(cmd);
63 - if (APPLET_IS_NOEXEC(a))
64 - run_applet_no_and_exit(a, argv);
65 - /* re-exec ourselves with the new arguments */
66 - execve(bb_busybox_exec_path, argv, envp);
67 - /* If they called chroot or otherwise made the binary no longer
68 - * executable, fall through */
76 @@ -6687,11 +6673,7 @@
80 - if (strchr(argv[0], '/')
81 -#if ENABLE_FEATURE_SH_STANDALONE
82 - || find_applet_by_name(argv[0]) >= 0
85 + if (strchr(argv[0], '/')) {
86 tryexec(argv[0], argv, envp);
89 @@ -6706,6 +6688,11 @@
93 +#if ENABLE_FEATURE_SH_STANDALONE
95 + bb_execv_applet(argv[0], argv, envp);
98 /* Map to POSIX errors */
101 --- busybox.orig/libbb/vfork_daemon_rexec.c
102 +++ busybox/libbb/vfork_daemon_rexec.c
107 -#if ENABLE_FEATURE_PREFER_APPLETS
108 +#if ENABLE_FEATURE_APPLETS_FALLBACK
109 void save_nofork_data(struct nofork_save_area *save)
111 memcpy(&save->die_jmp, &die_jmp, sizeof(die_jmp));
113 int spawn_and_wait(char **argv)
116 -#if ENABLE_FEATURE_PREFER_APPLETS
117 +#if ENABLE_FEATURE_APPLETS_FALLBACK
118 int a = find_applet_by_name(argv[0]);
120 if (a >= 0 && (APPLET_IS_NOFORK(a)
121 --- busybox.orig/libbb/execable.c
122 +++ busybox/libbb/execable.c
130 /* check if path points to an executable file;
132 * return 0 otherwise;
137 -#if ENABLE_FEATURE_PREFER_APPLETS
138 -/* just like the real execvp, but try to launch an applet named 'file' first
139 +#if ENABLE_FEATURE_APPLETS_FALLBACK
140 +int bb_execv_applet(const char *name, char *const argv[], char *const envp[])
142 + const char **path = bb_busybox_exec_paths;
146 + if (find_applet_by_name(name) < 0)
149 + for (; *path; ++path)
150 + execve(*path, argv, envp);
155 +/* just like the real execvp, but try to launch applet if exec failes
157 int bb_execvp(const char *file, char *const argv[])
159 - return execvp(find_applet_by_name(file) >= 0 ? bb_busybox_exec_path : file,
161 + int ret = execvp(file, argv);
162 + if (errno != ENOENT)
165 + return bb_execv_applet(file, argv, environ);
168 +int bb_execlp(const char *file, const char *arg, ...)
170 +#define INITIAL_ARGV_MAX 16
171 + size_t argv_max = INITIAL_ARGV_MAX;
172 + const char **argv = malloc(argv_max * sizeof (const char *));
174 + unsigned int i = 0;
177 + va_start (args, arg);
178 + while (argv[i++] != NULL) {
179 + if (i == argv_max) {
182 + nptr = realloc (argv, argv_max * sizeof (const char *));
188 + argv[i] = va_arg (args, const char *);
192 + ret = bb_execvp(file, (char *const *)argv);
198 --- busybox.orig/libbb/error_msg_and_die.c
199 +++ busybox/libbb/error_msg_and_die.c
204 -#if ENABLE_FEATURE_PREFER_APPLETS || ENABLE_HUSH
205 +#if ENABLE_FEATURE_APPLETS_FALLBACK || ENABLE_HUSH
212 - if ((ENABLE_FEATURE_PREFER_APPLETS || ENABLE_HUSH)
213 + if ((ENABLE_FEATURE_APPLETS_FALLBACK || ENABLE_HUSH)
216 /* Special case. We arrive here if NOFORK applet
217 --- busybox.orig/libbb/fflush_stdout_and_exit.c
218 +++ busybox/libbb/fflush_stdout_and_exit.c
221 bb_perror_msg_and_die(bb_msg_standard_output);
223 - if (ENABLE_FEATURE_PREFER_APPLETS && die_sleep < 0) {
224 + if (ENABLE_FEATURE_APPLETS_FALLBACK && die_sleep < 0) {
225 /* We are in NOFORK applet. Do not exit() directly,
226 * but use xfunc_die() */
227 xfunc_error_retval = retval;
228 --- busybox.orig/libbb/messages.c
229 +++ busybox/libbb/messages.c
231 const char bb_path_gshadow_file[] ALIGN1 = "/etc/gshadow";
232 const char bb_path_motd_file[] ALIGN1 = "/etc/motd";
233 const char bb_dev_null[] ALIGN1 = "/dev/null";
234 -const char bb_busybox_exec_path[] ALIGN1 = CONFIG_BUSYBOX_EXEC_PATH;
235 +const char *bb_busybox_exec_paths[] ALIGN1 = {
239 +#ifdef CONFIG_BUSYBOX_EXEC_PATH
240 + CONFIG_BUSYBOX_EXEC_PATH,
244 const char bb_default_login_shell[] ALIGN1 = LIBBB_DEFAULT_LOGIN_SHELL;
245 /* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin,
246 * but I want to save a few bytes here. Check libbb.h before changing! */
247 --- busybox.orig/libbb/appletlib.c
248 +++ busybox/libbb/appletlib.c
251 if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) {
253 - busybox = xmalloc_readlink(bb_busybox_exec_path);
254 + busybox = xmalloc_readlink(bb_busybox_exec_paths[0]);
256 - busybox = bb_busybox_exec_path;
257 + busybox = bb_busybox_exec_paths[0];
258 /* -s makes symlinks */
259 install_links(busybox, argv[2] && strcmp(argv[2], "-s") == 0);
261 --- busybox.orig/include/libbb.h
262 +++ busybox/include/libbb.h
263 @@ -650,12 +650,12 @@
264 /* BB_EXECxx always execs (it's not doing NOFORK/NOEXEC stuff),
265 * but it may exec busybox and call applet instead of searching PATH.
267 -#if ENABLE_FEATURE_PREFER_APPLETS
268 +#if ENABLE_FEATURE_APPLETS_FALLBACK
269 +int bb_execv_applet(const char *name, char *const argv[], char *const envp[]);
270 int bb_execvp(const char *file, char *const argv[]);
271 -#define BB_EXECVP(prog,cmd) bb_execvp(prog,cmd)
272 -#define BB_EXECLP(prog,cmd,...) \
273 - execlp((find_applet_by_name(prog) >= 0) ? CONFIG_BUSYBOX_EXEC_PATH : prog, \
275 +int bb_execlp(const char *file, const char *arg, ...);
276 +#define BB_EXECVP(prog,cmd) bb_execvp(prog,cmd)
277 +#define BB_EXECLP(prog,cmd,...) bb_execlp(prog,cmd, __VA_ARGS__)
279 #define BB_EXECVP(prog,cmd) execvp(prog,cmd)
280 #define BB_EXECLP(prog,cmd,...) execlp(prog,cmd, __VA_ARGS__)
281 @@ -1211,7 +1211,7 @@
282 extern const char bb_path_motd_file[];
283 extern const char bb_path_wtmp_file[];
284 extern const char bb_dev_null[];
285 -extern const char bb_busybox_exec_path[];
286 +extern const char *bb_busybox_exec_paths[];
287 /* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin,
288 * but I want to save a few bytes here */
289 extern const char bb_PATH_root_path[]; /* "PATH=/sbin:/usr/sbin:/bin:/usr/bin" */
290 --- busybox.orig/include/busybox.h
291 +++ busybox/include/busybox.h
293 extern const uint16_t applet_nameofs[];
294 extern const uint8_t applet_install_loc[];
296 -#if ENABLE_FEATURE_SUID || ENABLE_FEATURE_PREFER_APPLETS
297 +#if ENABLE_FEATURE_SUID || ENABLE_FEATURE_APPLETS_FALLBACK
298 #define APPLET_NAME(i) (applet_names + (applet_nameofs[i] & 0x0fff))
300 #define APPLET_NAME(i) (applet_names + applet_nameofs[i])
303 -#if ENABLE_FEATURE_PREFER_APPLETS
304 +#if ENABLE_FEATURE_APPLETS_FALLBACK
305 #define APPLET_IS_NOFORK(i) (applet_nameofs[i] & (1 << 12))
306 #define APPLET_IS_NOEXEC(i) (applet_nameofs[i] & (1 << 13))
308 --- busybox.orig/applets/applet_tables.c
309 +++ busybox/applets/applet_tables.c
311 for (i = 0; i < NUM_APPLETS; i++) {
314 -#if ENABLE_FEATURE_PREFER_APPLETS
315 +#if ENABLE_FEATURE_APPLETS_FALLBACK
316 + (applets[i].nofork << 12)
317 + (applets[i].noexec << 13)
319 --- busybox.orig/Config.in
320 +++ busybox/Config.in
321 @@ -222,29 +222,16 @@
323 Most people will leave this set to 'N'.
325 -config FEATURE_PREFER_APPLETS
326 - bool "exec prefers applets"
327 +config FEATURE_APPLETS_FALLBACK
328 + bool "exec uses applets as fallback"
331 - This is an experimental option which directs applets about to
332 - call 'exec' to try and find an applicable busybox applet before
333 - searching the PATH. This is typically done by exec'ing
335 - This may affect shell, find -exec, xargs and similar applets.
336 - They will use applets even if /bin/<applet> -> busybox link
337 - is missing (or is not a link to busybox). However, this causes
338 - problems in chroot jails without mounted /proc and with ps/top
339 - (command name can be shown as 'exe' for applets started this way).
341 config BUSYBOX_EXEC_PATH
342 string "Path to BusyBox executable"
343 - default "/proc/self/exe"
344 + default "/bin/busybox"
346 When Busybox applets need to run other busybox applets, BusyBox
347 - sometimes needs to exec() itself. When the /proc filesystem is
348 - mounted, /proc/self/exe always points to the currently running
349 - executable. If you haven't got /proc, set this to wherever you
350 - want to run BusyBox from.
351 + sometimes needs to exec() itself.
353 # These are auto-selected by other options
356 config BUILD_LIBBUSYBOX
357 bool "Build shared libbusybox"
359 - depends on !FEATURE_PREFER_APPLETS
360 + depends on !FEATURE_APPLETS_FALLBACK
362 Build a shared library libbusybox.so.N.N.N which contains all
366 config INSTALL_APPLET_DONT
368 - depends on FEATURE_INSTALLER || FEATURE_SH_STANDALONE || FEATURE_PREFER_APPLETS
369 + depends on FEATURE_INSTALLER || FEATURE_SH_STANDALONE || FEATURE_APPLETS_FALLBACK
371 Do not install applet links. Useful when using the -install feature
372 or a standalone shell for rescue purposes.