diff options
Diffstat (limited to 'toys/other')
-rw-r--r-- | toys/other/login.c | 8 | ||||
-rw-r--r-- | toys/other/nbd_client.c | 1 | ||||
-rw-r--r-- | toys/other/netcat.c | 23 | ||||
-rw-r--r-- | toys/other/nsenter.c | 13 | ||||
-rw-r--r-- | toys/other/setsid.c | 2 | ||||
-rw-r--r-- | toys/other/timeout.c | 8 |
6 files changed, 30 insertions, 25 deletions
diff --git a/toys/other/login.c b/toys/other/login.c index c727bf96..7f9559aa 100644 --- a/toys/other/login.c +++ b/toys/other/login.c @@ -159,9 +159,7 @@ void login_main(void) syslog(LOG_INFO, "%s logged in on %s %s %s", pwd->pw_name, ttyname(tty), hh ? "from" : "", hh ? TT.hostname : ""); - // can't xexec here because name doesn't match argv[0] - snprintf(toybuf, sizeof(toybuf)-1, "-%s", basename_r(pwd->pw_shell)); - toy_exec((char *[]){toybuf, 0}); - execl(pwd->pw_shell, toybuf, NULL); - error_exit("Failed to spawn shell"); + // not using xexec(), login calls absolute path from filesystem so must exec() + execl(pwd->pw_shell, xmprintf("-%s", pwd->pw_shell), (char *)0); + perror_exit("exec shell '%s'", pwd->pw_shell); } diff --git a/toys/other/nbd_client.c b/toys/other/nbd_client.c index a82ff7c8..3ad366f3 100644 --- a/toys/other/nbd_client.c +++ b/toys/other/nbd_client.c @@ -12,6 +12,7 @@ USE_NBD_CLIENT(OLDTOY(nbd-client, nbd_client, TOYFLAG_USR|TOYFLAG_BIN)) config NBD_CLIENT bool "nbd-client" + depends on TOYBOX_FORK default y help usage: nbd-client [-ns] HOST PORT DEVICE diff --git a/toys/other/netcat.c b/toys/other/netcat.c index 3cc3f0a0..1c75eb26 100644 --- a/toys/other/netcat.c +++ b/toys/other/netcat.c @@ -26,10 +26,10 @@ config NETCAT_LISTEN bool "netcat server options (-let)" default y depends on NETCAT + depends on TOYBOX_FORK help - usage: netcat [-t] [-lL COMMAND...] + usage: netcat [-lL COMMAND...] - -t allocate tty (must come before -l or -L) -l listen for one incoming connection. -L listen for multiple incoming connections (server mode). @@ -38,6 +38,16 @@ config NETCAT_LISTEN For a quick-and-dirty server, try something like: netcat -s 127.0.0.1 -p 1234 -tL /bin/bash -l + +config NETCAT_LISTEN_TTY + bool + default y + depends on NETCAT_LISTEN + depends on TOYBOX_FORK + help + usage: netcat [-t] + + -t allocate tty (must come before -l or -L) */ #define FOR_netcat @@ -139,7 +149,7 @@ void netcat_main(void) // Do we need to return immediately because -l has arguments? if ((toys.optflags & FLAG_l) && toys.optc) { - if (xfork()) goto cleanup; + if (CFG_TOYBOX_FORK && xfork()) goto cleanup; close(0); close(1); close(2); @@ -161,7 +171,10 @@ void netcat_main(void) // Do we need to fork and/or redirect for exec? else { - if (toys.optflags&FLAG_L) child = fork(); + if (toys.optflags&FLAG_L) { + toys.stacktop = 0; + child = vfork(); + } if (!child && toys.optc) { int fd = pollfds[0].fd; @@ -183,7 +196,7 @@ void netcat_main(void) // (Does not play well with -L, but what _should_ that do?) set_alarm(0); - if (CFG_NETCAT_LISTEN && (toys.optflags&(FLAG_L|FLAG_l) && toys.optc)) + if (CFG_NETCAT_LISTEN && ((toys.optflags&(FLAG_L|FLAG_l)) && toys.optc)) xexec(toys.optargs); // Poll loop copying stdin->socket and socket->stdout. diff --git a/toys/other/nsenter.c b/toys/other/nsenter.c index 18a2cd21..bda77ac1 100644 --- a/toys/other/nsenter.c +++ b/toys/other/nsenter.c @@ -1,14 +1,14 @@ /* nsenter.c - Enter existing namespaces * - * Copyright 2014 andy Lutomirski <luto@amacapital.net> + * Copyright 2014 Andy Lutomirski <luto@amacapital.net> * - * No standard + * See http://man7.org/linux/man-pages/man1/nsenter.1.html * * unshare.c - run command in new context * * Copyright 2011 Rob Landley <rob@landley.net> * - * No Standard + * See http://man7.org/linux/man-pages/man1/unshare.1.html * // Note: flags go in same order (right to left) for shared subset @@ -149,12 +149,9 @@ void unshare_main(void) } if ((toys.optflags & FLAG_p) && !(toys.optflags & FLAG_F)) { - pid_t pid = xfork(); + toys.exitval = xrun(toys.optargs); - if (pid) { - while (waitpid(pid, 0, 0) == -1 && errno == EINTR); - return; - } + return; } } diff --git a/toys/other/setsid.c b/toys/other/setsid.c index 83db044d..95698260 100644 --- a/toys/other/setsid.c +++ b/toys/other/setsid.c @@ -19,7 +19,7 @@ config SETSID void setsid_main(void) { - while (setsid()<0) if (xvfork()) _exit(0); + while (setsid()<0) if (XVFORK()) _exit(0); if (toys.optflags) { setpgid(0, 0); tcsetpgrp(0, getpid()); diff --git a/toys/other/timeout.c b/toys/other/timeout.c index bd716e63..0e912f7c 100644 --- a/toys/other/timeout.c +++ b/toys/other/timeout.c @@ -62,14 +62,10 @@ void timeout_main(void) if (TT.s_signal && -1 == (TT.nextsig = sig_to_num(TT.s_signal))) error_exit("bad -s: '%s'", TT.s_signal); - if (!(TT.pid = xvfork())) xexec(toys.optargs+1); + if (!(TT.pid = XVFORK())) xexec(toys.optargs+1); else { - int status; - xsignal(SIGALRM, handler); setitimer(ITIMER_REAL, &TT.itv, (void *)toybuf); - while (-1 == waitpid(TT.pid, &status, 0) && errno == EINTR); - toys.exitval = WIFEXITED(status) - ? WEXITSTATUS(status) : WTERMSIG(status) + 127; + toys.exitval = xwaitpid(TT.pid); } } |