[svn] gpgme - r1262 - in trunk: . assuan gpgme

svn author marcus cvs at cvs.gnupg.org
Thu Sep 27 13:06:32 CEST 2007


Author: marcus
Date: 2007-09-27 13:06:23 +0200 (Thu, 27 Sep 2007)
New Revision: 1262

Modified:
   trunk/ChangeLog
   trunk/assuan/assuan-pipe-connect.c
   trunk/gpgme/rungpg.c
Log:
2007-09-27  Marcus Brinkmann  <marcus at g10code.de>

	* assuan-pipe-connect.c (pipe_connect_gpgme): New function, use it
	if _ASSUAN_IN_GPGME_BUILD_ASSUAN.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-09-25 16:35:36 UTC (rev 1261)
+++ trunk/ChangeLog	2007-09-27 11:06:23 UTC (rev 1262)
@@ -1,3 +1,8 @@
+2007-09-27  Marcus Brinkmann  <marcus at g10code.de>
+
+	* assuan-pipe-connect.c (pipe_connect_gpgme): New function, use it
+	if _ASSUAN_IN_GPGME_BUILD_ASSUAN.
+
 2007-09-17  Werner Koch  <wk at g10code.com>
 
 	* configure.ac: Use the svn version magic.

Modified: trunk/assuan/assuan-pipe-connect.c
===================================================================
--- trunk/assuan/assuan-pipe-connect.c	2007-09-25 16:35:36 UTC (rev 1261)
+++ trunk/assuan/assuan-pipe-connect.c	2007-09-27 11:06:23 UTC (rev 1262)
@@ -550,6 +550,108 @@
 
 
 
+#ifdef _ASSUAN_IN_GPGME_BUILD_ASSUAN
+
+#define pipe_connect pipe_connect_gpgme
+
+/* From GPGME priv-io.h  */
+struct spawn_fd_item_s
+{
+  int fd;
+  int dup_to;
+};
+
+/* W32 version of the pipe connection code. */
+static assuan_error_t
+pipe_connect_gpgme (assuan_context_t *ctx,
+		    const char *name, const char *const argv[],
+		    int *fd_child_list,
+		    void (*atfork) (void *opaque, int reserved),
+		    void *atforkvalue)
+{
+  assuan_error_t err;
+  int pid;
+int rp[2];
+  int wp[2];
+  char mypidstr[50];
+  struct spawn_fd_item_s child_fds[3]; /* stdin, stdout, terminating -1 */
+
+  if (!ctx || !name || !argv || !argv[0])
+    return _assuan_error (ASSUAN_Invalid_Value);
+
+  /* Actually, GPGME does this for us.  But we plan to reuse this code
+     in the generic assuan.  */
+  fix_signals ();
+
+  sprintf (mypidstr, "%lu", (unsigned long)getpid ());
+
+  /* Create the two pipes. */
+  if (_gpgme_io_pipe (rp, 0))
+    return _assuan_error (ASSUAN_General_Error);
+  
+  if (_gpgme_io_pipe (wp, 1))
+    {
+      _gpgme_io_close (rp[0]);
+      _gpgme_io_close (rp[1]);
+      return _assuan_error (ASSUAN_General_Error);
+    }
+
+  err = _assuan_new_context (ctx);
+  if (err)
+    {
+      _gpgme_io_close (rp[0]);
+      _gpgme_io_close (rp[1]);
+      _gpgme_io_close (wp[0]);
+      _gpgme_io_close (wp[1]);
+      return _assuan_error (ASSUAN_General_Error);
+    }
+
+  (*ctx)->pipe_mode = 1;
+  (*ctx)->inbound.fd  = rp[0];  /* Our inbound is read end of read pipe. */
+  (*ctx)->outbound.fd = wp[1];  /* Our outbound is write end of write pipe. */
+  (*ctx)->deinit_handler = do_deinit;
+  (*ctx)->finish_handler = do_finish;
+
+  /* fixme: Actually we should set the "_assuan_pipe_connect_pid" env
+     variable to mypidstr.  However this requires us to write a full
+     environment handler, because the strings are expected in sorted
+     order.  The suggestion given in the MS Reference Library, to save
+     the old value, changeit, create proces and restore it, is not
+     thread safe.  */
+
+  /* Parent list is same as client list.  Note that GPGME will dup nul
+     to stderr even if the caller wants to inherit the handle for
+     it.  */
+  /* Server stdout is its write end of our read pipe.  */
+  child_fds[0].fd = rp[1];
+  child_fds[0].dup_to = 1;
+  /* Server stdin is its read end of our write pipe.  */
+  child_fds[1].fd = wp[0];
+  child_fds[1].dup_to = 0;
+  child_fds[2].fd = -1;
+
+  /* Start the process.  */
+  pid = _gpgme_io_spawn (name, argv, child_fds, child_fds);
+  if (pid == -1)
+    {
+      _assuan_log_printf ("CreateProcess failed: %s\n", strerror (errno));
+      _gpgme_io_close (rp[0]);
+      _gpgme_io_close (rp[1]);
+      _gpgme_io_close (wp[0]);
+      _gpgme_io_close (wp[1]);
+      return _assuan_error (ASSUAN_General_Error);
+    }
+
+  /* ERR contains the PID.  */
+  (*ctx)->pid = 0;  /* We don't use the PID. */
+
+  /* FIXME: Should be done by GPGME.  */
+  CloseHandle ((HANDLE) pid); /* We don't need to wait for the process. */
+
+  return initial_handshake (ctx);
+}
+
+#else
 #ifdef HAVE_W32_SYSTEM
 /* Build a command line for use with W32's CreateProcess.  On success
    CMDLINE gets the address of a newly allocated string.  */
@@ -648,9 +750,8 @@
   filedes[1] = handle_to_fd (w);
   return 0;
 }
-#endif /*HAVE_W32_SYSTEM*/
+#endif /* HAVE_W32_SYSTEM */
 
-
 #ifdef HAVE_W32_SYSTEM
 #define pipe_connect pipe_connect_w32
 /* W32 version of the pipe connection code. */
@@ -832,6 +933,7 @@
   return initial_handshake (ctx);
 }
 #endif /*HAVE_W32_SYSTEM*/
+#endif /* !_ASSUAN_IN_GPGME_BUILD_ASSUAN */ 
 
 
 /* Connect to a server over a pipe, creating the assuan context and

Modified: trunk/gpgme/rungpg.c
===================================================================
--- trunk/gpgme/rungpg.c	2007-09-25 16:35:36 UTC (rev 1261)
+++ trunk/gpgme/rungpg.c	2007-09-27 11:06:23 UTC (rev 1262)
@@ -1263,6 +1263,7 @@
 
   /* build the fd list for the child */
   n = 0;
+  /* The status fd is never dup'ed, so do not include it in the list.  */
   if (gpg->colon.fnc)
     {
       fd_child_list[n].fd = gpg->colon.fd[1]; 




More information about the Gnupg-commits mailing list