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-w32-8220399173cf8d25e37059cadac96ac30f94e82a.tar.gz
busybox-w32-8220399173cf8d25e37059cadac96ac30f94e82a.tar.bz2
busybox-w32-8220399173cf8d25e37059cadac96ac30f94e82a.zip
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)
230 ns->ns_nsfile8 + 3 /* skip over "ns/" */ 230 ns->ns_nsfile8 + 3 /* skip over "ns/" */
231 ); 231 );
232 } 232 }
233 /*close(ns_ctx->fd);*/ 233 close(ns_ctx->fd); /* should close fds, to not confuse exec'ed PROG */
234 /*ns_ctx->fd = -1;*/ 234 /*ns_ctx->fd = -1;*/
235 } 235 }
236 236
@@ -244,13 +244,13 @@ int nsenter_main(int argc UNUSED_PARAM, char **argv)
244 } 244 }
245 xfchdir(root_fd); 245 xfchdir(root_fd);
246 xchroot("."); 246 xchroot(".");
247 /*close(root_fd);*/ 247 close(root_fd);
248 /*root_fd = -1;*/ 248 /*root_fd = -1;*/
249 } 249 }
250 250
251 if (wd_fd >= 0) { 251 if (wd_fd >= 0) {
252 xfchdir(wd_fd); 252 xfchdir(wd_fd);
253 /*close(wd_fd);*/ 253 close(wd_fd);
254 /*wd_fd = -1;*/ 254 /*wd_fd = -1;*/
255 } 255 }
256 256
@@ -259,14 +259,7 @@ int nsenter_main(int argc UNUSED_PARAM, char **argv)
259 * explicitly requested by the user not to. 259 * explicitly requested by the user not to.
260 */ 260 */
261 if (!(opts & OPT_nofork) && (opts & OPT_pid)) { 261 if (!(opts & OPT_nofork) && (opts & OPT_pid)) {
262 pid_t pid = xvfork(); 262 xvfork_parent_waits_and_exits();
263 if (pid > 0) {
264 /* Parent */
265 int exit_status = wait_for_exitstatus(pid);
266 if (WIFSIGNALED(exit_status))
267 kill_myself_with_sig(WTERMSIG(exit_status));
268 return WEXITSTATUS(exit_status);
269 }
270 /* Child continues */ 263 /* Child continues */
271 } 264 }
272 265
@@ -278,9 +271,5 @@ int nsenter_main(int argc UNUSED_PARAM, char **argv)
278 if (opts & OPT_setuid) 271 if (opts & OPT_setuid)
279 xsetuid(uid); 272 xsetuid(uid);
280 273
281 if (*argv) { 274 exec_prog_or_SHELL(argv);
282 BB_EXECVP_or_die(argv);
283 }
284
285 run_shell(getenv("SHELL"), /*login:*/ 1, NULL, NULL);
286} 275}