[PATCH v8 14/14] libbb: implement re_exec using bb_execv
Nadav Tasher
tashernadav at gmail.com
Sun Mar 9 23:55:36 UTC 2025
By using bb_execv, an applet can be executed with NOEXEC
instead of actually re-executing the binary, which might
not work in scenareos where busybox is embedded into
another binary.
Signed-off-by: Nadav Tasher <tashernadav at gmail.com>
---
libbb/vfork_daemon_rexec.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index eff1bfd6d..387c9324e 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -286,11 +286,16 @@ int FAST_FUNC bb_system(const char *command) {
#if !BB_MMU
void FAST_FUNC re_exec(char **argv)
{
+ /* create a copy of argv[0], we'll use it for exec */
+ char *name = xstrdup(argv[0]);
+
/* high-order bit of first char in argv[0] is a hidden
* "we have (already) re-execed, don't do it again" flag */
argv[0][0] |= 0x80;
- execv(bb_busybox_exec_path, argv);
- bb_perror_msg_and_die("can't execute '%s'", bb_busybox_exec_path);
+
+ /* if required, bb_execvp with re-exec bb_busybox_exec_path */
+ bb_execv(name, argv);
+ bb_perror_msg_and_die("can't execute '%s'", name);
}
pid_t FAST_FUNC fork_or_rexec(char **argv)
--
2.43.0
More information about the busybox
mailing list