[PATCH v10 10/15] hush: use bb_execvp to execute commands and applets in execvp_or_die
Nadav Tasher
tashernadav at gmail.com
Thu Apr 17 20:01:13 UTC 2025
This commit replaces direct execXX calls with bb_execXX proxy calls,
allowing for direct applet execution using libbb.
This commit also removes some applet handling code from the
pseudo_exec_argv function, as bb_execXX already handles direct applet
executions.
Signed-off-by: Nadav Tasher <tashernadav at gmail.com>
---
shell/hush.c | 44 ++++----------------------------------------
1 file changed, 4 insertions(+), 40 deletions(-)
diff --git a/shell/hush.c b/shell/hush.c
index 4a97293cc..0044fad45 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -7552,10 +7552,10 @@ static void re_execute_shell(char ***to_free, const char *s,
/* Don't propagate SIG_IGN to the child */
if (SPECIAL_JOBSTOP_SIGS != 0)
switch_off_special_sigs(G.special_sig_mask & SPECIAL_JOBSTOP_SIGS);
- execve(bb_busybox_exec_path, argv, pp);
+ bb_execve("hush", argv, pp);
/* Fallback. Useful for init=/bin/hush usage etc */
if (argv[0][0] == '/')
- execve(argv[0], argv, pp);
+ bb_execve(argv[0], argv, pp);
xfunc_error_retval = 127;
bb_simple_error_msg_and_die("can't re-execute the shell");
}
@@ -8574,7 +8574,7 @@ static void execvp_or_die(char **argv)
/* Don't propagate SIG_IGN to the child */
if (SPECIAL_JOBSTOP_SIGS != 0)
switch_off_special_sigs(G.special_sig_mask & SPECIAL_JOBSTOP_SIGS);
- execvp(argv[0], argv);
+ bb_execvp(argv[0], argv);
e = 2;
if (errno == EACCES) e = 126;
if (errno == ENOENT) e = 127;
@@ -8799,43 +8799,7 @@ static NOINLINE void pseudo_exec_argv(nommu_save_t *nommu_save,
exec_builtin(&nommu_save->argv_from_re_execing, x, argv);
}
-#if ENABLE_FEATURE_SH_STANDALONE
- /* Check if the command matches any busybox applets */
- {
- int a = find_applet_by_name(argv[0]);
- if (a >= 0) {
- if_command_vV_print_and_exit(opt_vV, argv[0], "an applet");
-# if BB_MMU /* see above why on NOMMU it is not allowed */
- if (APPLET_IS_NOEXEC(a)) {
- /* Do not leak open fds from opened script files etc.
- * Testcase: interactive "ls -l /proc/self/fd"
- * should not show tty fd open.
- */
- close_saved_fds_and_FILE_fds();
-//FIXME: should also close saved redir fds
-//This casuses test failures in
-//redir_children_should_not_see_saved_fd_2.tests
-//redir_children_should_not_see_saved_fd_3.tests
-//if you replace "busybox find" with just "find" in them
- /* Without this, "rm -i FILE" can't be ^C'ed: */
- switch_off_special_sigs(G.special_sig_mask);
- debug_printf_exec("running applet '%s'\n", argv[0]);
- run_noexec_applet_and_exit(a, argv[0], argv);
- }
-# endif
- /* Re-exec ourselves */
- debug_printf_exec("re-execing applet '%s'\n", argv[0]);
- /* Don't propagate SIG_IGN to the child */
- if (SPECIAL_JOBSTOP_SIGS != 0)
- switch_off_special_sigs(G.special_sig_mask & SPECIAL_JOBSTOP_SIGS);
- execv(bb_busybox_exec_path, argv);
- /* If they called chroot or otherwise made the binary no longer
- * executable, fall through */
- }
- }
-#endif
-
-#if ENABLE_FEATURE_SH_STANDALONE || BB_MMU
+#if BB_MMU
skip:
#endif
if_command_vV_print_and_exit(opt_vV, argv[0], NULL);
--
2.34.1
More information about the busybox
mailing list