aboutsummaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/nsenter.c21
-rw-r--r--util-linux/unshare.c19
2 files changed, 8 insertions, 32 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);
}
diff --git a/util-linux/unshare.c b/util-linux/unshare.c
index 2a5bea5a6..95a7cb647 100644
--- a/util-linux/unshare.c
+++ b/util-linux/unshare.c
@@ -281,7 +281,7 @@ int unshare_main(int argc UNUSED_PARAM, char **argv)
if (fdp.wr >= 0) {
close(fdp.wr); /* Release child */
- /*close(fdp.rd);*/
+ close(fdp.rd); /* should close fd, to not confuse exec'ed PROG */
}
if (need_mount) {
@@ -307,14 +307,7 @@ int unshare_main(int argc UNUSED_PARAM, char **argv)
* that'll become PID 1 in this new namespace.
*/
if (opts & OPT_fork) {
- pid_t pid = xfork();
- 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 */
}
@@ -354,11 +347,5 @@ int unshare_main(int argc UNUSED_PARAM, char **argv)
mount_or_die("proc", proc_mnt_target, "proc", MS_NOSUID | MS_NOEXEC | MS_NODEV);
}
- if (argv[0]) {
- BB_EXECVP_or_die(argv);
- }
- /* unshare from util-linux 2.27.1, despite not documenting it,
- * runs a login shell (argv0="-sh") if no PROG is given
- */
- run_shell(getenv("SHELL"), /*login:*/ 1, NULL, NULL);
+ exec_prog_or_SHELL(argv);
}