summaryrefslogtreecommitdiffstats
path: root/crypto/init.c
diff options
context:
space:
mode:
authorRich Salz <rsalz@openssl.org>2017-06-22 14:00:06 -0400
committerRich Salz <rsalz@openssl.org>2017-06-29 16:19:41 -0400
commit2915fe19a6676374c335d8c50eaaa4c940cf47d6 (patch)
tree4d959df974cc5ea075a230101ac2b95c7da23320 /crypto/init.c
parent5ee407460b3b68aa4695f17cf8c43e0d07cb18a8 (diff)
Add fork handlers, based on pthread_atfork
Only for Unix platforms Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/3754)
Diffstat (limited to 'crypto/init.c')
-rw-r--r--crypto/init.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/crypto/init.c b/crypto/init.c
index e159a3dd0c..bc961718da 100644
--- a/crypto/init.c
+++ b/crypto/init.c
@@ -552,6 +552,10 @@ int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
&& !RUN_ONCE(&add_all_digests, ossl_init_add_all_digests))
return 0;
+ if ((opts & OPENSSL_INIT_NO_ATFORK) == 0
+ && !openssl_init_fork_handlers())
+ return 0;
+
if ((opts & OPENSSL_INIT_NO_LOAD_CONFIG)
&& !RUN_ONCE(&config, ossl_init_no_config))
return 0;
@@ -677,3 +681,28 @@ int OPENSSL_atexit(void (*handler)(void))
return 1;
}
+
+#ifdef OPENSSL_SYS_UNIX
+/*
+ * The following three functions are for OpenSSL developers. This is
+ * where we set/reset state across fork (called via pthread_atfork when
+ * it exists, or manually by the application when it doesn't).
+ *
+ * WARNING! If you put code in either OPENSSL_fork_parent or
+ * OPENSSL_fork_child, you MUST MAKE SURE that they are async-signal-
+ * safe. See this link, for example:
+ * http://man7.org/linux/man-pages/man7/signal-safety.7.html
+ */
+
+void OPENSSL_fork_prepare(void)
+{
+}
+
+void OPENSSL_fork_parent(void)
+{
+}
+
+void OPENSSL_fork_child(void)
+{
+}
+#endif