Module: kamailio Branch: 5.8 Commit: 0ba1ff1d430e5e51c7745d7eb1242dcae2557db9 URL: https://github.com/kamailio/kamailio/commit/0ba1ff1d430e5e51c7745d7eb1242dca...
Author: S-P Chan shihping.chan@gmail.com Committer: S-P Chan shihping.chan@gmail.com Date: 2024-03-04T22:27:36+08:00
tls: new option tls_threads_mode = 2
- use pthread_atfork to force all thread-locals to 0x0 after fork()
(cherry picked from commit 464299c202f3ba963aed821b777075397e843856)
---
Modified: src/modules/tls/tls_mod.c
---
Diff: https://github.com/kamailio/kamailio/commit/0ba1ff1d430e5e51c7745d7eb1242dca... Patch: https://github.com/kamailio/kamailio/commit/0ba1ff1d430e5e51c7745d7eb1242dca...
---
diff --git a/src/modules/tls/tls_mod.c b/src/modules/tls/tls_mod.c index 1dc9357f56a..6dfde00c93a 100644 --- a/src/modules/tls/tls_mod.c +++ b/src/modules/tls/tls_mod.c @@ -337,6 +337,20 @@ static tls_domains_cfg_t* tls_use_modparams(void) } #endif
+/* global config tls_threads_mode = 2 + * - force all thread-locals to be 0x0 after fork() + * - with OpenSSL loaded the largest value observed + * is < 10 + * + */ +static void fork_child(void) +{ + for(int k = 0; k < 16; k++) { + if(pthread_getspecific(k) != 0) + pthread_setspecific(k, 0x0); + } +} + static int mod_init(void) { int method; @@ -446,6 +460,9 @@ static int mod_init(void) ksr_module_set_flag(KSRMOD_FLAG_POSTCHILDINIT); } #endif + if(ksr_tls_threads_mode == 2) { + pthread_atfork(NULL, NULL, &fork_child); + } return 0; error: tls_h_mod_destroy_f();