From: Nikos Mavrogiannopoulos Date: Thu, 5 Dec 2013 10:16:03 +0000 (+0100) Subject: Added automatic reinitialization on fork() on the PKCS #11 subsystem. X-Git-Tag: gnutls_3_3_0pre0~493 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0802857500997bd7544daa32a728fcd4778f0bc8;p=thirdparty%2Fgnutls.git Added automatic reinitialization on fork() on the PKCS #11 subsystem. --- diff --git a/lib/pkcs11.c b/lib/pkcs11.c index 66bbdef316..1de44f9244 100644 --- a/lib/pkcs11.c +++ b/lib/pkcs11.c @@ -36,6 +36,9 @@ #include #include #include +#ifdef HAVE_GETPID +# include +#endif #define MAX_PROVIDERS 16 @@ -72,6 +75,9 @@ struct crt_find_data_st { static struct gnutls_pkcs11_provider_st providers[MAX_PROVIDERS]; static unsigned int active_providers = 0; static unsigned int providers_initialized = 0; +#ifdef HAVE_GETPID +static pid_t init_pid = -1; +#endif gnutls_pkcs11_token_callback_t _gnutls_token_func; void *_gnutls_token_data; @@ -216,11 +222,25 @@ pkcs11_init_modules(void) if (ret != 0) return gnutls_assert_val(GNUTLS_E_LOCKING_ERROR); + if (providers_initialized != 0) { + ret = 0; +#ifdef HAVE_GETPID + if (init_pid != getpid()) { + /* if we are initialized but a fork is detected */ + ret = gnutls_pkcs11_reinit(); + init_pid = getpid(); + } +#endif + gnutls_mutex_unlock(&_gnutls_pkcs11_mutex); - return 0; + return ret; } - + +#ifdef HAVE_GETPID + init_pid = getpid(); +#endif + providers_initialized = 1; gnutls_mutex_unlock(&_gnutls_pkcs11_mutex);