summaryrefslogtreecommitdiffstats
path: root/agent
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2007-11-27 09:01:19 +0100
committerWerner Koch <wk@gnupg.org>2007-11-27 09:01:19 +0100
commit598a3d0ab4a401f929c03d08cea5c272bf49abda (patch)
tree3c1e527c7fc15b8da3599d81832e195a0fbde3c2 /agent
parentAdd option --data to GETAUDITLOG command. (diff)
downloadgnupg2-598a3d0ab4a401f929c03d08cea5c272bf49abda.tar.xz
gnupg2-598a3d0ab4a401f929c03d08cea5c272bf49abda.zip
[W32] Changed default socket for dirmngr.
[W32] Add some code for event notifications between scdaemon and gpg-agent.
Diffstat (limited to 'agent')
-rw-r--r--agent/ChangeLog12
-rw-r--r--agent/agent.h3
-rw-r--r--agent/call-scd.c17
-rw-r--r--agent/command.c4
-rw-r--r--agent/gpg-agent.c64
5 files changed, 84 insertions, 16 deletions
diff --git a/agent/ChangeLog b/agent/ChangeLog
index 7a4716c3d..adb278868 100644
--- a/agent/ChangeLog
+++ b/agent/ChangeLog
@@ -1,3 +1,15 @@
+2007-11-20 Werner Koch <wk@g10code.com>
+
+ * gpg-agent.c (get_agent_scd_notify_event): New.
+ (handle_signal): Factor SIGUSR2 code out to:
+ (agent_sigusr2_action): .. New.
+ (agent_sighup_action): Print info message here and not in
+ handle_signal.
+ (handle_connections) [PTH_EVENT_HANDLE]: Call agent_sigusr2_action.
+
+ * call-scd.c (agent_scd_check_aliveness) [W32]: Implemented.
+ (start_scd) [W32]: Send event-signal option.
+
2007-11-19 Werner Koch <wk@g10code.com>
* call-pinentry.c (agent_askpin): Set the tooltip for the quality
diff --git a/agent/agent.h b/agent/agent.h
index beb70111e..f824fe615 100644
--- a/agent/agent.h
+++ b/agent/agent.h
@@ -205,6 +205,9 @@ cache_mode_t;
void agent_exit (int rc) JNLIB_GCC_A_NR; /* Also implemented in other tools */
const char *get_agent_socket_name (void);
const char *get_agent_ssh_socket_name (void);
+#ifdef HAVE_W32_SYSTEM
+void *get_agent_scd_notify_event (void);
+#endif
void agent_sighup_action (void);
/*-- command.c --*/
diff --git a/agent/call-scd.c b/agent/call-scd.c
index 42f3f8e12..872ba3433 100644
--- a/agent/call-scd.c
+++ b/agent/call-scd.c
@@ -374,14 +374,17 @@ start_scd (ctrl_t ctrl)
}
/* Tell the scdaemon we want him to send us an event signal. */
-#ifndef HAVE_W32_SYSTEM
{
char buf[100];
- sprintf (buf, "OPTION event-signal=%d", SIGUSR2);
+#ifdef HAVE_W32_SYSTEM
+ snprintf (buf, sizeof buf, "OPTION event-signal=%lx",
+ (unsigned long)get_agent_scd_notify_event ());
+#else
+ snprintf (buf, sizeof buf, "OPTION event-signal=%d", SIGUSR2);
+#endif
assuan_transact (ctx, buf, NULL, NULL, NULL, NULL, NULL, NULL);
}
-#endif
primary_scd_ctx = ctx;
primary_scd_ctx_reusable = 0;
@@ -408,6 +411,9 @@ agent_scd_check_aliveness (void)
pth_event_t evt;
pid_t pid;
int rc;
+#ifdef HAVE_W32_SYSTEM
+ DWORD dummyec;
+#endif
if (!primary_scd_ctx)
return; /* No scdaemon running. */
@@ -435,10 +441,12 @@ agent_scd_check_aliveness (void)
{
pid = assuan_get_pid (primary_scd_ctx);
#ifdef HAVE_W32_SYSTEM
-#warning Need to implement an alive test for scdaemon
+ if (pid != (pid_t)(void*)(-1) && pid
+ && !GetExitCodeProcess ((HANDLE)pid, &dummyec))
#else
if (pid != (pid_t)(-1) && pid
&& ((rc=waitpid (pid, NULL, WNOHANG))==-1 || (rc == pid)) )
+#endif
{
/* Okay, scdaemon died. Disconnect the primary connection
now but take care that it won't do another wait. Also
@@ -467,7 +475,6 @@ agent_scd_check_aliveness (void)
xfree (socket_name);
socket_name = NULL;
}
-#endif
}
if (!pth_mutex_release (&start_scd_lock))
diff --git a/agent/command.c b/agent/command.c
index c0c21bf79..91279fa0f 100644
--- a/agent/command.c
+++ b/agent/command.c
@@ -353,7 +353,7 @@ cmd_geteventcounter (assuan_context_t ctx, char *line)
/* This function should be called once for all key removals or
- additions. Thus function is assured not to do any context
+ additions. This function is assured not to do any context
switches. */
void
bump_key_eventcounter (void)
@@ -363,7 +363,7 @@ bump_key_eventcounter (void)
}
/* This function should be called for all card reader status
- changes. Thus function is assured not to do any context
+ changes. This function is assured not to do any context
switches. */
void
bump_card_eventcounter (void)
diff --git a/agent/gpg-agent.c b/agent/gpg-agent.c
index e4d8f3e13..48087db63 100644
--- a/agent/gpg-agent.c
+++ b/agent/gpg-agent.c
@@ -1246,6 +1246,28 @@ get_agent_ssh_socket_name (void)
}
+/* Under W32, this function returns the handle of the scdaemon
+ notification event. Calling it the first time creates that
+ event. */
+#ifdef HAVE_W32_SYSTEM
+void *
+get_agent_scd_notify_event (void)
+{
+ static HANDLE the_event;
+
+ if (!the_event)
+ {
+ SECURITY_ATTRIBUTES sa = { sizeof (SECURITY_ATTRIBUTES), NULL, TRUE};
+
+ the_event = CreateEvent ( &sa, FALSE, FALSE, NULL);
+ if (!the_event)
+ log_error ("can't create scd notify event: %s\n", w32_strerror (-1) );
+ }
+ return the_event;
+}
+#endif /*HAVE_W32_SYSTEM*/
+
+
/* Create a name for the socket. With USE_STANDARD_SOCKET given as
true using STANDARD_NAME in the home directory or if given as
@@ -1486,11 +1508,13 @@ handle_tick (void)
}
-/* A global fucntion which allows us to call the reload stuff from
- other palces too. This is only used when build for W32. */
+/* A global function which allows us to call the reload stuff from
+ other places too. This is only used when build for W32. */
void
agent_sighup_action (void)
{
+ log_info ("SIGHUP received - "
+ "re-reading configuration and flushing cache\n");
agent_flush_cache ();
reread_configuration ();
agent_reload_trustlist ();
@@ -1498,14 +1522,22 @@ agent_sighup_action (void)
static void
+agent_sigusr2_action (void)
+{
+ if (opt.verbose)
+ log_info ("SIGUSR2 received - checking smartcard status\n");
+ /* Nothing to check right now. We only increment a counter. */
+ bump_card_eventcounter ();
+}
+
+
+static void
handle_signal (int signo)
{
switch (signo)
{
#ifndef HAVE_W32_SYSTEM
case SIGHUP:
- log_info ("SIGHUP received - "
- "re-reading configuration and flushing cache\n");
agent_sighup_action ();
break;
@@ -1517,10 +1549,7 @@ handle_signal (int signo)
break;
case SIGUSR2:
- if (opt.verbose)
- log_info ("SIGUSR2 received - checking smartcard status\n");
- /* Nothing to check right now. We only increment a counter. */
- bump_card_eventcounter ();
+ agent_sigusr2_action ();
break;
case SIGTERM:
@@ -1652,8 +1681,15 @@ handle_connections (gnupg_fd_t listen_fd, gnupg_fd_t listen_fd_ssh)
pth_sigmask (SIG_UNBLOCK, &sigs, NULL);
ev = pth_event (PTH_EVENT_SIGS, &sigs, &signo);
#else
+# ifdef PTH_EVENT_HANDLE
+ sigs = 0;
+ ev = pth_event (PTH_EVENT_HANDLE, get_agent_scd_notify_event ());
+ signo = 0;
+# else
+ /* Use a dummy event. */
sigs = 0;
ev = pth_event (PTH_EVENT_SIGS, &sigs, &signo);
+# endif
#endif
time_ev = NULL;
@@ -1706,7 +1742,13 @@ handle_connections (gnupg_fd_t listen_fd, gnupg_fd_t listen_fd_ssh)
|| (time_ev && pth_event_occurred (time_ev)))
{
if (pth_event_occurred (ev))
- handle_signal (signo);
+ {
+#if defined(HAVE_W32_SYSTEM) && defined(PTH_EVENT_HANDLE)
+ agent_sigusr2_action ();
+#else
+ handle_signal (signo);
+#endif
+ }
if (time_ev && pth_event_occurred (time_ev))
{
pth_event_free (time_ev, PTH_FREE_ALL);
@@ -1723,7 +1765,11 @@ handle_connections (gnupg_fd_t listen_fd, gnupg_fd_t listen_fd_ssh)
if (pth_event_occurred (ev))
{
+#if defined(HAVE_W32_SYSTEM) && defined(PTH_EVENT_HANDLE)
+ agent_sigusr2_action ();
+#else
handle_signal (signo);
+#endif
}
if (time_ev && pth_event_occurred (time_ev))