aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorLadislav Michl <Ladislav.Michl@seznam.cz>2010-06-27 03:23:31 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-06-27 03:23:31 +0200
commita73b87e9343df2a6f14e328a977e7b70eb3ed707 (patch)
tree564869bde93c870b20f6d4d8a3da71e42b629f2e /libbb
parent1b14cdb27ca5e8104a824424731be430c8592dd6 (diff)
downloadbusybox-a73b87e9343df2a6f14e328a977e7b70eb3ed707.tar.gz
*: s/"/bin/sh"/DEFAULT_SHELL, run_shell() API fix, remove unneeded strdup
function old new delta run_shell 157 166 +9 su_main 477 470 -7 sulogin_main 515 503 -12 Signed-off-by: Ladislav Michl <Ladislav.Michl@seznam.cz> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/run_shell.c18
-rw-r--r--libbb/setup_environment.c4
2 files changed, 12 insertions, 10 deletions
diff --git a/libbb/run_shell.c b/libbb/run_shell.c
index 4608a24a9..4d92c3caa 100644
--- a/libbb/run_shell.c
+++ b/libbb/run_shell.c
@@ -49,15 +49,14 @@ void FAST_FUNC set_current_security_context(security_context_t 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. */
-
+/* 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++)
@@ -65,11 +64,13 @@ void FAST_FUNC run_shell(const char *shell, int loginshell, const char *command,
args = xmalloc(sizeof(char*) * (4 + additional_args_cnt));
- args[0] = bb_get_last_path_component_nostrip(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;
@@ -79,6 +80,7 @@ void FAST_FUNC run_shell(const char *shell, int loginshell, const char *command,
args[argno++] = *additional_args;
}
args[argno] = NULL;
+
#if ENABLE_SELINUX
if (current_sid)
setexeccon(current_sid);
diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c
index 13e60d8e4..a95fbc5bf 100644
--- a/libbb/setup_environment.c
+++ b/libbb/setup_environment.c
@@ -43,7 +43,7 @@ void FAST_FUNC setup_environment(const char *shell, int flags, const struct pass
const char *term;
/* Leave TERM unchanged. Set HOME, SHELL, USER, LOGNAME, PATH.
- Unset all other environment variables. */
+ * Unset all other environment variables. */
term = getenv("TERM");
clearenv();
if (term)
@@ -57,7 +57,7 @@ void FAST_FUNC setup_environment(const char *shell, int flags, const struct pass
//xsetenv("SHELL", shell);
} else if (flags & SETUP_ENV_CHANGEENV) {
/* Set HOME, SHELL, and if not becoming a super-user,
- USER and LOGNAME. */
+ * USER and LOGNAME. */
if (pw->pw_uid) {
shortcut:
xsetenv("USER", pw->pw_name);