From 0c2bfd9d5a49a6134188f8f7820f6ccdebd9f181 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 28 Jan 2015 19:57:22 +0100 Subject: [PATCH] Add a hook to be called right after main. * common/init.c (early_system_init): New stub function. Signed-off-by: Werner Koch --- agent/gpg-agent.c | 2 ++ agent/preset-passphrase.c | 1 + agent/protect-tool.c | 1 + common/init.c | 7 +++++++ common/init.h | 1 + dirmngr/dirmngr-client.c | 2 ++ dirmngr/dirmngr.c | 2 ++ dirmngr/dirmngr_ldap.c | 2 ++ g10/gpg.c | 1 + g10/gpgv.c | 1 + g13/g13.c | 1 + kbx/kbxutil.c | 1 + scd/scdaemon.c | 1 + sm/gpgsm.c | 1 + tools/gpg-check-pattern.c | 1 + tools/gpg-connect-agent.c | 1 + tools/gpgconf.c | 1 + tools/symcryptrun.c | 1 + 18 files changed, 28 insertions(+) diff --git a/agent/gpg-agent.c b/agent/gpg-agent.c index fe310f490..a874e76c2 100644 --- a/agent/gpg-agent.c +++ b/agent/gpg-agent.c @@ -665,6 +665,8 @@ main (int argc, char **argv ) gpg_error_t err; struct assuan_malloc_hooks malloc_hooks; + early_system_init (); + /* Before we do anything else we save the list of currently open file descriptors and the signal mask. This info is required to do the exec call properly. */ diff --git a/agent/preset-passphrase.c b/agent/preset-passphrase.c index ad8e50047..6378d7a56 100644 --- a/agent/preset-passphrase.c +++ b/agent/preset-passphrase.c @@ -212,6 +212,7 @@ main (int argc, char **argv) int cmd = 0; const char *keygrip = NULL; + early_system_init (); set_strusage (my_strusage); log_set_prefix ("gpg-preset-passphrase", 1); diff --git a/agent/protect-tool.c b/agent/protect-tool.c index 5e540cf00..dc363f2ca 100644 --- a/agent/protect-tool.c +++ b/agent/protect-tool.c @@ -549,6 +549,7 @@ main (int argc, char **argv ) int cmd = 0; const char *fname; + early_system_init (); set_strusage (my_strusage); gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN); log_set_prefix ("gpg-protect-tool", 1); diff --git a/common/init.c b/common/init.c index 2d5d6301c..c68a4e631 100644 --- a/common/init.c +++ b/common/init.c @@ -133,6 +133,13 @@ writestring_via_estream (int mode, const char *string) } +/* This function should be the first called after main. */ +void +early_system_init (void) +{ +} + + /* This function is to be used early at program startup to make sure that some subsystems are initialized. This is in particular important for W32 to initialize the sockets so that our socket diff --git a/common/init.h b/common/init.h index eea2eb167..530a4797c 100644 --- a/common/init.h +++ b/common/init.h @@ -38,6 +38,7 @@ void register_mem_cleanup_func (void (*func)(void)); +void early_system_init (void); void _init_common_subsystems (gpg_err_source_t errsource, int *argcp, char ***argvp); #define init_common_subsystems(a,b) \ diff --git a/dirmngr/dirmngr-client.c b/dirmngr/dirmngr-client.c index 0e627642d..770e941a4 100644 --- a/dirmngr/dirmngr-client.c +++ b/dirmngr/dirmngr-client.c @@ -40,6 +40,7 @@ #include "i18n.h" #include "util.h" +#include "init.h" /* Constants for the options. */ @@ -180,6 +181,7 @@ main (int argc, char **argv ) int cmd_loadcrl = 0; int cmd_squid_mode = 0; + early_system_init (); set_strusage (my_strusage); log_set_prefix ("dirmngr-client", JNLIB_LOG_WITH_PREFIX); diff --git a/dirmngr/dirmngr.c b/dirmngr/dirmngr.c index d3424c19e..a46f736a7 100644 --- a/dirmngr/dirmngr.c +++ b/dirmngr/dirmngr.c @@ -650,6 +650,8 @@ main (int argc, char **argv) int homedir_seen = 0; struct assuan_malloc_hooks malloc_hooks; + early_system_init (); + #ifdef USE_W32_SERVICE /* The option will be set by main() below if we should run as a system daemon. */ diff --git a/dirmngr/dirmngr_ldap.c b/dirmngr/dirmngr_ldap.c index daa2d1bcb..981b5ccf1 100644 --- a/dirmngr/dirmngr_ldap.c +++ b/dirmngr/dirmngr_ldap.c @@ -242,6 +242,8 @@ ldap_wrapper_main (char **argv, estream_t outstream) memset (&my_opt_buffer, 0, sizeof my_opt_buffer); + early_system_init (); + #ifdef USE_LDAPWRAPPER set_strusage (my_strusage); log_set_prefix ("dirmngr_ldap", JNLIB_LOG_WITH_PREFIX); diff --git a/g10/gpg.c b/g10/gpg.c index 2047e306d..5e929d985 100644 --- a/g10/gpg.c +++ b/g10/gpg.c @@ -2048,6 +2048,7 @@ main (int argc, char **argv) /* Please note that we may running SUID(ROOT), so be very CAREFUL when adding any stuff between here and the call to secmem_init() somewhere after the option parsing. */ + early_system_init (); gnupg_reopen_std (GPG_NAME); trap_unaligned (); gnupg_rl_initialize (); diff --git a/g10/gpgv.c b/g10/gpgv.c index f09b5da87..157fdea45 100644 --- a/g10/gpgv.c +++ b/g10/gpgv.c @@ -144,6 +144,7 @@ main( int argc, char **argv ) unsigned configlineno; ctrl_t ctrl; + early_system_init (); set_strusage (my_strusage); log_set_prefix ("gpgv", 1); diff --git a/g13/g13.c b/g13/g13.c index 86821144d..157e6465d 100644 --- a/g13/g13.c +++ b/g13/g13.c @@ -344,6 +344,7 @@ main ( int argc, char **argv) /*mtrace();*/ + early_system_init (); gnupg_reopen_std (G13_NAME); set_strusage (my_strusage); gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN); diff --git a/kbx/kbxutil.c b/kbx/kbxutil.c index 34cbc5394..368c02d22 100644 --- a/kbx/kbxutil.c +++ b/kbx/kbxutil.c @@ -452,6 +452,7 @@ main( int argc, char **argv ) unsigned long from = 0, to = ULONG_MAX; int dry_run = 0; + early_system_init (); set_strusage( my_strusage ); gcry_control (GCRYCTL_DISABLE_SECMEM); log_set_prefix ("kbxutil", 1); diff --git a/scd/scdaemon.c b/scd/scdaemon.c index 7c786c2c4..d0777e80f 100644 --- a/scd/scdaemon.c +++ b/scd/scdaemon.c @@ -411,6 +411,7 @@ main (int argc, char **argv ) int res; npth_t pipecon_handler; + early_system_init (); set_strusage (my_strusage); gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN); /* Please note that we may running SUID(ROOT), so be very CAREFUL diff --git a/sm/gpgsm.c b/sm/gpgsm.c index 72bceb433..62e29b86f 100644 --- a/sm/gpgsm.c +++ b/sm/gpgsm.c @@ -910,6 +910,7 @@ main ( int argc, char **argv) /*mtrace();*/ + early_system_init (); gnupg_reopen_std (GPGSM_NAME); /* trap_unaligned ();*/ gnupg_rl_initialize (); diff --git a/tools/gpg-check-pattern.c b/tools/gpg-check-pattern.c index 2db9ae53f..e76f12140 100644 --- a/tools/gpg-check-pattern.c +++ b/tools/gpg-check-pattern.c @@ -164,6 +164,7 @@ main (int argc, char **argv ) size_t raw_pattern_length; pattern_t *patternarray; + early_system_init (); set_strusage (my_strusage); gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN); log_set_prefix ("gpg-check-pattern", 1); diff --git a/tools/gpg-connect-agent.c b/tools/gpg-connect-agent.c index 1d9bb665d..f1d123ffa 100644 --- a/tools/gpg-connect-agent.c +++ b/tools/gpg-connect-agent.c @@ -1169,6 +1169,7 @@ main (int argc, char **argv) int loopidx; char **cmdline_commands = NULL; + early_system_init (); gnupg_rl_initialize (); set_strusage (my_strusage); log_set_prefix ("gpg-connect-agent", 1); diff --git a/tools/gpgconf.c b/tools/gpgconf.c index 423a66c71..180c88adf 100644 --- a/tools/gpgconf.c +++ b/tools/gpgconf.c @@ -151,6 +151,7 @@ main (int argc, char **argv) enum cmd_and_opt_values cmd = 0; estream_t outfp = NULL; + early_system_init (); gnupg_reopen_std (GPGCONF_NAME); set_strusage (my_strusage); log_set_prefix (GPGCONF_NAME, 1); diff --git a/tools/symcryptrun.c b/tools/symcryptrun.c index 4873d7690..c7fc5b6b3 100644 --- a/tools/symcryptrun.c +++ b/tools/symcryptrun.c @@ -889,6 +889,7 @@ main (int argc, char **argv) char *logfile = NULL; int default_config = 1; + early_system_init (); set_strusage (my_strusage); log_set_prefix ("symcryptrun", 1);