From a5cd27d3f86b0e2ae0ddf8434ea36fc7b3018455 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Sun, 10 Nov 2013 16:40:37 -0500 Subject: [PATCH] Try to bind to the local socket before doing a cache push on startup. --- src/pwmd.c | 107 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 53 insertions(+), 54 deletions(-) diff --git a/src/pwmd.c b/src/pwmd.c index e3112299..670ba64a 100644 --- a/src/pwmd.c +++ b/src/pwmd.c @@ -2878,59 +2878,6 @@ main (int argc, char *argv[]) goto do_exit; /* - * Set the cache entry for a file. Prompts for the password. - */ - if (cache_push) - { - struct crypto_s *crypto = NULL; - gpg_error_t rc = init_client_crypto (&crypto); - - if (rc) - { - estatus = EXIT_FAILURE; - goto do_exit; - } - -#ifdef WITH_AGENT - if (use_agent) - { - rc = agent_set_pinentry_options (crypto->agent); - if (rc) - { - estatus = EXIT_FAILURE; - goto do_exit; - } - } -#endif - - for (opt = 0; cache_push[opt]; opt++) - { - if (!do_cache_push (cache_push[opt], crypto) && !force) - { - strv_free (cache_push); - startup_failure (); - estatus = EXIT_FAILURE; - cleanup_crypto (&crypto); - goto do_exit; - } - - cleanup_crypto_stage1 (crypto); - } - -#ifdef WITH_AGENT - if (use_agent) - (void) kill_scd (crypto->agent); -#endif - - cleanup_crypto (&crypto); - strv_free (cache_push); - log_write (!nofork ? _("Done. Daemonizing...") : - _("Done. Waiting for connections...")); - } - - config_clear_keys (); - - /* * bind() doesn't like the full pathname of the socket or any non alphanum * characters so change to the directory where the socket is wanted then * create it then change to datadir. @@ -3003,6 +2950,59 @@ main (int argc, char *argv[]) xfree (datadir); + /* + * Set the cache entry for a file. Prompts for the password. + */ + if (cache_push) + { + struct crypto_s *crypto = NULL; + gpg_error_t rc = init_client_crypto (&crypto); + + if (rc) + { + estatus = EXIT_FAILURE; + goto do_exit; + } + +#ifdef WITH_AGENT + if (use_agent) + { + rc = agent_set_pinentry_options (crypto->agent); + if (rc) + { + estatus = EXIT_FAILURE; + goto do_exit; + } + } +#endif + + for (opt = 0; cache_push[opt]; opt++) + { + if (!do_cache_push (cache_push[opt], crypto) && !force) + { + strv_free (cache_push); + startup_failure (); + estatus = EXIT_FAILURE; + cleanup_crypto (&crypto); + goto do_exit; + } + + cleanup_crypto_stage1 (crypto); + } + +#ifdef WITH_AGENT + if (use_agent) + (void) kill_scd (crypto->agent); +#endif + + cleanup_crypto (&crypto); + strv_free (cache_push); + log_write (!nofork ? _("Done. Daemonizing...") : + _("Done. Waiting for connections...")); + } + + config_clear_keys (); + if (listen (sockfd, 0) == -1) { log_write ("listen(): %s", pwmd_strerror (gpg_error_from_errno (errno))); @@ -3030,7 +3030,6 @@ main (int argc, char *argv[]) (void)test_pidfile (socketpath, socketname, buf, sizeof(buf), &pidfile, 1, mode); - cmdline = 0; pthread_key_create (&thread_name_key, free_key); pthread_setspecific (thread_name_key, str_dup ("main")); -- 2.11.4.GIT