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 --- sys-utils/nsenter.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'sys-utils/nsenter.c') diff --git a/sys-utils/nsenter.c b/sys-utils/nsenter.c index 3df433812..106349c7e 100644 --- a/sys-utils/nsenter.c +++ b/sys-utils/nsenter.c @@ -17,8 +17,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include -#include #include #include #include @@ -28,12 +26,15 @@ #include #include #include +#include +#include #include "strutils.h" #include "nls.h" #include "c.h" #include "closestream.h" #include "namespace.h" +#include "exec_shell.h" static struct namespace_file { int nstype; @@ -253,9 +254,6 @@ int main(int argc, char *argv[]) } } - if (optind >= argc) - usage(EXIT_FAILURE); - /* * Open remaining namespace and directory descriptors. */ @@ -317,7 +315,9 @@ int main(int argc, char *argv[]) if (do_fork == 1) continue_as_child(); - execvp(argv[optind], argv + optind); - - err(EXIT_FAILURE, _("failed to execute %s"), argv[optind]); + if (optind < argc) { + execvp(argv[optind], argv + optind); + err(EXIT_FAILURE, _("failed to execute %s"), argv[optind]); + } + exec_shell(); } -- cgit v1.2.3-55-g7522