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 <[email protected]> --- 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 39ca6d811..e04321dc8 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1280,6 +1280,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 _______________________________________________ busybox mailing list [email protected] https://lists.busybox.net/mailman/listinfo/busybox
