libbb: code shrink in exec_shell()

function                                             old     new   delta
exec_shell                                           129     120      -9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2020-12-02 21:35:32 +01:00
parent 2075aa93e0
commit 0622416fec

View File

@ -59,7 +59,7 @@ void FAST_FUNC exec_shell(const char *shell, int loginshell, const char **additi
while (args && *args) while (args && *args)
args++; args++;
args = xmalloc(sizeof(char*) * (2 + (args - additional_args))); args = xzalloc(sizeof(args[0]) * (2 + (args - additional_args)));
if (!shell || !shell[0]) if (!shell || !shell[0])
shell = DEFAULT_SHELL; shell = DEFAULT_SHELL;
@ -67,12 +67,11 @@ void FAST_FUNC exec_shell(const char *shell, int loginshell, const char **additi
args[0] = bb_get_last_path_component_nostrip(shell); args[0] = bb_get_last_path_component_nostrip(shell);
if (loginshell) if (loginshell)
args[0] = xasprintf("-%s", args[0]); args[0] = xasprintf("-%s", args[0]);
args[1] = NULL; /*args[1] = NULL; - already is */
if (additional_args) { if (additional_args) {
int cnt = 1; int cnt = 0;
for (;;) while (*additional_args)
if ((args[cnt++] = *additional_args++) == NULL) args[++cnt] = *additional_args++;
break;
} }
#if ENABLE_SELINUX #if ENABLE_SELINUX
@ -91,5 +90,8 @@ void FAST_FUNC exec_prog_or_SHELL(char **argv)
if (argv[0]) { if (argv[0]) {
BB_EXECVP_or_die(argv); BB_EXECVP_or_die(argv);
} }
/* Why login=1? Both users (nsenter and unshare) do indeed exec
* a _login_ shell (with dash in argv[0])!
*/
exec_shell(getenv("SHELL"), /*login:*/ 1, NULL); exec_shell(getenv("SHELL"), /*login:*/ 1, NULL);
} }