summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Leonard <d@cvs.openbsd.org>2000-01-06 06:54:29 +0000
committerDavid Leonard <d@cvs.openbsd.org>2000-01-06 06:54:29 +0000
commitf26a97df5e3f7e48be61e887cd6c4959f05e5c8d (patch)
treef3e28407ce08d9d77c47f691ed93ca52e398fb75 /lib
parent968e769c8bbe23bd6f7287f9caae63be8fa16676 (diff)
longer sleep, doc, get rid of bad signal handler
Diffstat (limited to 'lib')
-rw-r--r--lib/libc_r/TEST/test_fork.c66
1 files changed, 24 insertions, 42 deletions
diff --git a/lib/libc_r/TEST/test_fork.c b/lib/libc_r/TEST/test_fork.c
index 60a7181a4ad..efd23860ca8 100644
--- a/lib/libc_r/TEST/test_fork.c
+++ b/lib/libc_r/TEST/test_fork.c
@@ -1,10 +1,8 @@
-/* ==== test_fork.c ============================================================
+/* $OpenBSD: test_fork.c,v 1.7 2000/01/06 06:54:28 d Exp $ */
+/*
* Copyright (c) 1994 by Chris Provenzano, proven@athena.mit.edu
*
- * Description : Test fork() and dup2() calls.
- *
- * 1.00 94/04/29 proven
- * -Started coding this file.
+ * Test the fork system call.
*/
#include <pthread.h>
@@ -17,43 +15,26 @@
#include <sys/wait.h>
#include "test.h"
+
void *
sleeper(void *arg)
{
pthread_set_name_np(pthread_self(), "slpr");
- sleep(2);
+ sleep(4);
PANIC("sleeper timed out");
}
-static pid_t parent_pid;
-
-static void
-sigchld(sig)
- int sig;
-{
- int status;
-
- /* we should have got a SIGCHLD */
- ASSERT(sig == SIGCHLD);
- /* We should be the parent */
- ASSERT(getpid() == parent_pid);
- /* wait for any child */
- CHECKe(wait(&status));
- /* the child should have called exit(0) */
- ASSERT(WIFEXITED(status));
- ASSERT(WEXITSTATUS(status) == 0);
- printf("parent ok\n");
- SUCCEED;
-}
int
main()
{
int flags;
- pid_t pid;
pthread_t sleeper_thread;
void *result;
+ int status;
+ pid_t parent_pid;
+ pid_t child_pid;
parent_pid = getpid();
@@ -66,13 +47,10 @@ main()
CHECKr(pthread_create(&sleeper_thread, NULL, sleeper, NULL));
sleep(1);
- CHECKe(signal(SIGCHLD, sigchld));
-
printf("forking from pid %d\n", getpid());
- CHECKe(pid = fork());
- switch(pid) {
- case 0:
+ CHECKe(child_pid = fork());
+ if (child_pid == 0) {
/* child: */
printf("child = pid %d\n", getpid());
/* Our pid should change */
@@ -82,15 +60,19 @@ main()
printf("child ok\n");
_exit(0);
PANIC("child _exit");
- default:
- /* parent: */
- printf("parent = pid %d\n", getpid());
- /* Our pid should stay the same */
- ASSERT(getpid() == parent_pid);
- /* Our sleeper thread should still be around */
- CHECKr(pthread_join(sleeper_thread, &result));
- /* wait for the SIGCHLD from the child */
- CHECKe(pause());
- PANIC("pause");
}
+
+ /* parent: */
+ printf("parent = pid %d\n", getpid());
+ /* Our pid should stay the same */
+ ASSERT(getpid() == parent_pid);
+ /* wait for the child */
+ ASSERTe(wait(&status), == child_pid);
+ /* the child should have called exit(0) */
+ ASSERT(WIFEXITED(status));
+ ASSERT(WEXITSTATUS(status) == 0);
+ /* Our sleeper thread should still be around */
+ CHECKr(pthread_detach(sleeper_thread));
+ printf("parent ok\n");
+ SUCCEED;
}