This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCHv2,HURD] Add fork hooks for pthread_atfork
- From: Samuel Thibault <samuel dot thibault at ens-lyon dot org>
- To: roland at redhat dot com
- Cc: libc-alpha at sources dot redhat dot com
- Date: Tue, 24 Sep 2013 23:08:15 +0200
- Subject: [PATCHv2,HURD] Add fork hooks for pthread_atfork
- Authentication-results: sourceware.org; auth=none
- References: <20110619130724 dot GV6349 at const dot famille dot thibault dot fr> <20130921212355 dot GV30838 at type dot youpi dot perso dot aquilenet dot fr>
2013-09-24 Samuel Thibault <samuel.thibault@ens-lyon.org>
pthread_atfork needs application callbacks to be called outside any locking.
* sysdeps/mach/hurd/fork.c (_hurd_atfork_prepare_hook, _hurd_atfork_child_hook,
_hurd_atfork_parent_hook): New hooks.
(__fork): Call _hurd_atfork_prepare_hook hooks before all locking, call
_hurd_atfork_parent_hook or _hurd_atfork_child_hook after all unlocking.
---
sysdeps/mach/hurd/fork.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/sysdeps/mach/hurd/fork.c b/sysdeps/mach/hurd/fork.c
index ab11bab..3a6803e 100644
--- a/sysdeps/mach/hurd/fork.c
+++ b/sysdeps/mach/hurd/fork.c
@@ -34,6 +34,11 @@
symbol_set_declare (_hurd_fork_locks)
+/* Application callbacks registered through pthread_atfork. */
+DEFINE_HOOK (_hurd_atfork_prepare_hook, (void));
+DEFINE_HOOK (_hurd_atfork_child_hook, (void));
+DEFINE_HOOK (_hurd_atfork_parent_hook, (void));
+
/* Things that want to be called before we fork, to prepare the parent for
task_create, when the new child task will inherit our address space. */
DEFINE_HOOK (_hurd_fork_prepare_hook, (void));
@@ -62,6 +67,8 @@ __fork (void)
error_t err;
struct hurd_sigstate *volatile ss;
+ RUN_HOOK (_hurd_atfork_prepare_hook, ());
+
ss = _hurd_self_sigstate ();
__spin_lock (&ss->critical_section_lock);
@@ -695,6 +702,14 @@ __fork (void)
_hurd_critical_section_unlock (ss);
+ if (!err)
+ {
+ if (pid != 0)
+ RUN_HOOK (_hurd_atfork_parent_hook, ());
+ else
+ RUN_HOOK (_hurd_atfork_child_hook, ());
+ }
+
return err ? __hurd_fail (err) : pid;
}
libc_hidden_def (__fork)