summaryrefslogtreecommitdiff
path: root/test/signal
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2002-01-02 06:52:04 +0000
committerEric Andersen <andersen@codepoet.org>2002-01-02 06:52:04 +0000
commit53b4958525785698539e0846a6fe6b4086148858 (patch)
tree46b4e776e832dbdcda03f66acf82de0f74cf5725 /test/signal
parenteae91bb3afc7976e855f21cb916bb3caaf513933 (diff)
Cleaned up test that doesn't need manual intervention.
-Erik
Diffstat (limited to 'test/signal')
-rw-r--r--test/signal/sigchld.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/test/signal/sigchld.c b/test/signal/sigchld.c
index 05f4d1594..cf82bb6b5 100644
--- a/test/signal/sigchld.c
+++ b/test/signal/sigchld.c
@@ -1,34 +1,57 @@
#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
#include <stdio.h>
#include <sys/signal.h>
+#include <sys/wait.h>
#include <unistd.h>
+
void test_handler(int signo)
{
- fprintf(stderr, "caught signo: %d\n", signo);
+ printf("caught signo: %d\n", signo);
+ fflush(stdout);
}
int main(void)
{
+ pid_t mypid;
int count = 0;
struct sigaction siga;
static sigset_t sigset;
+ mypid = getpid();
+
+ if (fork() == 0) {
+ int i;
+
+ for (i=0; i < 3; i++) {
+ sleep(2);
+ kill(mypid, SIGCHLD);
+ }
+ exit(EXIT_SUCCESS);
+ }
+
sigfillset(&sigset);
siga.sa_handler = test_handler;
siga.sa_mask = sigset;
siga.sa_flags = 0;
- if (0 != sigaction(SIGCHLD, &siga, (struct sigaction *)NULL)) {
- fprintf(stderr, "ack!");
+ if (sigaction(SIGCHLD, &siga, (struct sigaction *)NULL) != 0) {
+ fprintf(stderr, "sigaction choked: %s!", strerror(errno));
+ exit(EXIT_FAILURE);
}
- printf("give me a SIGCHLD\n");
+ printf("waiting for a SIGCHLD\n");
+ fflush(stdout);
for(;;) {
sleep(10);
+ if (waitpid(-1, NULL, WNOHANG | WUNTRACED) > 0)
+ break;
printf("after sleep %d\n", ++count);
+ fflush(stdout);
}
printf("after loop\n");