summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2020-12-02 21:35:32 +0100
committerDenys Vlasenko2020-12-02 21:39:57 +0100
commit0622416fece00507cf0ac53a2aa17ca3b1e565b2 (patch)
treee211f4b8aff274bad43e8a26d07b7ccfe063b286
parent2075aa93e007863c6b680994a7a0ba420181034f (diff)
downloadbusybox-0622416fece00507cf0ac53a2aa17ca3b1e565b2.zip
busybox-0622416fece00507cf0ac53a2aa17ca3b1e565b2.tar.gz
libbb: code shrink in exec_shell()
function old new delta exec_shell 129 120 -9 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--libbb/run_shell.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/libbb/run_shell.c b/libbb/run_shell.c
index c2ff696..9bec43b 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);
}