diff options
author | Rob Landley <rob@landley.net> | 2014-05-31 12:33:24 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2014-05-31 12:33:24 -0500 |
commit | d8872c43b48eae5501998a4e5a84337017d8fbe6 (patch) | |
tree | 8360d8673d0ed40b02f9d58bdf74b639f6e780f9 /toys/other | |
parent | b0d97a0059555cb0e7e0009b72c038aa67aaa769 (diff) | |
download | toybox-d8872c43b48eae5501998a4e5a84337017d8fbe6.tar.gz |
Introduce xfork() and make commands use it, and make some WEXITSTATUS() use WIFEXITED() and WTERMSIG()+127.
Diffstat (limited to 'toys/other')
-rw-r--r-- | toys/other/netcat.c | 4 | ||||
-rw-r--r-- | toys/other/timeout.c | 7 |
2 files changed, 5 insertions, 6 deletions
diff --git a/toys/other/netcat.c b/toys/other/netcat.c index d002b047..3c6f630b 100644 --- a/toys/other/netcat.c +++ b/toys/other/netcat.c @@ -140,7 +140,7 @@ void netcat_main(void) // Do we need to return immediately because -l has arguments? if ((toys.optflags & FLAG_l) && toys.optc) { - if (fork()) goto cleanup; + if (xfork()) goto cleanup; close(0); close(1); close(2); @@ -149,7 +149,7 @@ void netcat_main(void) for (;;) { pid_t child = 0; - // For -l, call accept from the _new_ thread. + // For -l, call accept from the _new_ process. pollfds[0].fd = accept(sockfd, (struct sockaddr *)&address, &len); if (pollfds[0].fd<0) perror_exit("accept"); diff --git a/toys/other/timeout.c b/toys/other/timeout.c index 4b8a87df..f8acabf5 100644 --- a/toys/other/timeout.c +++ b/toys/other/timeout.c @@ -60,15 +60,14 @@ 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 = fork())) xexec_optargs(1); + if (!(TT.pid = xfork())) xexec_optargs(1); else { int status; signal(SIGALRM, handler); setitimer(ITIMER_REAL, &TT.itv, (void *)&toybuf); while (-1 == waitpid(TT.pid, &status, 0) && errno == EINTR); - if (WIFEXITED(status)) toys.exitval = WEXITSTATUS(status); - else if (WIFSIGNALED(status)) toys.exitval = WTERMSIG(status); - else toys.exitval = 1; + toys.exitval = WIFEXITED(status) + ? WEXITSTATUS(status) : WTERMSIG(status) + 127; } } |