From 0622416fece00507cf0ac53a2aa17ca3b1e565b2 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 2 Dec 2020 21:35:32 +0100 Subject: libbb: code shrink in exec_shell() function old new delta exec_shell 129 120 -9 Signed-off-by: Denys Vlasenko --- libbb/run_shell.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'libbb') diff --git a/libbb/run_shell.c b/libbb/run_shell.c index c2ff69651..9bec43b7c 100644 --- a/libbb/run_shell.c +++ b/libbb/run_shell.c @@ -59,7 +59,7 @@ void FAST_FUNC exec_shell(const char *shell, int loginshell, const char **additi while (args && *args) args++; - args = xmalloc(sizeof(char*) * (2 + (args - additional_args))); + args = xzalloc(sizeof(args[0]) * (2 + (args - additional_args))); if (!shell || !shell[0]) 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); if (loginshell) args[0] = xasprintf("-%s", args[0]); - args[1] = NULL; + /*args[1] = NULL; - already is */ if (additional_args) { - int cnt = 1; - for (;;) - if ((args[cnt++] = *additional_args++) == NULL) - break; + int cnt = 0; + while (*additional_args) + args[++cnt] = *additional_args++; } #if ENABLE_SELINUX @@ -91,5 +90,8 @@ void FAST_FUNC exec_prog_or_SHELL(char **argv) if (argv[0]) { 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); } -- cgit v1.2.3