aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-09-05 14:18:38 -0500
committerRob Landley <rob@landley.net>2015-09-05 14:18:38 -0500
commit60d1aea2df9a8cc1e975ed5fee079982612f5966 (patch)
treefbe587bed6b3f20973870479da1ee512023e4843 /toys
parent73eca9182dfd7c2d52775ca24da6a7a0d55b3cee (diff)
downloadtoybox-60d1aea2df9a8cc1e975ed5fee079982612f5966.tar.gz
Two large thinkos in oneit: -3 was always enabled and signal numbers were
overwritten before we set up signal handlers.
Diffstat (limited to 'toys')
-rw-r--r--toys/other/oneit.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/toys/other/oneit.c b/toys/other/oneit.c
index 8e4b7133..cc510c15 100644
--- a/toys/other/oneit.c
+++ b/toys/other/oneit.c
@@ -61,7 +61,10 @@ void oneit_main(void)
{
int i, pid, pipes[] = {SIGUSR1, SIGUSR2, SIGTERM, SIGINT};
- if (FLAG_3) {
+ // Setup signal handlers for signals of interest
+ for (i = 0; i<ARRAY_LEN(pipes); i++) xsignal(pipes[i], oneit_signaled);
+
+ if (toys.optflags & FLAG_3) {
// Ensure next available filehandle is #3
while (open("/", 0) < 3);
close(3);
@@ -70,9 +73,6 @@ void oneit_main(void)
fcntl(4, F_SETFD, FD_CLOEXEC);
}
- // Setup signal handlers for signals of interest
- for (i = 0; i<ARRAY_LEN(pipes); i++) xsignal(pipes[i], oneit_signaled);
-
while (!toys.signal) {
// Create a new child process.
@@ -83,7 +83,7 @@ void oneit_main(void)
// We ignore the return value of write (what would we do with it?)
// but save it in a variable we never read to make fortify shut up.
// (Real problem is if pid2 never reads, write() fills pipe and blocks.)
- while (pid != wait(&i)) if (FLAG_3) i = write(4, &pid, 4);
+ while (pid != wait(&i)) if (toys.optflags & FLAG_3) i = write(4, &pid, 4);
if (toys.optflags & FLAG_n) continue;
oneit_signaled((toys.optflags & FLAG_p) ? SIGUSR2 : SIGTERM);