aboutsummaryrefslogtreecommitdiffstats
path: root/sm/call-agent.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2004-12-20 16:17:25 +0000
committerWerner Koch <[email protected]>2004-12-20 16:17:25 +0000
commit581f5ddb1724f469dc7f934f5093179dfb1e05a9 (patch)
treed239f17e59f705f1b85c5cb5c2b9e1595e512e5f /sm/call-agent.c
parent(do_pth_event_free): The events are hold in a ring (diff)
downloadgnupg-581f5ddb1724f469dc7f934f5093179dfb1e05a9.tar.gz
gnupg-581f5ddb1724f469dc7f934f5093179dfb1e05a9.zip
* configure.ac: Add PATHSEP_C and PATHSEP_S. For W32 let all
directories default to c:/gnupg. Require libassuan 0.6.9. * gpg-agent.c (main) [W32]: Now that Mutexes work we can remove the pth_init kludge. (main): Add new options --[no-]use-standard-socket. (check_for_running_agent): Check whether it is running on the standard socket. * sysutils.h [W32]: Define sleep. * util.h: Add prototype for mkdtemp. * call-agent.c (start_agent): Before starting a pipe server start to connect to a server on the standard socket. Use PATHSEP * call-dirmngr.c (start_dirmngr): Use PATHSEP. * import.c: Include unistd.h for dup and close.
Diffstat (limited to 'sm/call-agent.c')
-rw-r--r--sm/call-agent.c72
1 files changed, 42 insertions, 30 deletions
diff --git a/sm/call-agent.c b/sm/call-agent.c
index 0d15a5595..0647acbb8 100644
--- a/sm/call-agent.c
+++ b/sm/call-agent.c
@@ -81,41 +81,53 @@ start_agent (ctrl_t ctrl)
{
const char *pgmname;
const char *argv[3];
+ char *sockname;
int no_close_list[3];
int i;
- if (opt.verbose)
- log_info (_("no running gpg-agent - starting one\n"));
-
- gpgsm_status (ctrl, STATUS_PROGRESS, "starting_agent ? 0 0");
+ /* 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);
- if (fflush (NULL))
+ if (rc)
{
- gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno));
- log_error ("error flushing pending output: %s\n", strerror (errno));
- return tmperr;
+ /* With no success start a new server. */
+ if (opt.verbose)
+ log_info (_("no running gpg-agent - starting one\n"));
+
+ gpgsm_status (ctrl, STATUS_PROGRESS, "starting_agent ? 0 0");
+
+ if (fflush (NULL))
+ {
+ gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno));
+ log_error ("error flushing pending output: %s\n",
+ strerror (errno));
+ return tmperr;
+ }
+
+ if (!opt.agent_program || !*opt.agent_program)
+ opt.agent_program = GNUPG_DEFAULT_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, (char**)argv,
+ no_close_list);
}
-
- if (!opt.agent_program || !*opt.agent_program)
- opt.agent_program = GNUPG_DEFAULT_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, (char**)argv,
- no_close_list);
}
else
{
@@ -123,7 +135,7 @@ start_agent (ctrl_t ctrl)
int pid;
infostr = xstrdup (infostr);
- if ( !(p = strchr (infostr, ':')) || p == infostr)
+ if ( !(p = strchr (infostr, PATHSEP_C)) || p == infostr)
{
log_error (_("malformed GPG_AGENT_INFO environment variable\n"));
xfree (infostr);