mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
agent, dirmngr, scd: npth_init must be after fork.
* agent/gpg-agent.c (thread_init_once, initialize_modules): New. (main): Make sure no daemonizing-fork call after npth_init, and no npth calls before npth_init, with care of npth calls by assuan hooks. * dirmngr/dirmngr.c (thread_init): New. (main): Make sure npth_init must not be called before daemonizing fork. * scd/scdaemon.c (main): Likewise. -- It is simply the best for nPth not to allow the daemonizing fork after npth_init, because semantics and implementations of forked child process in a threaded application is a difficult corner case. GnuPG-bug-id: 1779 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
parent
a43739a245
commit
eda17649f8
3 changed files with 52 additions and 21 deletions
|
@ -718,6 +718,29 @@ finalize_rereadable_options (void)
|
|||
}
|
||||
|
||||
|
||||
static void
|
||||
thread_init_once (void)
|
||||
{
|
||||
static int npth_initialized = 0;
|
||||
|
||||
if (!npth_initialized)
|
||||
{
|
||||
npth_initialized++;
|
||||
npth_init ();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
initialize_modules (void)
|
||||
{
|
||||
thread_init_once ();
|
||||
assuan_set_system_hooks (ASSUAN_SYSTEM_NPTH);
|
||||
initialize_module_cache ();
|
||||
initialize_module_call_pinentry ();
|
||||
initialize_module_call_scd ();
|
||||
initialize_module_trustlist ();
|
||||
}
|
||||
|
||||
|
||||
/* The main entry point. */
|
||||
int
|
||||
|
@ -765,14 +788,11 @@ main (int argc, char **argv )
|
|||
i18n_init ();
|
||||
init_common_subsystems (&argc, &argv);
|
||||
|
||||
npth_init ();
|
||||
|
||||
malloc_hooks.malloc = gcry_malloc;
|
||||
malloc_hooks.realloc = gcry_realloc;
|
||||
malloc_hooks.free = gcry_free;
|
||||
assuan_set_malloc_hooks (&malloc_hooks);
|
||||
assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT);
|
||||
assuan_set_system_hooks (ASSUAN_SYSTEM_NPTH);
|
||||
assuan_sock_init ();
|
||||
setup_libassuan_logging (&opt.debug, NULL);
|
||||
|
||||
|
@ -1080,16 +1100,12 @@ main (int argc, char **argv )
|
|||
exit (1);
|
||||
}
|
||||
|
||||
initialize_module_cache ();
|
||||
initialize_module_call_pinentry ();
|
||||
initialize_module_call_scd ();
|
||||
initialize_module_trustlist ();
|
||||
|
||||
/* Try to create missing directories. */
|
||||
create_directories ();
|
||||
|
||||
if (debug_wait && pipe_server)
|
||||
{
|
||||
thread_init_once ();
|
||||
log_debug ("waiting for debugger - my pid is %u .....\n",
|
||||
(unsigned int)getpid());
|
||||
gnupg_sleep (debug_wait);
|
||||
|
@ -1196,6 +1212,8 @@ main (int argc, char **argv )
|
|||
/* This is the simple pipe based server */
|
||||
ctrl_t ctrl;
|
||||
|
||||
initialize_modules ();
|
||||
|
||||
ctrl = xtrycalloc (1, sizeof *ctrl);
|
||||
if (!ctrl)
|
||||
{
|
||||
|
@ -1403,6 +1421,8 @@ main (int argc, char **argv )
|
|||
This is the child
|
||||
*/
|
||||
|
||||
initialize_modules ();
|
||||
|
||||
/* Detach from tty and put process into a new session */
|
||||
if (!nodetach )
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue