X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=libbb%2Frun_shell.c;h=4d92c3caa10266dd6e9bba46cf27aad7f014e1a3;hb=4c46d854690595bb2c5487aedccebab8de8aafda;hp=25d55dd63b407a6cc171b5e0b49e03bbb179854b;hpb=fad2b86c9e7eaadb973b50a1bc0e2accc1a96cfd;p=oweals%2Fbusybox.git diff --git a/libbb/run_shell.c b/libbb/run_shell.c index 25d55dd63..4d92c3caa 100644 --- a/libbb/run_shell.c +++ b/libbb/run_shell.c @@ -36,32 +36,27 @@ #if ENABLE_SELINUX static security_context_t current_sid; -void -renew_current_security_context(void) +void FAST_FUNC renew_current_security_context(void) { - if (current_sid) - freecon(current_sid); /* Release old context */ + freecon(current_sid); /* Release old context */ getcon(¤t_sid); /* update */ } -void -set_current_security_context(security_context_t sid) +void FAST_FUNC set_current_security_context(security_context_t sid) { - if (current_sid) - freecon(current_sid); /* Release old context */ + freecon(current_sid); /* Release old context */ current_sid = sid; } #endif -/* Run SHELL, or DEFAULT_SHELL if SHELL is empty. - 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 run_shell(const char *shell, int loginshell, const char *command, const char **additional_args) +/* 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) { const char **args; - int argno = 1; + int argno; int additional_args_cnt = 0; for (args = additional_args; args && *args; args++) @@ -69,11 +64,13 @@ void run_shell(const char *shell, int loginshell, const char *command, const cha args = xmalloc(sizeof(char*) * (4 + additional_args_cnt)); - args[0] = bb_get_last_path_component(xstrdup(shell)); + if (!shell || !shell[0]) + shell = DEFAULT_SHELL; + 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; @@ -83,12 +80,13 @@ void run_shell(const char *shell, int loginshell, const char *command, const cha args[argno++] = *additional_args; } args[argno] = NULL; + #if ENABLE_SELINUX - if (current_sid && !setexeccon(current_sid)) { + if (current_sid) + setexeccon(current_sid); + if (ENABLE_FEATURE_CLEAN_UP) freecon(current_sid); - execve(shell, (char **) args, environ); - } else #endif execv(shell, (char **) args); - bb_perror_msg_and_die("cannot run %s", shell); + bb_perror_msg_and_die("can't execute '%s'", shell); }