From 57dbcf94d8178009ce1f6ebf7b5bbddfe3d26ac8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 25 Jan 2013 16:32:01 +0100 Subject: [PATCH] nsenter: respect --exec no matter where it appears MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Zbigniew Jędrzejewski-Szmek Signed-off-by: Karel Zak --- sys-utils/nsenter.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sys-utils/nsenter.c b/sys-utils/nsenter.c index 6fb428663a..926eb6227c 100644 --- a/sys-utils/nsenter.c +++ b/sys-utils/nsenter.c @@ -175,7 +175,8 @@ int main(int argc, char *argv[]) struct namespace_file *nsfile; int c, namespaces = 0; - bool do_rd = false, do_wd = false, do_fork = false; + bool do_rd = false, do_wd = false; + int do_fork = -1; /* unknown yet */ setlocale(LC_MESSAGES, ""); bindtextdomain(PACKAGE, LOCALEDIR); @@ -220,7 +221,6 @@ int main(int argc, char *argv[]) namespaces |= CLONE_NEWNET; break; case 'p': - do_fork = true; if (optarg) open_namespace_fd(CLONE_NEWPID, optarg); else @@ -233,7 +233,7 @@ int main(int argc, char *argv[]) namespaces |= CLONE_NEWUSER; break; case 'F': - do_fork = false; + do_fork = 0; break; case 'r': if (optarg) @@ -272,6 +272,8 @@ int main(int argc, char *argv[]) for (nsfile = namespace_files; nsfile->nstype; nsfile++) { if (nsfile->fd < 0) continue; + if (nsfile->nstype == CLONE_NEWPID && do_fork == -1) + do_fork = 1; if (setns(nsfile->fd, nsfile->nstype)) err(EXIT_FAILURE, _("reassociate to namespace '%s' failed"), @@ -311,7 +313,7 @@ int main(int argc, char *argv[]) wd_fd = -1; } - if (do_fork) + if (do_fork == 1) continue_as_child(); execvp(argv[optind], argv + optind); -- 2.47.2