diff options
author | Zbigniew Jędrzejewski-Szmek | 2013-02-14 03:05:48 +0100 |
---|---|---|
committer | Karel Zak | 2013-02-14 14:42:35 +0100 |
commit | 57580694269be36cc52138b0f82e72f09338e192 (patch) | |
tree | 1b4f0a31421327529afc83c9d2b16750f465fe49 /lib | |
parent | libblkid: read whole buffer for iso_volume_descriptor (diff) | |
download | kernel-qcow2-util-linux-57580694269be36cc52138b0f82e72f09338e192.tar.gz kernel-qcow2-util-linux-57580694269be36cc52138b0f82e72f09338e192.tar.xz kernel-qcow2-util-linux-57580694269be36cc52138b0f82e72f09338e192.zip |
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 <zbyszek@in.waw.pl>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makemodule.am | 3 | ||||
-rw-r--r-- | lib/exec_shell.c | 27 |
2 files changed, 29 insertions, 1 deletions
diff --git a/lib/Makemodule.am b/lib/Makemodule.am index 81e20b106..74b6bc1fa 100644 --- a/lib/Makemodule.am +++ b/lib/Makemodule.am @@ -24,7 +24,8 @@ libcommon_la_SOURCES = \ lib/tt.c \ lib/wholedisk.c \ lib/ttyutils.c \ - lib/xgetpass.c + lib/xgetpass.c \ + lib/exec_shell.c if LINUX libcommon_la_SOURCES += \ 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 <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/types.h> + +#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); +} |