summaryrefslogtreecommitdiffstats
path: root/lib/librthread/rthread_fork.c
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2015-04-07 01:27:06 +0000
committerguenther <guenther@openbsd.org>2015-04-07 01:27:06 +0000
commit514a545f8a3983d53b7de4e8dfcefe16c9496776 (patch)
treee17cf0966466dfd49a1decf34dd536d3fdbe4765 /lib/librthread/rthread_fork.c
parentDo not mistreat empty arguments to font alternating macros (diff)
downloadwireguard-openbsd-514a545f8a3983d53b7de4e8dfcefe16c9496776.tar.xz
wireguard-openbsd-514a545f8a3983d53b7de4e8dfcefe16c9496776.zip
Make pthread_atfork() track the DSO that called it like atexit() does,
unregistering callbacks if the DSO is unloaded. Move the callback handling from libpthread to libc, though libpthread still overrides the inner call to handle locking and thread-library reinitialization. Major version bump for both libc and libpthread. verification that this fixes various ports ajacoutot@ asm assistance miod@; ok millert@ deraadt@
Diffstat (limited to 'lib/librthread/rthread_fork.c')
-rw-r--r--lib/librthread/rthread_fork.c56
1 files changed, 4 insertions, 52 deletions
diff --git a/lib/librthread/rthread_fork.c b/lib/librthread/rthread_fork.c
index cb76421d2a1..c9086daf595 100644
--- a/lib/librthread/rthread_fork.c
+++ b/lib/librthread/rthread_fork.c
@@ -1,8 +1,8 @@
-/* $OpenBSD: rthread_fork.c,v 1.10 2013/11/29 16:27:40 guenther Exp $ */
+/* $OpenBSD: rthread_fork.c,v 1.11 2015/04/07 01:27:07 guenther Exp $ */
/*
* Copyright (c) 2008 Kurt Miller <kurt@openbsd.org>
- * Copyright (c) 2008 Philip Guenther <guenther@gmail.com>
+ * Copyright (c) 2008 Philip Guenther <guenther@openbsd.org>
* Copyright (c) 2003 Daniel Eischen <deischen@freebsd.org>
* All rights reserved.
*
@@ -46,18 +46,6 @@
#include "rthread.h"
-struct rthread_atfork {
- TAILQ_ENTRY(rthread_atfork) next;
- void (*prepare)(void);
- void (*parent)(void);
- void (*child)(void);
-};
-
-static TAILQ_HEAD(atfork_listhead, rthread_atfork) _atfork_list =
- TAILQ_HEAD_INITIALIZER(_atfork_list);
-
-static struct _spinlock _atfork_lock = _SPINLOCK_UNLOCKED;
-
pid_t _thread_sys_fork(void);
pid_t _thread_sys_vfork(void);
pid_t _dofork(int);
@@ -144,27 +132,9 @@ _dofork(int is_vfork)
}
pid_t
-fork(void)
+_thread_fork(void)
{
- struct rthread_atfork *p;
- pid_t newid;
-
- _spinlock(&_atfork_lock);
- TAILQ_FOREACH_REVERSE(p, &_atfork_list, atfork_listhead, next)
- if (p->prepare)
- p->prepare();
- newid = _dofork(0);
- if (newid == 0) {
- TAILQ_FOREACH(p, &_atfork_list, next)
- if (p->child)
- p->child();
- } else {
- TAILQ_FOREACH(p, &_atfork_list, next)
- if (p->parent)
- p->parent();
- }
- _spinunlock(&_atfork_lock);
- return newid;
+ return _dofork(0);
}
pid_t
@@ -172,21 +142,3 @@ vfork(void)
{
return _dofork(1);
}
-
-int
-pthread_atfork(void (*prepare)(void), void (*parent)(void),
- void (*child)(void))
-{
- struct rthread_atfork *af;
-
- if ((af = malloc(sizeof *af)) == NULL)
- return (ENOMEM);
-
- af->prepare = prepare;
- af->parent = parent;
- af->child = child;
- _spinlock(&_atfork_lock);
- TAILQ_INSERT_TAIL(&_atfork_list, af, next);
- _spinunlock(&_atfork_lock);
- return (0);
-}