aboutsummaryrefslogtreecommitdiff
path: root/util-linux/nsenter.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-04-02 18:06:24 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2016-04-02 18:06:24 +0200
commit8220399173cf8d25e37059cadac96ac30f94e82a (patch)
treeffe5ae4a783c8ddeceda15f57eae74ee69feebea /util-linux/nsenter.c
parentc87e81f9440278dd46a3eddd1e0f4773afd46a95 (diff)
downloadbusybox-8220399173cf8d25e37059cadac96ac30f94e82a.tar.gz
nsenter,unshare: share common code; fix a bug of not closing all fds
function old new delta xvfork_parent_waits_and_exits - 64 +64 exec_prog_or_SHELL - 39 +39 unshare_main 873 810 -63 nsenter_main 663 596 -67 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 0/2 up/down: 106/-130) Total: -27 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux/nsenter.c')
-rw-r--r--util-linux/nsenter.c21
1 files changed, 5 insertions, 16 deletions
diff --git a/util-linux/nsenter.c b/util-linux/nsenter.c
index 9c1dabaa8..0dad595cd 100644
--- a/util-linux/nsenter.c
+++ b/util-linux/nsenter.c
@@ -230,7 +230,7 @@ int nsenter_main(int argc UNUSED_PARAM, char **argv)
ns->ns_nsfile8 + 3 /* skip over "ns/" */
);
}
- /*close(ns_ctx->fd);*/
+ close(ns_ctx->fd); /* should close fds, to not confuse exec'ed PROG */
/*ns_ctx->fd = -1;*/
}
@@ -244,13 +244,13 @@ int nsenter_main(int argc UNUSED_PARAM, char **argv)
}
xfchdir(root_fd);
xchroot(".");
- /*close(root_fd);*/
+ close(root_fd);
/*root_fd = -1;*/
}
if (wd_fd >= 0) {
xfchdir(wd_fd);
- /*close(wd_fd);*/
+ close(wd_fd);
/*wd_fd = -1;*/
}
@@ -259,14 +259,7 @@ int nsenter_main(int argc UNUSED_PARAM, char **argv)
* explicitly requested by the user not to.
*/
if (!(opts & OPT_nofork) && (opts & OPT_pid)) {
- pid_t pid = xvfork();
- if (pid > 0) {
- /* Parent */
- int exit_status = wait_for_exitstatus(pid);
- if (WIFSIGNALED(exit_status))
- kill_myself_with_sig(WTERMSIG(exit_status));
- return WEXITSTATUS(exit_status);
- }
+ xvfork_parent_waits_and_exits();
/* Child continues */
}
@@ -278,9 +271,5 @@ int nsenter_main(int argc UNUSED_PARAM, char **argv)
if (opts & OPT_setuid)
xsetuid(uid);
- if (*argv) {
- BB_EXECVP_or_die(argv);
- }
-
- run_shell(getenv("SHELL"), /*login:*/ 1, NULL, NULL);
+ exec_prog_or_SHELL(argv);
}