diff options
author | David Leonard <d@cvs.openbsd.org> | 1999-06-15 00:07:41 +0000 |
---|---|---|
committer | David Leonard <d@cvs.openbsd.org> | 1999-06-15 00:07:41 +0000 |
commit | b4a06a2741e75d6207a667a5e3a5d049f0bb0c4f (patch) | |
tree | 942f6f10743aedac513c569a7628c6a9d8abe980 /lib/libc_r | |
parent | 2f5d3571146c5577b8f5205f4e7b1cc6bf5795e1 (diff) |
Remove pthread_atfork(). It was only part of draft 10 for a little while and was removed before stddization.
Diffstat (limited to 'lib/libc_r')
-rw-r--r-- | lib/libc_r/TEST/test_fork.c | 60 | ||||
-rw-r--r-- | lib/libc_r/man/Makefile.inc | 6 | ||||
-rw-r--r-- | lib/libc_r/man/pthread_atfork.3 | 68 | ||||
-rw-r--r-- | lib/libc_r/uthread/Makefile.inc | 5 | ||||
-rw-r--r-- | lib/libc_r/uthread/pthread_private.h | 7 | ||||
-rw-r--r-- | lib/libc_r/uthread/uthread_atfork.c | 93 | ||||
-rw-r--r-- | lib/libc_r/uthread/uthread_fork.c | 10 |
7 files changed, 10 insertions, 239 deletions
diff --git a/lib/libc_r/TEST/test_fork.c b/lib/libc_r/TEST/test_fork.c index bf0cc583c80..ab53ec41d4c 100644 --- a/lib/libc_r/TEST/test_fork.c +++ b/lib/libc_r/TEST/test_fork.c @@ -47,51 +47,6 @@ sigchld(sig) SUCCEED; } -static int atfork_state = 0; - -void -atfork_child2() -{ - ASSERT(atfork_state++ == 3); - ASSERT(getpid() != parent_pid); -} - -void -atfork_parent2() -{ - ASSERT(atfork_state++ == 3); - ASSERT(getpid() == parent_pid); -} - -void -atfork_prepare2() -{ - ASSERT(atfork_state++ == 0); - ASSERT(getpid() == parent_pid); -} - - -void -atfork_child1() -{ - ASSERT(atfork_state++ == 2); - ASSERT(getpid() != parent_pid); -} - -void -atfork_parent1() -{ - ASSERT(atfork_state++ == 2); - ASSERT(getpid() == parent_pid); -} - -void -atfork_prepare1() -{ - ASSERT(atfork_state++ == 1); - ASSERT(getpid() == parent_pid); -} - int main() { @@ -112,36 +67,27 @@ main() CHECKe(signal(SIGCHLD, sigchld)); - /* Install some atfork handlers */ - - CHECKr(pthread_atfork(&atfork_prepare1, &atfork_parent1, - &atfork_child1)); - CHECKr(pthread_atfork(&atfork_prepare2, &atfork_parent2, - &atfork_child2)); - - printf("forking\n"); + printf("forking from pid %d\n", getpid()); CHECKe(pid = fork()); switch(pid) { case 0: /* child: */ + printf("child = pid %d\n", getpid()); /* Our pid should change */ ASSERT(getpid() != parent_pid); /* Our sleeper thread should have disappeared */ ASSERT(ESRCH == pthread_cancel(sleeper_thread)); - /* The atfork handler should have run */ - ASSERT(atfork_state++ == 4); 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_cancel(sleeper_thread)); - /* The atfork handler should have run */ - ASSERT(atfork_state++ == 4); /* wait for the SIGCHLD from the child */ CHECKe(pause()); PANIC("pause"); diff --git a/lib/libc_r/man/Makefile.inc b/lib/libc_r/man/Makefile.inc index 55b37d24f48..c51d8ad23cc 100644 --- a/lib/libc_r/man/Makefile.inc +++ b/lib/libc_r/man/Makefile.inc @@ -1,11 +1,11 @@ -# $Id: Makefile.inc,v 1.5 1999/03/24 00:46:23 d Exp $ -# $OpenBSD: Makefile.inc,v 1.5 1999/03/24 00:46:23 d Exp $ +# $Id: Makefile.inc,v 1.6 1999/06/15 00:07:40 d Exp $ +# $OpenBSD: Makefile.inc,v 1.6 1999/06/15 00:07:40 d Exp $ # POSIX thread man files .PATH: ${.CURDIR}/man -MAN+= pthread_atfork.3 \ +MAN+= \ pthread_cleanup_pop.3 \ pthread_cleanup_push.3 \ pthread_cond_broadcast.3 \ diff --git a/lib/libc_r/man/pthread_atfork.3 b/lib/libc_r/man/pthread_atfork.3 deleted file mode 100644 index 1e56409ce51..00000000000 --- a/lib/libc_r/man/pthread_atfork.3 +++ /dev/null @@ -1,68 +0,0 @@ -.Dd January 17, 1999 -.Dt PTHREAD_ATFORK 3 -.Os -.Sh NAME -.Nm pthread_atfork -.Nd specify handler functions to call when the process forks -.Sh SYNOPSIS -.Fd #include <pthread.h> -.Ft int -.Fn pthread_atfork "void (*prepare)(void)" "void (*parent)(void)" "void (*child)(void)" -.Sh DESCRIPTION -The -.Fn pthread_atfork -function declares fork handlers to be called before and after -.Fn fork , -in the context of the thread that called -.Fn fork . -The -.Fa prepare -fork handler will be called before -.Fn fork -processing commences. The -.Fa parent -fork handler will be called after -.Fn fork -prcessing completes in the parent process. The -.Fa child -fork handler will be called after -.Fn fork -processing completes in the child process. If no handling is desired at -one or more of these three points, the correspoding fork handler -address(es) may be set to -.Dv NULL . -.Pp -The order of calls to -.Fn pthread_atfork -is significant. The -.Fa parent -and -.Fa child -fork handlers will be called in the order in which they were established -by calls to -.Fn pthread_atfork . -The -.Fa prepare -fork handlers will be called in the opposite order. -.Sh RETURN VALUES -Upon successful completion, -.Fn pthread_atfork -will return a value of zero. Otherwise, an error number will be -returned to indicate the error. -.Sh ERRORS -.Fn pthread_atfork -will fail if: -.Bl -tag -width Er -.It Bq Er ENOMEM -Insufficient table space exists to record the fork handler addresses. -None of the handler lists are modified. -.El -.Pp -.Sh SEE ALSO -.Xr fork 2 , -.Xr atexit 3 -.Sh STANDARDS -.Fn pthread_atfork -conforms to ISO/IEC 9945-1 ANSI/IEEE -.Pq Dq Tn POSIX -Std 1003.1 Second Edition 1996-07-12. diff --git a/lib/libc_r/uthread/Makefile.inc b/lib/libc_r/uthread/Makefile.inc index 22bfb740e07..56a6b0046ba 100644 --- a/lib/libc_r/uthread/Makefile.inc +++ b/lib/libc_r/uthread/Makefile.inc @@ -1,5 +1,5 @@ -# $Id: Makefile.inc,v 1.7 1999/05/26 00:18:21 d Exp $ -# $OpenBSD: Makefile.inc,v 1.7 1999/05/26 00:18:21 d Exp $ +# $Id: Makefile.inc,v 1.8 1999/06/15 00:07:39 d Exp $ +# $OpenBSD: Makefile.inc,v 1.8 1999/06/15 00:07:39 d Exp $ # uthread sources .PATH: ${.CURDIR}/uthread @@ -8,7 +8,6 @@ CFLAGS += -I${.CURDIR}/arch/${MACHINE_ARCH} SRCS+= \ uthread_accept.c \ - uthread_atfork.c \ uthread_attr_destroy.c \ uthread_attr_init.c \ uthread_attr_getdetachstate.c \ diff --git a/lib/libc_r/uthread/pthread_private.h b/lib/libc_r/uthread/pthread_private.h index ef7b7e838e2..748485bc454 100644 --- a/lib/libc_r/uthread/pthread_private.h +++ b/lib/libc_r/uthread/pthread_private.h @@ -31,7 +31,7 @@ * * Private thread definitions for the uthread kernel. * - * $OpenBSD: pthread_private.h,v 1.15 1999/06/09 07:06:54 d Exp $ + * $OpenBSD: pthread_private.h,v 1.16 1999/06/15 00:07:39 d Exp $ * */ @@ -301,10 +301,6 @@ struct pthread_attr { #define PTHREAD_MIN_PRIORITY 0 #define _POSIX_THREAD_ATTR_STACKSIZE -#define PTHREAD_ATFORK_PREPARE 0 -#define PTHREAD_ATFORK_PARENT 1 -#define PTHREAD_ATFORK_CHILD 2 - /* * Clock resolution in nanoseconds. */ @@ -784,7 +780,6 @@ pthread_addr_t _thread_gc(pthread_addr_t); void _thread_enter_cancellation_point(void); void _thread_leave_cancellation_point(void); void _thread_cancellation_point(void); -void _thread_atfork(int); int _thread_slow_atomic_lock(volatile _spinlock_lock_t *); int _thread_slow_atomic_is_locked(volatile _spinlock_lock_t *); diff --git a/lib/libc_r/uthread/uthread_atfork.c b/lib/libc_r/uthread/uthread_atfork.c deleted file mode 100644 index a3ea65e8288..00000000000 --- a/lib/libc_r/uthread/uthread_atfork.c +++ /dev/null @@ -1,93 +0,0 @@ -/* - * David Leonard <d@openbsd.org>, 1999. Public domain. - * $OpenBSD: uthread_atfork.c,v 1.1 1999/01/17 23:46:26 d Exp $ - */ - -#include <stdlib.h> -#include <sys/queue.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" - -struct atfork_entry { - void (*handler)(void); - TAILQ_ENTRY(atfork_entry) entries; -}; - -static TAILQ_HEAD(atfork_list, atfork_entry) atfork_head[3] = - { TAILQ_HEAD_INITIALIZER(atfork_head[PTHREAD_ATFORK_PREPARE]), - TAILQ_HEAD_INITIALIZER(atfork_head[PTHREAD_ATFORK_PARENT]), - TAILQ_HEAD_INITIALIZER(atfork_head[PTHREAD_ATFORK_CHILD]) }; - -void -_thread_atfork(which) -{ - struct atfork_list *head; - struct atfork_entry *ae; - - head = &atfork_head[which]; - - /* Call the fork handlers in order: */ - for (ae = head->tqh_first; ae != NULL; ae = ae->entries.tqe_next) - (*ae->handler)(); -} - -int -pthread_atfork(prepare, parent, child) - void (*prepare)(void); - void (*parent)(void); - void (*child)(void); -{ - int ret = 0; - struct atfork_entry *prepare_entry = NULL; - struct atfork_entry *parent_entry = NULL; - struct atfork_entry *child_entry = NULL; - - if (ret == 0 && prepare != NULL) { - /* Allocate space for the prepare handler: */ - if ((prepare_entry = malloc(sizeof *prepare_entry)) != NULL) - prepare_entry->handler = prepare; - else - ret = -1; - } - - if (ret == 0 && parent != NULL) { - /* Allocate space for the parent handler: */ - if ((parent_entry = malloc(sizeof *parent_entry)) != NULL) - parent_entry->handler = parent; - else - ret = -1; - } - - if (ret == 0 && child != NULL) { - /* Allocate space for the child handler: */ - if ((child_entry = malloc(sizeof *child_entry)) != NULL) - child_entry->handler = child; - else - ret = -1; - } - - if (ret == 0) { - /* Insert the handlers into the handler lists: */ - if (prepare_entry != NULL) - TAILQ_INSERT_HEAD(&atfork_head[PTHREAD_ATFORK_PREPARE], - prepare_entry, entries); - if (parent_entry != NULL) - TAILQ_INSERT_TAIL(&atfork_head[PTHREAD_ATFORK_PARENT], - parent_entry, entries); - if (child_entry != NULL) - TAILQ_INSERT_TAIL(&atfork_head[PTHREAD_ATFORK_CHILD], - child_entry, entries); - } else { - /* Release unused resources: */ - if (prepare_entry) - free(prepare_entry); - if (child_entry) - free(child_entry); - if (parent_entry) - free(parent_entry); - } - - return (ret); -} -#endif diff --git a/lib/libc_r/uthread/uthread_fork.c b/lib/libc_r/uthread/uthread_fork.c index 9dc90825233..ed1566915bd 100644 --- a/lib/libc_r/uthread/uthread_fork.c +++ b/lib/libc_r/uthread/uthread_fork.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $OpenBSD: uthread_fork.c,v 1.5 1999/05/26 00:18:23 d Exp $ + * $OpenBSD: uthread_fork.c,v 1.6 1999/06/15 00:07:39 d Exp $ */ #include <errno.h> #include <string.h> @@ -48,17 +48,12 @@ fork(void) pthread_t pthread; pthread_t pthread_next; - /* Call atfork handlers: */ - _thread_atfork(PTHREAD_ATFORK_PREPARE); - /* Lock the thread list: */ _lock_thread_list(); /* Fork a new process: */ if ((ret = _thread_sys_fork()) != 0) { /* Parent process or error. Nothing to do here. */ - if (ret > 0) - _thread_atfork(PTHREAD_ATFORK_PARENT); } else { /* Close the pthread kernel pipe: */ _thread_sys_close(_thread_kern_pipe[0]); @@ -157,9 +152,6 @@ fork(void) _thread_queue_init(&_thread_fd_table[i]->w_queue); } } - - /* Initialise the atfork handler: */ - _thread_atfork(PTHREAD_ATFORK_CHILD); } } |