vfs: check userland buffers before reading them.
[haiku.git] / src / tests / kits / net / sock / tellwait.c
blob4422de669c8532555bb307e527a77c7bb0004667
1 /* -*- c-basic-offset: 8; -*- */
2 #include <signal.h>
3 #include "ourhdr.h"
5 static volatile sig_atomic_t sigflag;
6 /* set nonzero by signal handler */
7 static sigset_t newmask, oldmask, zeromask;
9 static void
10 sig_usr(int signo) /* one signal handler for SIGUSR1 and SIGUSR2 */
12 sigflag = 1;
13 return;
16 void
17 TELL_WAIT()
19 if (signal(SIGUSR1, sig_usr) == SIG_ERR)
20 err_sys("signal(SIGINT) error");
21 if (signal(SIGUSR2, sig_usr) == SIG_ERR)
22 err_sys("signal(SIGQUIT) error");
24 sigemptyset(&zeromask);
26 sigemptyset(&newmask);
27 sigaddset(&newmask, SIGUSR1);
28 sigaddset(&newmask, SIGUSR2);
29 /* block SIGUSR1 and SIGUSR2, and save current signal mask */
30 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
31 err_sys("SIG_BLOCK error");
34 void
35 TELL_PARENT(pid_t pid)
37 kill(pid, SIGUSR2); /* tell parent we're done */
40 void
41 WAIT_PARENT(void)
43 while (sigflag == 0)
44 sigsuspend(&zeromask); /* and wait for parent */
46 sigflag = 0;
47 /* reset signal mask to original value */
48 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
49 err_sys("SIG_SETMASK error");
52 void
53 TELL_CHILD(pid_t pid)
55 kill(pid, SIGUSR1); /* tell child we're done */
58 void
59 WAIT_CHILD(void)
61 while (sigflag == 0)
62 sigsuspend(&zeromask); /* and wait for child */
64 sigflag = 0;
65 /* reset signal mask to original value */
66 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
67 err_sys("SIG_SETMASK error");