aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
Diffstat (limited to 'toys')
-rw-r--r--toys/other/login.c8
-rw-r--r--toys/other/nbd_client.c1
-rw-r--r--toys/other/netcat.c23
-rw-r--r--toys/other/nsenter.c13
-rw-r--r--toys/other/setsid.c2
-rw-r--r--toys/other/timeout.c8
-rw-r--r--toys/pending/arping.c12
-rw-r--r--toys/posix/cpio.c11
-rw-r--r--toys/posix/time.c2
-rw-r--r--toys/posix/xargs.c4
10 files changed, 43 insertions, 41 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);
}
}
diff --git a/toys/pending/arping.c b/toys/pending/arping.c
index 3e522bdf..be43cab1 100644
--- a/toys/pending/arping.c
+++ b/toys/pending/arping.c
@@ -39,15 +39,9 @@ GLOBALS(
char *src_ip;
int sockfd;
- unsigned start;
- unsigned end;
- unsigned sent_at;
- unsigned sent_nr;
- unsigned rcvd_nr;
- unsigned brd_sent;
- unsigned rcvd_req;
- unsigned brd_rcv;
- unsigned unicast_flag;
+ unsigned long start, end;
+ unsigned sent_at, sent_nr, rcvd_nr, brd_sent, rcvd_req, brd_rcv,
+ unicast_flag;
)
struct sockaddr_ll src_pk, dst_pk;
diff --git a/toys/posix/cpio.c b/toys/posix/cpio.c
index 312bb939..a442f0d1 100644
--- a/toys/posix/cpio.c
+++ b/toys/posix/cpio.c
@@ -82,12 +82,15 @@ void cpio_main(void)
// In passthrough mode, parent stays in original dir and generates archive
// to pipe, child does chdir to new dir and reads archive from stdin (pipe).
if (TT.pass) {
- if (!(pid = xpopen(0, &pipe, 0))) {
+ if (toys.stacktop) {
+ // xpopen() doesn't return from child due to vfork(), instead restarts
+ // with !toys.stacktop
+ pid = xpopen(0, &pipe, 0);
+ afd = pipe;
+ } else {
+ // child
toys.optflags |= FLAG_i;
xchdir(TT.pass);
- } else {
- toys.optflags |= FLAG_o;
- afd = pipe;
}
}
diff --git a/toys/posix/time.c b/toys/posix/time.c
index b3cfd26b..2151826d 100644
--- a/toys/posix/time.c
+++ b/toys/posix/time.c
@@ -28,7 +28,7 @@ void time_main(void)
struct timeval tv, tv2;
gettimeofday(&tv, NULL);
- if (!(pid = xvfork())) xexec(toys.optargs);
+ if (!(pid = XVFORK())) xexec(toys.optargs);
else {
int stat;
struct rusage ru;
diff --git a/toys/posix/xargs.c b/toys/posix/xargs.c
index 50c42620..b4cb80a0 100644
--- a/toys/posix/xargs.c
+++ b/toys/posix/xargs.c
@@ -111,6 +111,7 @@ void xargs_main(void)
struct double_list *dlist = NULL, *dtemp;
int entries, bytes, done = 0, status;
char *data = NULL, **out;
+ pid_t pid;
if (!(toys.optflags & FLAG_0)) TT.delim = '\n';
@@ -168,8 +169,7 @@ void xargs_main(void)
for (dtemp = dlist; dtemp; dtemp = dtemp->next)
handle_entries(dtemp->data, out+entries);
- pid_t pid=xvfork();
- if (!pid) {
+ if (!(pid = XVFORK())) {
xclose(0);
open("/dev/null", O_RDONLY);
xexec(out);