summaryrefslogtreecommitdiff
path: root/lib/libpthread/tests/test_fork.c
diff options
context:
space:
mode:
authorPeter Galbavy <peter@cvs.openbsd.org>1998-07-21 13:22:23 +0000
committerPeter Galbavy <peter@cvs.openbsd.org>1998-07-21 13:22:23 +0000
commit0294ed9251849ce79ab3d4cc45841a9f6de82844 (patch)
tree30d684d4c18138e4ccaf59b61acadc667e515c74 /lib/libpthread/tests/test_fork.c
parent43b686d61558c0957f1779c747214ddef20a2252 (diff)
Complete initial import from mySQL 3.22.4 (mit-pthreads/).
Lots of dross to move and remove yet. At minimum: o remove GNU config and GNU Makefiles o build arch directory and migrate away machdep/ o rebuild BSD Makefiles o move notes etc. into doc/
Diffstat (limited to 'lib/libpthread/tests/test_fork.c')
-rw-r--r--lib/libpthread/tests/test_fork.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/lib/libpthread/tests/test_fork.c b/lib/libpthread/tests/test_fork.c
new file mode 100644
index 00000000000..4c2125e678a
--- /dev/null
+++ b/lib/libpthread/tests/test_fork.c
@@ -0,0 +1,60 @@
+/* ==== test_fork.c ============================================================
+ * 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.
+ */
+
+#define PTHREAD_KERNEL
+#include <pthread.h>
+#include <stdio.h>
+#include <fcntl.h>
+
+main()
+{
+ pthread_t thread;
+ int flags, pid;
+
+ pthread_init();
+
+ if (((flags = machdep_sys_fcntl(1, F_GETFL, NULL)) >= OK) &&
+ (flags & __FD_NONBLOCK | O_NDELAY)) {
+ machdep_sys_fcntl(1, F_SETFL, flags & (~__FD_NONBLOCK | O_NDELAY));
+ }
+ printf("parent process %d\n", getpid());
+
+ switch(pid = fork()) {
+ case OK:
+ exit(OK);
+ break;
+ case NOTOK:
+ printf("fork() FAILED\n");
+ exit(2);
+ break;
+ default:
+ if ((flags = machdep_sys_fcntl(1, F_GETFL, NULL)) >= OK) {
+ if (flags & (__FD_NONBLOCK | O_NDELAY)) {
+ printf("fd flags not set to BLOCKING ERROR\n");
+ printf("test_fork FAILED\n");
+ exit(1);
+ break;
+ }
+ printf("The stdout fd was set to BLOCKING\n");
+ printf("child process %d\n", pid);
+ flags = machdep_sys_fcntl(1, F_GETFL, NULL);
+ if (flags & (__FD_NONBLOCK | O_NDELAY)) {
+ printf("The stdout fd was reset to O_NDELAY\n");
+ } else {
+ printf("Error: the stdout fd was not reset\n");
+ printf("test_fork FAILED\n");
+ exit(1);
+ }
+ }
+ break;
+ }
+
+ printf("test_fork PASSED\n");
+ pthread_exit(NULL);
+}