[PATCH v3 19/27] vfork_daemon_rexec: implement bb_system using spawn_and_wait
Nadav Tasher
tashernadav at gmail.com
Mon Jan 27 00:04:30 UTC 2025
Implemented bb_system using spawn_and_wait in conjuction with "sh",
to allow bb_system to execute the internal shell when using the
FEATURE_PREFER_APPLETS config option.
When FEATURE_PREFER_APPLETS is disabled, libc "system()" is used.
Signed-off-by: Nadav Tasher <tashernadav at gmail.com>
---
include/libbb.h | 1 +
libbb/vfork_daemon_rexec.c | 12 ++++++++++++
2 files changed, 13 insertions(+)
diff --git a/include/libbb.h b/include/libbb.h
index bb9261626..4e1cc3d73 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1277,6 +1277,7 @@ int wait_for_exitstatus(pid_t pid) FAST_FUNC;
/************************************************************************/
/* Same as wait4pid(spawn(argv)), but with NOFORK/NOEXEC if configured: */
int spawn_and_wait(char **argv) FAST_FUNC;
+int bb_system(const char *command) FAST_FUNC;
/* Does NOT check that applet is NOFORK, just blindly runs it */
int run_nofork_applet(int applet_no, char **argv) FAST_FUNC;
void run_noexec_applet_and_exit(int a, const char *name, char **argv) NORETURN FAST_FUNC;
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index 43f09f2f1..5dd92abe9 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -249,6 +249,18 @@ int FAST_FUNC spawn_and_wait(char **argv)
return wait4pid(rc);
}
+int FAST_FUNC bb_system(const char *command) {
+#if ENABLE_FEATURE_PREFER_APPLETS
+ /* we use sh because it might launch ash */
+ const char* system_argv[] = {"sh", "-c", command, NULL};
+
+ /* just use spawn and wait - returns the exit code */
+ return spawn_and_wait((char**) system_argv);
+#else
+ return system(command);
+#endif
+}
+
#if !BB_MMU
void FAST_FUNC re_exec(char **argv)
{
--
2.43.0
More information about the busybox
mailing list