summaryrefslogtreecommitdiffstats
path: root/sm
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2007-06-20 13:16:42 +0200
committerWerner Koch <wk@gnupg.org>2007-06-20 13:16:42 +0200
commit09cc0ee7bebcdde9f5a40e827a9e29f9ae7fdf11 (patch)
tree7b5d692846eeed89f8c419814b791188488290fe /sm
parentMade percent_escape more general. (diff)
downloadgnupg2-09cc0ee7bebcdde9f5a40e827a9e29f9ae7fdf11.tar.xz
gnupg2-09cc0ee7bebcdde9f5a40e827a9e29f9ae7fdf11.zip
[w32] gpg-agent is now started automagically by gpgsm.
Diffstat (limited to 'sm')
-rw-r--r--sm/ChangeLog4
-rw-r--r--sm/call-agent.c89
-rw-r--r--sm/gpgsm.c2
3 files changed, 66 insertions, 29 deletions
diff --git a/sm/ChangeLog b/sm/ChangeLog
index c5d342bd2..896b5c368 100644
--- a/sm/ChangeLog
+++ b/sm/ChangeLog
@@ -1,3 +1,7 @@
+2007-06-20 Werner Koch <wk@g10code.com>
+
+ * call-agent.c (start_agent) [W32]: Start the agent on the fly.
+
2007-06-18 Marcus Brinkmann <marcus@g10code.de>
* gpgsm.c (main): Percent escape output of --gpgconf-list.
diff --git a/sm/call-agent.c b/sm/call-agent.c
index 1ac5412be..b30fe60df 100644
--- a/sm/call-agent.c
+++ b/sm/call-agent.c
@@ -37,7 +37,8 @@
#include "i18n.h"
#include "asshelp.h"
#include "keydb.h" /* fixme: Move this to import.c */
-#include "../common/membuf.h"
+#include "membuf.h"
+#include "exechelp.h"
static assuan_context_t agent_ctx = NULL;
@@ -83,21 +84,12 @@ start_agent (ctrl_t ctrl)
infostr = force_pipe_server? NULL : getenv ("GPG_AGENT_INFO");
if (!infostr || !*infostr)
{
- const char *pgmname;
- const char *argv[3];
char *sockname;
- int no_close_list[3];
- int i;
/* First check whether we can connect at the standard
socket. */
sockname = make_filename (opt.homedir, "S.gpg-agent", NULL);
rc = assuan_socket_connect (&ctx, sockname, 0);
- xfree (sockname);
-#ifdef HAVE_W32_SYSTEM
-# warning Print a warning if connecting is not possible
- /* and offer to fire up the agent. */
-#endif
if (rc)
{
@@ -112,30 +104,71 @@ start_agent (ctrl_t ctrl)
gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno));
log_error ("error flushing pending output: %s\n",
strerror (errno));
+ xfree (sockname);
return tmperr;
}
if (!opt.agent_program || !*opt.agent_program)
opt.agent_program = gnupg_module_name (GNUPG_MODULE_NAME_AGENT);
- if ( !(pgmname = strrchr (opt.agent_program, '/')))
- pgmname = opt.agent_program;
- else
- pgmname++;
-
- argv[0] = pgmname;
- argv[1] = "--server";
- argv[2] = NULL;
-
- i=0;
- if (log_get_fd () != -1)
- no_close_list[i++] = log_get_fd ();
- no_close_list[i++] = fileno (stderr);
- no_close_list[i] = -1;
-
- /* Connect to the agent and perform initial handshaking. */
- rc = assuan_pipe_connect (&ctx, opt.agent_program, argv,
- no_close_list);
+
+#ifdef HAVE_W32_SYSTEM
+ {
+ /* Under Windows we start the server in daemon mode. This
+ is because the default is to use the standard socket
+ and thus there is no need for the GPG_AGENT_INFO
+ envvar. This is possible as we don't have a real unix
+ domain socket but use a plain file and thus there is no
+ need to care about non-local file systems. */
+ const char *argv[3];
+
+ /* The --no-reuse-standard option makes sure that we don't
+ start a second instance of a agent in case another
+ process has started one in the meantime. */
+ argv[0] = "--daemon";
+ argv[1] = "--no-reuse-standard-socket";
+ argv[2] = NULL;
+
+ rc = gnupg_spawn_process_detached (opt.agent_program, argv, NULL);
+ if (rc)
+ log_debug ("failed to start agent `%s': %s\n",
+ opt.agent_program, gpg_strerror (rc));
+ else
+ {
+ /* Give the agent some time to prepare itself. */
+ gnupg_sleep (3);
+ /* Now try again to connect the agent. */
+ rc = assuan_socket_connect (&ctx, sockname, 0);
+ }
+ }
+#else /*!HAVE_W32_SYSTEM*/
+ {
+ const char *pgmname;
+ const char *argv[3];
+ int no_close_list[3];
+ int i;
+
+ if ( !(pgmname = strrchr (opt.agent_program, '/')))
+ pgmname = opt.agent_program;
+ else
+ pgmname++;
+
+ argv[0] = pgmname;
+ argv[1] = "--server";
+ argv[2] = NULL;
+
+ i=0;
+ if (log_get_fd () != -1)
+ no_close_list[i++] = log_get_fd ();
+ no_close_list[i++] = fileno (stderr);
+ no_close_list[i] = -1;
+
+ /* Connect to the agent and perform initial handshaking. */
+ rc = assuan_pipe_connect (&ctx, opt.agent_program, argv,
+ no_close_list);
+ }
+#endif /*!HAVE_W32_SYSTEM*/
}
+ xfree (sockname);
}
else
{
diff --git a/sm/gpgsm.c b/sm/gpgsm.c
index f6d2b8444..b6a3e69c2 100644
--- a/sm/gpgsm.c
+++ b/sm/gpgsm.c
@@ -1438,7 +1438,7 @@ main ( int argc, char **argv)
{
log_debug ("waiting for debugger - my pid is %u .....\n",
(unsigned int)getpid());
- sleep (debug_wait);
+ gnupg_sleep (debug_wait);
log_debug ("... okay\n");
}
gpgsm_server (recplist);