From e9417fffb39c299e556c5ad0c1545f0c02618e3c Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Fri, 18 Feb 2011 19:52:42 -0500 Subject: add pthread_atfork interface note that this presently does not handle consistency of the libc's own global state during forking. as per POSIX 2008, if the parent process was threaded, the child process may only call async-signal-safe functions until one of the exec-family functions is called, so the current behavior is believed to be conformant even if non-ideal. it may be improved at some later time. --- src/process/fork.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/process/fork.c') diff --git a/src/process/fork.c b/src/process/fork.c index 1213f0f5..0638ed67 100644 --- a/src/process/fork.c +++ b/src/process/fork.c @@ -1,9 +1,12 @@ #include #include "syscall.h" - -/* FIXME: add support for atfork stupidity */ +#include "libc.h" pid_t fork(void) { - return syscall0(__NR_fork); + pid_t ret; + if (libc.fork_handler) libc.fork_handler(-1); + ret = syscall0(__NR_fork); + if (libc.fork_handler) libc.fork_handler(!ret); + return ret; } -- cgit v1.2.1