1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-03-11 22:52:47 +01:00

dirmngr: Use the same thread init strategy as gpg-agent et al.

* dirmngr/dirmngr.c (initialize_modules): New.
(thread_init): Run npth_init only once.  Re-init Libassuan and
Libgcrypt syscall clamps.  Replace all calls by calls to
initialize_modules.
--

GnuPG-bug-id: 6606
This commit is contained in:
Werner Koch 2025-03-06 10:51:59 +01:00
parent 73f6c2dd4d
commit 25d48663f9
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B

View File

@ -976,23 +976,48 @@ my_ntbtls_log_handler (void *opaque, int level, const char *fmt, va_list argv)
#endif #endif
/* Helper for initialize_modules. */
static void static void
thread_init (void) thread_init (void)
{ {
npth_init (); static int npth_initialized = 0;
if (!npth_initialized)
{
npth_initialized++;
npth_init ();
/* With nPth running we can set the logging callback. Our
* windows implementation does not yet feature the nPth TLS
* functions. */
#ifndef HAVE_W32_SYSTEM
if (npth_key_create (&my_tlskey_current_fd, NULL) == 0)
if (npth_setspecific (my_tlskey_current_fd, NULL) == 0)
log_set_pid_suffix_cb (pid_suffix_callback);
#endif /*!HAVE_W32_SYSTEM*/
}
gpgrt_set_syscall_clamp (npth_unprotect, npth_protect); gpgrt_set_syscall_clamp (npth_unprotect, npth_protect);
/* Now with NPth running we can set the logging callback. Our /* Now that we have set the syscall clamp we need to tell Libgcrypt
windows implementation does not yet feature the NPth TLS * that it should get them from libgpg-error. Note that Libgcrypt
functions. */ * has already been initialized but at that point nPth was not
#ifndef HAVE_W32_SYSTEM * initialized and thus Libgcrypt could not set its system call
if (npth_key_create (&my_tlskey_current_fd, NULL) == 0) * clamp. */
if (npth_setspecific (my_tlskey_current_fd, NULL) == 0) gcry_control (GCRYCTL_REINIT_SYSCALL_CLAMP, 0, 0);
log_set_pid_suffix_cb (pid_suffix_callback); assuan_control (ASSUAN_CONTROL_REINIT_SYSCALL_CLAMP, NULL);
#endif /*!HAVE_W32_SYSTEM*/
} }
static void
initialize_modules (void)
{
thread_init ();
cert_cache_init (hkp_cacert_filenames);
crl_cache_init ();
ks_hkp_init ();
}
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
@ -1317,12 +1342,9 @@ main (int argc, char **argv)
log_debug ("... okay\n"); log_debug ("... okay\n");
} }
initialize_modules ();
thread_init ();
cert_cache_init (hkp_cacert_filenames);
crl_cache_init ();
ks_hkp_init ();
http_register_netactivity_cb (netactivity_action); http_register_netactivity_cb (netactivity_action);
start_command_handler (ASSUAN_INVALID_FD, 0); start_command_handler (ASSUAN_INVALID_FD, 0);
shutdown_reaper (); shutdown_reaper ();
} }
@ -1360,10 +1382,7 @@ main (int argc, char **argv)
else else
log_set_prefix (NULL, 0); log_set_prefix (NULL, 0);
thread_init (); initialize_modules ();
cert_cache_init (hkp_cacert_filenames);
crl_cache_init ();
ks_hkp_init ();
http_register_netactivity_cb (netactivity_action); http_register_netactivity_cb (netactivity_action);
handle_connections (3); handle_connections (3);
shutdown_reaper (); shutdown_reaper ();
@ -1587,11 +1606,9 @@ main (int argc, char **argv)
} }
} }
thread_init (); initialize_modules ();
cert_cache_init (hkp_cacert_filenames);
crl_cache_init ();
ks_hkp_init ();
http_register_netactivity_cb (netactivity_action); http_register_netactivity_cb (netactivity_action);
handle_connections (fd); handle_connections (fd);
shutdown_reaper (); shutdown_reaper ();
} }
@ -1610,10 +1627,8 @@ main (int argc, char **argv)
memset (&ctrlbuf, 0, sizeof ctrlbuf); memset (&ctrlbuf, 0, sizeof ctrlbuf);
dirmngr_init_default_ctrl (&ctrlbuf); dirmngr_init_default_ctrl (&ctrlbuf);
thread_init (); initialize_modules ();
cert_cache_init (hkp_cacert_filenames);
crl_cache_init ();
ks_hkp_init ();
if (!argc) if (!argc)
rc = crl_cache_load (&ctrlbuf, NULL); rc = crl_cache_load (&ctrlbuf, NULL);
else else
@ -1634,10 +1649,8 @@ main (int argc, char **argv)
memset (&ctrlbuf, 0, sizeof ctrlbuf); memset (&ctrlbuf, 0, sizeof ctrlbuf);
dirmngr_init_default_ctrl (&ctrlbuf); dirmngr_init_default_ctrl (&ctrlbuf);
thread_init (); initialize_modules ();
cert_cache_init (hkp_cacert_filenames);
crl_cache_init ();
ks_hkp_init ();
rc = crl_fetch (&ctrlbuf, argv[0], &reader); rc = crl_fetch (&ctrlbuf, argv[0], &reader);
if (rc) if (rc)
log_error (_("fetching CRL from '%s' failed: %s\n"), log_error (_("fetching CRL from '%s' failed: %s\n"),