]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
nsenter: respect --exec no matter where it appears
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 25 Jan 2013 15:32:01 +0000 (16:32 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 25 Jan 2013 15:32:01 +0000 (16:32 +0100)
Signed-off-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/nsenter.c

index 6fb428663a537dcce06e2710eb4fd48bbdcdbe67..926eb6227c0ad1e6521df4cafc8f18e0020a4465 100644 (file)
@@ -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);