diff options
author | Ladislav Michl <Ladislav.Michl@seznam.cz> | 2010-06-27 03:23:31 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-06-27 03:23:31 +0200 |
commit | a73b87e9343df2a6f14e328a977e7b70eb3ed707 (patch) | |
tree | 564869bde93c870b20f6d4d8a3da71e42b629f2e /libbb | |
parent | 1b14cdb27ca5e8104a824424731be430c8592dd6 (diff) | |
download | busybox-w32-a73b87e9343df2a6f14e328a977e7b70eb3ed707.tar.gz busybox-w32-a73b87e9343df2a6f14e328a977e7b70eb3ed707.tar.bz2 busybox-w32-a73b87e9343df2a6f14e328a977e7b70eb3ed707.zip |
*: 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.c | 18 | ||||
-rw-r--r-- | libbb/setup_environment.c | 4 |
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) | |||
49 | 49 | ||
50 | #endif | 50 | #endif |
51 | 51 | ||
52 | /* Run SHELL, or DEFAULT_SHELL if SHELL is empty. | 52 | /* Run SHELL, or DEFAULT_SHELL if SHELL is "" or NULL. |
53 | If COMMAND is nonzero, pass it to the shell with the -c option. | 53 | * If COMMAND is nonzero, pass it to the shell with the -c option. |
54 | If ADDITIONAL_ARGS is nonzero, pass it to the shell as more | 54 | * If ADDITIONAL_ARGS is nonzero, pass it to the shell as more |
55 | arguments. */ | 55 | * arguments. */ |
56 | |||
57 | void FAST_FUNC run_shell(const char *shell, int loginshell, const char *command, const char **additional_args) | 56 | void FAST_FUNC run_shell(const char *shell, int loginshell, const char *command, const char **additional_args) |
58 | { | 57 | { |
59 | const char **args; | 58 | const char **args; |
60 | int argno = 1; | 59 | int argno; |
61 | int additional_args_cnt = 0; | 60 | int additional_args_cnt = 0; |
62 | 61 | ||
63 | for (args = additional_args; args && *args; args++) | 62 | for (args = additional_args; args && *args; args++) |
@@ -65,11 +64,13 @@ void FAST_FUNC run_shell(const char *shell, int loginshell, const char *command, | |||
65 | 64 | ||
66 | args = xmalloc(sizeof(char*) * (4 + additional_args_cnt)); | 65 | args = xmalloc(sizeof(char*) * (4 + additional_args_cnt)); |
67 | 66 | ||
68 | args[0] = bb_get_last_path_component_nostrip(xstrdup(shell)); | 67 | if (!shell || !shell[0]) |
68 | shell = DEFAULT_SHELL; | ||
69 | 69 | ||
70 | args[0] = bb_get_last_path_component_nostrip(shell); | ||
70 | if (loginshell) | 71 | if (loginshell) |
71 | args[0] = xasprintf("-%s", args[0]); | 72 | args[0] = xasprintf("-%s", args[0]); |
72 | 73 | argno = 1; | |
73 | if (command) { | 74 | if (command) { |
74 | args[argno++] = "-c"; | 75 | args[argno++] = "-c"; |
75 | args[argno++] = command; | 76 | args[argno++] = command; |
@@ -79,6 +80,7 @@ void FAST_FUNC run_shell(const char *shell, int loginshell, const char *command, | |||
79 | args[argno++] = *additional_args; | 80 | args[argno++] = *additional_args; |
80 | } | 81 | } |
81 | args[argno] = NULL; | 82 | args[argno] = NULL; |
83 | |||
82 | #if ENABLE_SELINUX | 84 | #if ENABLE_SELINUX |
83 | if (current_sid) | 85 | if (current_sid) |
84 | setexeccon(current_sid); | 86 | 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 | |||
43 | const char *term; | 43 | const char *term; |
44 | 44 | ||
45 | /* Leave TERM unchanged. Set HOME, SHELL, USER, LOGNAME, PATH. | 45 | /* Leave TERM unchanged. Set HOME, SHELL, USER, LOGNAME, PATH. |
46 | Unset all other environment variables. */ | 46 | * Unset all other environment variables. */ |
47 | term = getenv("TERM"); | 47 | term = getenv("TERM"); |
48 | clearenv(); | 48 | clearenv(); |
49 | if (term) | 49 | if (term) |
@@ -57,7 +57,7 @@ void FAST_FUNC setup_environment(const char *shell, int flags, const struct pass | |||
57 | //xsetenv("SHELL", shell); | 57 | //xsetenv("SHELL", shell); |
58 | } else if (flags & SETUP_ENV_CHANGEENV) { | 58 | } else if (flags & SETUP_ENV_CHANGEENV) { |
59 | /* Set HOME, SHELL, and if not becoming a super-user, | 59 | /* Set HOME, SHELL, and if not becoming a super-user, |
60 | USER and LOGNAME. */ | 60 | * USER and LOGNAME. */ |
61 | if (pw->pw_uid) { | 61 | if (pw->pw_uid) { |
62 | shortcut: | 62 | shortcut: |
63 | xsetenv("USER", pw->pw_name); | 63 | xsetenv("USER", pw->pw_name); |