From 53c34e8ff80500d6ef9366453e88c27a3a52ee46 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Mon, 23 Jan 2012 09:09:31 +0100 Subject: Remove automatic reinitialization of PKCS#11 after fork * First of all one should only call async-signal-safe functions from the callbacks of pthread_atfork(), and so we cannot reinitialize directly. * Some modules use pthread_atfork() to detect forking and setup their internal state. If we call into them in our pthread_atfork() callback then this is inherently racy. * There was danger of endless loops and deadlocks which are caused by handlers which fork in their C_Initialize * Many processes do fork/exec, reinitializing PKCS#11 for these forks is quite resourc intensive when the child process won't use PKCS#11 at all. --- p11-kit/modules.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/p11-kit/modules.c b/p11-kit/modules.c index c0660c7..047a2ca 100644 --- a/p11-kit/modules.c +++ b/p11-kit/modules.c @@ -541,21 +541,14 @@ reinitialize_after_fork (void) hashiter iter; Module *mod; - /* WARNING: This function must be reentrant */ _p11_debug ("forked"); _p11_lock (); if (gl.modules) { _p11_hash_iterate (gl.modules, &iter); - while (_p11_hash_next (&iter, NULL, (void **)&mod)) { - if (mod->initialize_called) { - mod->initialize_called = 0; - - /* WARNING: Reentrancy can occur here */ - initialize_module_unlocked_reentrant (mod); - } - } + while (_p11_hash_next (&iter, NULL, (void **)&mod)) + mod->initialize_called = 0; } _p11_unlock (); -- cgit v1.2.1