[svn] GnuPG - r4851 - in trunk: . agent jnlib scd

svn author wk cvs at cvs.gnupg.org
Wed Oct 15 15:23:10 CEST 2008


Author: wk
Date: 2008-10-15 15:23:10 +0200 (Wed, 15 Oct 2008)
New Revision: 4851

Modified:
   trunk/NEWS
   trunk/agent/ChangeLog
   trunk/agent/call-scd.c
   trunk/jnlib/ChangeLog
   trunk/jnlib/logging.c
   trunk/scd/ChangeLog
   trunk/scd/apdu.c
   trunk/scd/command.c
   trunk/scd/scdaemon.c
   trunk/scd/scdaemon.h
Log:
Made scdaemon more robust on Windows.


Modified: trunk/agent/ChangeLog
===================================================================
--- trunk/agent/ChangeLog	2008-10-14 18:18:21 UTC (rev 4850)
+++ trunk/agent/ChangeLog	2008-10-15 13:23:10 UTC (rev 4851)
@@ -1,3 +1,8 @@
+2008-10-15  Werner Koch  <wk at g10code.com>
+
+	* call-scd.c (start_scd): Enable assuan loggging if requested.
+	(agent_scd_check_aliveness) [W32]: Fix use of GetExitCodeProcess.
+
 2008-10-14  Werner Koch  <wk at g10code.com>
 
 	* gpg-agent.c (get_agent_scd_notify_event): Need to use a manual

Modified: trunk/jnlib/ChangeLog
===================================================================
--- trunk/jnlib/ChangeLog	2008-10-14 18:18:21 UTC (rev 4850)
+++ trunk/jnlib/ChangeLog	2008-10-15 13:23:10 UTC (rev 4851)
@@ -1,3 +1,7 @@
+2008-10-15  Werner Koch  <wk at g10code.com>
+
+	* logging.c (do_logv) [W32]: Flush the log stream.
+
 2008-09-29  Werner Koch  <wk at g10code.com>
 
 	* argparse.c (ARGERR_): Use constants for error values.

Modified: trunk/scd/ChangeLog
===================================================================
--- trunk/scd/ChangeLog	2008-10-14 18:18:21 UTC (rev 4850)
+++ trunk/scd/ChangeLog	2008-10-15 13:23:10 UTC (rev 4851)
@@ -1,3 +1,12 @@
+2008-10-15  Werner Koch  <wk at g10code.com>
+
+	* command.c (scd_command_handler): Return true if there is no more
+	active session.
+	* scdaemon.c (start_connection_thread): Set shutdown flag if
+	requested by command handler.
+	(main): Make PIPE_SERVER module global.
+	(handle_connections): Disable listen_fd if a shutdown is pending.
+
 2008-10-14  Werner Koch  <wk at g10code.com>
 
 

Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2008-10-14 18:18:21 UTC (rev 4850)
+++ trunk/NEWS	2008-10-15 13:23:10 UTC (rev 4851)
@@ -20,7 +20,7 @@
 
  * [gpgsm] Made --output option work with --export-secret-key-p12.
 
- * gpg-connect-agent accepts commands given as command line arguments.
+ * [gpg-connect-agent] Accept commands given as command line arguments.
 
  * [gpg] The option --fixed-list-mode is now implicitly used and obsolete.
 
@@ -35,6 +35,8 @@
 
  * Support for version 2 OpenPGP cards.
 
+ * [scdaemon] Made it more robust on W32.
+
  * Libgcrypt 1.4 is now required.
 
 

Modified: trunk/agent/call-scd.c
===================================================================
--- trunk/agent/call-scd.c	2008-10-14 18:18:21 UTC (rev 4850)
+++ trunk/agent/call-scd.c	2008-10-15 13:23:10 UTC (rev 4851)
@@ -343,6 +343,9 @@
   if (opt.verbose)
     log_debug ("first connection to SCdaemon established\n");
 
+  if (DBG_ASSUAN)
+    assuan_set_log_stream (ctx, log_get_stream ());
+
   /* Get the name of the additional socket opened by scdaemon. */
   {
     membuf_t data;
@@ -412,9 +415,10 @@
 {
   pth_event_t evt;
   pid_t pid;
+#ifdef HAVE_W32_SYSTEM
+  DWORD rc;
+#else
   int rc;
-#ifdef HAVE_W32_SYSTEM
-  DWORD dummyec;
 #endif
 
   if (!primary_scd_ctx)
@@ -443,8 +447,11 @@
     {
       pid = assuan_get_pid (primary_scd_ctx);
 #ifdef HAVE_W32_SYSTEM
+      /* If we have a PID we disconnect if either GetExitProcessCode
+         fails or if ir returns the exit code of the scdaemon.  259 is
+         the error code for STILL_ALIVE.  */
       if (pid != (pid_t)(void*)(-1) && pid
-          && !GetExitCodeProcess ((HANDLE)pid, &dummyec))
+          && (!GetExitCodeProcess ((HANDLE)pid, &rc) || rc != 259))
 #else
       if (pid != (pid_t)(-1) && pid
           && ((rc=waitpid (pid, NULL, WNOHANG))==-1 || (rc == pid)) )

Modified: trunk/jnlib/logging.c
===================================================================
--- trunk/jnlib/logging.c	2008-10-14 18:18:21 UTC (rev 4850)
+++ trunk/jnlib/logging.c	2008-10-15 13:23:10 UTC (rev 4851)
@@ -490,6 +490,10 @@
       vfprintf(logstream,fmt,arg_ptr) ;
       if (*fmt && fmt[strlen(fmt)-1] != '\n')
         missing_lf = 1;
+#ifdef HAVE_W32_SYSTEM
+      else
+        fflush (logstream);
+#endif
     }
 
   if (level == JNLIB_LOG_FATAL)

Modified: trunk/scd/apdu.c
===================================================================
--- trunk/scd/apdu.c	2008-10-14 18:18:21 UTC (rev 4850)
+++ trunk/scd/apdu.c	2008-10-15 13:23:10 UTC (rev 4851)
@@ -2442,11 +2442,7 @@
       pcsc_api_loaded = 1;
     }
 
-#ifdef NEED_PCSC_WRAPPER
-  return open_pcsc_reader_wrapped (portstr);
-#else
   return open_pcsc_reader (portstr);
-#endif
 }
 
 

Modified: trunk/scd/command.c
===================================================================
--- trunk/scd/command.c	2008-10-14 18:18:21 UTC (rev 4850)
+++ trunk/scd/command.c	2008-10-15 13:23:10 UTC (rev 4851)
@@ -1,6 +1,6 @@
 /* command.c - SCdaemon command handler
  * Copyright (C) 2001, 2002, 2003, 2004, 2005,
- *               2007  Free Software Foundation, Inc.
+ *               2007, 2008  Free Software Foundation, Inc.
  *
  * This file is part of GnuPG.
  *
@@ -1776,8 +1776,9 @@
 
 
 /* Startup the server.  If FD is given as -1 this is simple pipe
-   server, otherwise it is a regular server. */
-void
+   server, otherwise it is a regular server.  Returns true if there
+   are no more active asessions.  */
+int
 scd_command_handler (ctrl_t ctrl, int fd)
 {
   int rc;
@@ -1872,6 +1873,9 @@
 
   /* Release the Assuan context.  */
   assuan_deinit_server (ctx);
+
+  /* If there are no more sessions return true.  */
+  return !session_list;
 }
 
 

Modified: trunk/scd/scdaemon.c
===================================================================
--- trunk/scd/scdaemon.c	2008-10-14 18:18:21 UTC (rev 4850)
+++ trunk/scd/scdaemon.c	2008-10-15 13:23:10 UTC (rev 4851)
@@ -1,6 +1,6 @@
 /* scdaemon.c  -  The GnuPG Smartcard Daemon
  * Copyright (C) 2001, 2002, 2004, 2005, 
- *               2007 Free Software Foundation, Inc.
+ *               2007, 2008 Free Software Foundation, Inc.
  *
  * This file is part of GnuPG.
  *
@@ -167,6 +167,9 @@
 /* It is possible that we are currently running under setuid permissions */
 static int maybe_setuid = 1;
 
+/* Flag telling whether we are running as a pipe server.  */
+static int pipe_server;
+
 /* Name of the communication socket */
 static char *socket_name;
 
@@ -304,7 +307,6 @@
   int default_config =1;
   int greeting = 0;
   int nogreeting = 0;
-  int pipe_server = 0;
   int multi_server = 0;
   int is_daemon = 0;
   int nodetach = 0;
@@ -1027,19 +1029,18 @@
     log_info (_("handler for fd %d started\n"),
               FD2INT(ctrl->thread_startup.fd));
 
-  scd_command_handler (ctrl, FD2INT(ctrl->thread_startup.fd));
+  /* If this is a pipe server, we request a shutdown if the command
+     hanlder asked for it.  With the next ticker event and given that
+     no other connections are running the shutdown will then
+     happen.  */
+  if (scd_command_handler (ctrl, FD2INT(ctrl->thread_startup.fd))
+      && pipe_server)
+    shutdown_pending = 1;
 
   if (opt.verbose)
     log_info (_("handler for fd %d terminated\n"),
               FD2INT (ctrl->thread_startup.fd));
 
-  /* If this thread is the pipe connection thread, flag that a
-     shutdown is required.  With the next ticker event and given that
-     no other connections are running the shutdown will then
-     happen. */
-  if (ctrl->thread_startup.fd == GNUPG_INVALID_FD)
-    shutdown_pending = 1;
-  
   scd_deinit_default_ctrl (ctrl);
   xfree (ctrl);
   return NULL;
@@ -1105,6 +1106,7 @@
              file descriptors to wait for, so that the select will be
              used to just wait on a signal or timeout event. */
           FD_ZERO (&fdset);
+          listen_fd = -1;
 	}
 
       /* Create a timeout event if needed. */

Modified: trunk/scd/scdaemon.h
===================================================================
--- trunk/scd/scdaemon.h	2008-10-14 18:18:21 UTC (rev 4850)
+++ trunk/scd/scdaemon.h	2008-10-15 13:23:10 UTC (rev 4851)
@@ -121,7 +121,7 @@
 
 /*-- command.c --*/
 void initialize_module_command (void);
-void scd_command_handler (ctrl_t, int);
+int  scd_command_handler (ctrl_t, int);
 void send_status_info (ctrl_t ctrl, const char *keyword, ...)
      GNUPG_GCC_A_SENTINEL(1);
 void scd_update_reader_status_file (void);




More information about the Gnupg-commits mailing list