summaryrefslogtreecommitdiffstats
path: root/lib/libc/sys/w_fork.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/sys/w_fork.c')
-rw-r--r--lib/libc/sys/w_fork.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/lib/libc/sys/w_fork.c b/lib/libc/sys/w_fork.c
index 89415491f82..668731fdf67 100644
--- a/lib/libc/sys/w_fork.c
+++ b/lib/libc/sys/w_fork.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: w_fork.c,v 1.2 2015/10/25 18:03:17 guenther Exp $ */
+/* $OpenBSD: w_fork.c,v 1.3 2016/05/07 19:05:22 guenther Exp $ */
/*
* Copyright (c) 2008 Kurt Miller <kurt@openbsd.org>
@@ -30,14 +30,13 @@
* $FreeBSD: /repoman/r/ncvs/src/lib/libc_r/uthread/uthread_atfork.c,v 1.1 2004/12/10 03:36:45 grog Exp $
*/
+#include <tib.h>
#include <unistd.h>
#include "thread_private.h"
#include "atfork.h"
-pid_t _thread_fork(void);
-
pid_t
-fork(void)
+WRAP(fork)(void)
{
struct atfork_fn *p;
pid_t newid;
@@ -46,15 +45,27 @@ fork(void)
* In the common case the list is empty; remain async-signal-safe
* then by skipping the locking and just forking
*/
- if (TAILQ_FIRST(&_atfork_list) == NULL)
- return (_thread_fork());
+ if (TAILQ_FIRST(&_atfork_list) == NULL) {
+ if (_thread_cb.tc_fork != NULL)
+ return _thread_cb.tc_fork();
+ newid = fork();
+ if (newid == 0)
+ TIB_GET()->tib_tid = getthrid();
+ return newid;
+ }
_ATFORK_LOCK();
TAILQ_FOREACH_REVERSE(p, &_atfork_list, atfork_listhead, fn_next)
if (p->fn_prepare)
p->fn_prepare();
- newid = _thread_fork();
+ if (_thread_cb.tc_fork != NULL)
+ newid = _thread_cb.tc_fork();
+ else {
+ newid = fork();
+ if (newid == 0)
+ TIB_GET()->tib_tid = getthrid();
+ }
if (newid == 0) {
TAILQ_FOREACH(p, &_atfork_list, fn_next)
@@ -69,3 +80,4 @@ fork(void)
return (newid);
}
+DEF_WRAP(fork);