aboutsummaryrefslogtreecommitdiff
path: root/libbb/run_shell.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/run_shell.c')
-rw-r--r--libbb/run_shell.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/libbb/run_shell.c b/libbb/run_shell.c
index 4d92c3caa..b6b9360e8 100644
--- a/libbb/run_shell.c
+++ b/libbb/run_shell.c
@@ -50,19 +50,17 @@ void FAST_FUNC set_current_security_context(security_context_t sid)
#endif
/* Run SHELL, or DEFAULT_SHELL if SHELL is "" or NULL.
- * If COMMAND is nonzero, pass it to the shell with the -c option.
- * If ADDITIONAL_ARGS is nonzero, pass it to the shell as more
- * arguments. */
-void FAST_FUNC run_shell(const char *shell, int loginshell, const char *command, const char **additional_args)
+ * If ADDITIONAL_ARGS is not NULL, pass them to the shell.
+ */
+void FAST_FUNC run_shell(const char *shell, int loginshell, const char **additional_args)
{
const char **args;
- int argno;
- int additional_args_cnt = 0;
- for (args = additional_args; args && *args; args++)
- additional_args_cnt++;
+ args = additional_args;
+ while (args && *args)
+ args++;
- args = xmalloc(sizeof(char*) * (4 + additional_args_cnt));
+ args = xmalloc(sizeof(char*) * (2 + (args - additional_args)));
if (!shell || !shell[0])
shell = DEFAULT_SHELL;
@@ -70,16 +68,13 @@ void FAST_FUNC run_shell(const char *shell, int loginshell, const char *command,
args[0] = bb_get_last_path_component_nostrip(shell);
if (loginshell)
args[0] = xasprintf("-%s", args[0]);
- argno = 1;
- if (command) {
- args[argno++] = "-c";
- args[argno++] = command;
- }
+ args[1] = NULL;
if (additional_args) {
- for (; *additional_args; ++additional_args)
- args[argno++] = *additional_args;
+ int cnt = 1;
+ for (;;)
+ if ((args[cnt++] = *additional_args++) == NULL)
+ break;
}
- args[argno] = NULL;
#if ENABLE_SELINUX
if (current_sid)