From 57580694269be36cc52138b0f82e72f09338e192 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Wed, 13 Feb 2013 21:05:48 -0500 Subject: unshare,nsenter: spawn shell by default The behaviour mimics chroot. Possibly it would have been nicer to to query the password database in the new namepace and run the shell of the user there, but it's hard to do correctly. getpwuid() might need to load nss plugins, and the arch in the new namespace might be different (in case of NEWNS mounts), or the hostname might be different, etc. So in general it's not possible to do it reliably. Signed-off-by: Zbigniew Jędrzejewski-Szmek --- lib/exec_shell.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 lib/exec_shell.c (limited to 'lib/exec_shell.c') diff --git a/lib/exec_shell.c b/lib/exec_shell.c new file mode 100644 index 000000000..95620cd4d --- /dev/null +++ b/lib/exec_shell.c @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +#include "nls.h" +#include "c.h" +#include "xalloc.h" + +#include "exec_shell.h" + +#define DEFAULT_SHELL "/bin/sh" + +void __attribute__((__noreturn__)) exec_shell(void) { + const char *shell = getenv("SHELL"), *shell_basename; + char *arg0; + if (!shell) + shell = DEFAULT_SHELL; + + shell_basename = basename(shell); + arg0 = xmalloc(strlen(shell_basename) + 2); + arg0[0] = '-'; + strcpy(arg0 + 1, shell_basename); + + execl(shell, arg0, NULL); + err(EXIT_FAILURE, _("failed to execute %s"), shell); +} -- cgit v1.2.3-55-g7522