chiark / gitweb /
gpg-agent connection count: Abstract away all direct accesses
[gnupg2.git] / agent / gpg-agent.c
index 0e53549479f56044d4b26a9de2482193a41ceddd..8ca6d92b5404909a34702de2defa4f61e01c26d1 100644 (file)
@@ -1995,6 +1995,13 @@ get_agent_active_connection_count (void)
   return active_connections;
 }
 
+/* Increment/decrement the number of active connections. */
+static void
+adjust_agent_active_connections (int delta)
+{
+  active_connections += delta;
+}
+
 
 /* Under W32, this function returns the handle of the scdaemon
    notification event.  Calling it the first time creates that
@@ -2378,7 +2385,7 @@ handle_signal (int signo)
         log_info ("SIGTERM received - shutting down ...\n");
       else
         log_info ("SIGTERM received - still %i open connections\n",
-                 active_connections);
+                 get_agent_active_connection_count());
       shutdown_pending++;
       if (shutdown_pending > 2)
         {
@@ -2613,7 +2620,7 @@ putty_message_thread (void *arg)
 static void *
 do_start_connection_thread (ctrl_t ctrl)
 {
-  active_connections++;
+  adjust_agent_active_connections(+1);
   agent_init_default_ctrl (ctrl);
   if (opt.verbose && !DBG_IPC)
     log_info (_("handler 0x%lx for fd %d started\n"),
@@ -2626,7 +2633,7 @@ do_start_connection_thread (ctrl_t ctrl)
 
   agent_deinit_default_ctrl (ctrl);
   xfree (ctrl);
-  active_connections--;
+  adjust_agent_active_connections(-1);
   return NULL;
 }
 
@@ -2693,7 +2700,7 @@ start_connection_thread_ssh (void *arg)
   if (check_nonce (ctrl, &socket_nonce_ssh))
     return NULL;
 
-  active_connections++;
+  adjust_agent_active_connections(+1);
   agent_init_default_ctrl (ctrl);
   if (opt.verbose)
     log_info (_("ssh handler 0x%lx for fd %d started\n"),
@@ -2706,7 +2713,7 @@ start_connection_thread_ssh (void *arg)
 
   agent_deinit_default_ctrl (ctrl);
   xfree (ctrl);
-  active_connections--;
+  adjust_agent_active_connections(-1);
   return NULL;
 }
 
@@ -2869,7 +2876,7 @@ handle_connections (gnupg_fd_t listen_fd,
       /* Shutdown test.  */
       if (shutdown_pending)
         {
-          if (active_connections == 0)
+          if (get_agent_active_connection_count() == 0)
             break; /* ready */
 
           /* Do not accept new connections but keep on running the