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

svn author marcus cvs at cvs.gnupg.org
Fri Jul 13 02:43:49 CEST 2007


Author: marcus
Date: 2007-07-13 02:43:17 +0200 (Fri, 13 Jul 2007)
New Revision: 1235

Modified:
   trunk/ChangeLog
   trunk/assuan/README.1st
   trunk/assuan/assuan-io.c
   trunk/gpgme/ChangeLog
   trunk/gpgme/engine-gpgsm.c
   trunk/gpgme/posix-io.c
   trunk/gpgme/priv-io.h
   trunk/gpgme/rungpg.c
   trunk/gpgme/w32-glib-io.c
   trunk/gpgme/w32-io.c
Log:
2007-07-13  Marcus Brinkmann  <marcus at g10code.de>

	* assuan/assuan-io.c (_assuan_simple_read, _assuan_simple_write):
	Always use read/write (which means _gpgme_io_read and
	_gpgme_io_write).

gpgme/
2007-07-13  Marcus Brinkmann  <marcus at g10code.de>

	* priv-io.h (_gpgme_io_set_close_notify): Change type of HANDLER
	to _gpgme_close_notify_handler.
	(_gpgme_close_notify_handler): New type.
	(_gpgme_io_dup): Remove prototype.
	* posix-io.c (notify_table, _gpgme_io_set_close_notify): Change
	type of HANDLER to _gpgme_close_notify_handler_t.
	(_gpgme_io_close): Do not close the FD if handler returns 0.
	(_gpgme_io_dup): Remove function.
	* w32-io.c (notify_table, _gpgme_io_set_close_notify,
	_gpgme_io_close): Change type of HANDLER to
	_gpgme_close_notify_handler_t.
	(_gpgme_io_close): Do not close the FD if handler returns 0.
	(_gpgme_io_dup): Remove function.
	* w32-glib-io.c (_gpgme_io_dup): Remove function.
	(_gpgme_io_set_close_notify, notify_table): Change type of HANDLER
	to _gpgme_close_notify_handler_t.
	(_gpgme_io_close): Do not close the FD if handler returns 0.
	* rungpg.c (close_notify_handler): Change return type to int,
	return 1.
	* engine-gpgsm.c (close_notify_handler): Change return type to
	int, return 0 for status FD and 1 for all other FDs.
	(start): Do not duplicate the status FD.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-07-12 20:19:46 UTC (rev 1234)
+++ trunk/ChangeLog	2007-07-13 00:43:17 UTC (rev 1235)
@@ -1,3 +1,9 @@
+2007-07-13  Marcus Brinkmann  <marcus at g10code.de>
+
+	* assuan/assuan-io.c (_assuan_simple_read, _assuan_simple_write):
+	Always use read/write (which means _gpgme_io_read and
+	_gpgme_io_write).
+
 2007-07-09  Marcus Brinkmann  <marcus at g10code.de>
 
 	Released 1.1.5.

Modified: trunk/assuan/README.1st
===================================================================
--- trunk/assuan/README.1st	2007-07-12 20:19:46 UTC (rev 1234)
+++ trunk/assuan/README.1st	2007-07-13 00:43:17 UTC (rev 1235)
@@ -27,8 +27,14 @@
   We don't need this file as GPGME doesn't use sendmsg and recvmsg.
   If it would, we would need to pick up the W32 implementation.
 
- Copyright 2004 g10 Code GmbH
+* assuan-io.c
+** _assuan_simple_read() and _assuan_simple_write() must always use
+   read()/write() (which actually translates to _gpgme_io_read() and
+   _gpgme_io_write()).
 
+
+ Copyright 2004, 2007 g10 Code GmbH
+
  This file is free software; as a special exception the author gives
  unlimited permission to copy and/or distribute it, with or without
  modifications, as long as this notice is preserved.

Modified: trunk/assuan/assuan-io.c
===================================================================
--- trunk/assuan/assuan-io.c	2007-07-12 20:19:46 UTC (rev 1234)
+++ trunk/assuan/assuan-io.c	2007-07-13 00:43:17 UTC (rev 1235)
@@ -51,7 +51,7 @@
 ssize_t
 _assuan_simple_read (assuan_context_t ctx, void *buffer, size_t size)
 {
-#ifdef HAVE_W32_SYSTEM
+#if defined(HAVE_W32_SYSTEM) && !defined(_ASSUAN_IN_GPGME_BUILD_ASSUAN)
   /* Due to the peculiarities of the W32 API we can't use read for a
      network socket and thus we try to use recv first and fallback to
      read if recv detects that it is not a network socket.  */
@@ -84,7 +84,7 @@
 ssize_t
 _assuan_simple_write (assuan_context_t ctx, const void *buffer, size_t size)
 {
-#ifdef HAVE_W32_SYSTEM
+#if defined(HAVE_W32_SYSTEM) && !defined(_ASSUAN_IN_GPGME_BUILD_ASSUAN)
   /* Due to the peculiarities of the W32 API we can't use write for a
      network socket and thus we try to use send first and fallback to
      write if send detects that it is not a network socket.  */

Modified: trunk/gpgme/ChangeLog
===================================================================
--- trunk/gpgme/ChangeLog	2007-07-12 20:19:46 UTC (rev 1234)
+++ trunk/gpgme/ChangeLog	2007-07-13 00:43:17 UTC (rev 1235)
@@ -1,3 +1,28 @@
+2007-07-13  Marcus Brinkmann  <marcus at g10code.de>
+
+	* priv-io.h (_gpgme_io_set_close_notify): Change type of HANDLER
+	to _gpgme_close_notify_handler.
+	(_gpgme_close_notify_handler): New type.
+	(_gpgme_io_dup): Remove prototype.
+	* posix-io.c (notify_table, _gpgme_io_set_close_notify): Change
+	type of HANDLER to _gpgme_close_notify_handler_t.
+	(_gpgme_io_close): Do not close the FD if handler returns 0.
+	(_gpgme_io_dup): Remove function.
+	* w32-io.c (notify_table, _gpgme_io_set_close_notify,
+	_gpgme_io_close): Change type of HANDLER to
+	_gpgme_close_notify_handler_t.
+	(_gpgme_io_close): Do not close the FD if handler returns 0.
+	(_gpgme_io_dup): Remove function.
+	* w32-glib-io.c (_gpgme_io_dup): Remove function.
+	(_gpgme_io_set_close_notify, notify_table): Change type of HANDLER
+	to _gpgme_close_notify_handler_t.
+	(_gpgme_io_close): Do not close the FD if handler returns 0.
+	* rungpg.c (close_notify_handler): Change return type to int,
+	return 1.
+	* engine-gpgsm.c (close_notify_handler): Change return type to
+	int, return 0 for status FD and 1 for all other FDs.
+	(start): Do not duplicate the status FD.
+
 2007-07-12  Marcus Brinkmann  <marcus at g10code.de>
 
 	* Makefile.am: Replace implicite rule by suffix rule.  Add

Modified: trunk/gpgme/engine-gpgsm.c
===================================================================
--- trunk/gpgme/engine-gpgsm.c	2007-07-12 20:19:46 UTC (rev 1234)
+++ trunk/gpgme/engine-gpgsm.c	2007-07-13 00:43:17 UTC (rev 1235)
@@ -112,7 +112,7 @@
 }
 
 
-static void
+static int
 close_notify_handler (int fd, void *opaque)
 {
   engine_gpgsm_t gpgsm = opaque;
@@ -124,6 +124,9 @@
 	(*gpgsm->io_cbs.remove) (gpgsm->status_cb.tag);
       gpgsm->status_cb.fd = -1;
       gpgsm->status_cb.tag = NULL;
+      /* We do not want to close the status FD, as it is controled by
+	 Assuan.  */
+      return 0;
     }
   else if (gpgsm->input_cb.fd == fd)
     {
@@ -146,6 +149,7 @@
       gpgsm->message_cb.fd = -1;
       gpgsm->message_cb.tag = NULL;
     }
+  return 1;
 }
 
 
@@ -983,20 +987,16 @@
   if (nfds < 1)
     return gpg_error (GPG_ERR_GENERAL);	/* FIXME */
 
-  /* We duplicate the file descriptor, so we can close it without
-     disturbing assuan.  Alternatively, we could special case
-     status_fd and register/unregister it manually as needed, but this
-     increases code duplication and is more complicated as we can not
-     use the close notifications etc.  */
+  /* We used to duplicate the file descriptor so that we do not
+  disturb Assuan.  But this gets in the way of the Handle-to-Thread
+  mapping in w32-io.c, so instead we just share the file descriptor
+  *carefully*, by avoiding to close it ourselves (this is achieved by
+  returning 0 from the close_notify_handler for this descriptor).  */
+  gpgsm->status_cb.fd = fdlist[0];
 
-  gpgsm->status_cb.fd = _gpgme_io_dup (fdlist[0]);
-  if (gpgsm->status_cb.fd < 0)
-    return gpg_error_from_syserror ();
-
   if (_gpgme_io_set_close_notify (gpgsm->status_cb.fd,
 				  close_notify_handler, gpgsm))
     {
-      close (gpgsm->status_cb.fd);
       gpgsm->status_cb.fd = -1;
       return gpg_error (GPG_ERR_GENERAL);
     }

Modified: trunk/gpgme/posix-io.c
===================================================================
--- trunk/gpgme/posix-io.c	2007-07-12 20:19:46 UTC (rev 1234)
+++ trunk/gpgme/posix-io.c	2007-07-13 00:43:17 UTC (rev 1235)
@@ -69,7 +69,7 @@
 
 static struct
 {
-  void (*handler) (int,void*);
+  _gpgme_close_notify_handler_t handler;
   void *value;
 } notify_table[256];
 
@@ -139,6 +139,8 @@
 int
 _gpgme_io_close (int fd)
 {
+  int really_close = 1;
+
   if (fd == -1)
     return -1;
   /* First call the notify handler.  */
@@ -147,18 +149,22 @@
     {
       if (notify_table[fd].handler)
 	{
-	  notify_table[fd].handler (fd, notify_table[fd].value);
+	  really_close = notify_table[fd].handler (fd, notify_table[fd].value);
 	  notify_table[fd].handler = NULL;
 	  notify_table[fd].value = NULL;
         }
     }
   /* Then do the close.  */    
-  return close (fd);
+  if (really_close)
+    return close (fd);
+
+  return 0;
 }
 
 
 int
-_gpgme_io_set_close_notify (int fd, void (*handler)(int, void*), void *value)
+_gpgme_io_set_close_notify (int fd, _gpgme_close_notify_handler_t handler,
+			    void *value)
 {
   assert (fd != -1);
 
@@ -493,10 +499,3 @@
   errno = saved_errno;
   return nwritten;
 }
-
-
-int
-_gpgme_io_dup (int fd)
-{
-  return dup (fd);
-}

Modified: trunk/gpgme/priv-io.h
===================================================================
--- trunk/gpgme/priv-io.h	2007-07-12 20:19:46 UTC (rev 1234)
+++ trunk/gpgme/priv-io.h	2007-07-13 00:43:17 UTC (rev 1235)
@@ -47,7 +47,8 @@
 int _gpgme_io_write (int fd, const void *buffer, size_t count);
 int _gpgme_io_pipe (int filedes[2], int inherit_idx);
 int _gpgme_io_close (int fd);
-int _gpgme_io_set_close_notify (int fd, void (*handler) (int, void *),
+typedef int (*_gpgme_close_notify_handler_t) (int,void*);
+int _gpgme_io_set_close_notify (int fd, _gpgme_close_notify_handler_t handler,
 				void *value);
 int _gpgme_io_set_nonblocking (int fd);
 
@@ -64,7 +65,4 @@
    line that the child process expects.  */
 int _gpgme_io_fd2str (char *buf, int buflen, int fd);
 
-/* Like dup().  */
-int _gpgme_io_dup (int fd);
-
 #endif /* IO_H */

Modified: trunk/gpgme/rungpg.c
===================================================================
--- trunk/gpgme/rungpg.c	2007-07-12 20:19:46 UTC (rev 1234)
+++ trunk/gpgme/rungpg.c	2007-07-13 00:43:17 UTC (rev 1235)
@@ -141,7 +141,7 @@
 }
 
 
-static void
+static int
 close_notify_handler (int fd, void *opaque)
 {
   engine_gpg_t gpg = opaque;
@@ -183,6 +183,7 @@
             }
         }
     }
+  return 1;
 }
 
 /* If FRONT is true, push at the front of the list.  Use this for

Modified: trunk/gpgme/w32-glib-io.c
===================================================================
--- trunk/gpgme/w32-glib-io.c	2007-07-12 20:19:46 UTC (rev 1234)
+++ trunk/gpgme/w32-glib-io.c	2007-07-13 00:43:17 UTC (rev 1235)
@@ -123,10 +123,11 @@
 
 static struct
 {
-  void (*handler) (int,void*);
+  _gpgme_close_notify_handler_t handler;
   void *value;
 } notify_table[MAX_SLAFD];
 
+
 int
 _gpgme_io_read (int fd, void *buffer, size_t count)
 {
@@ -270,6 +271,7 @@
 _gpgme_io_close (int fd)
 {
   GIOChannel *chan;
+  int really_close = 1;
 
   if (fd < 0 || fd >= MAX_SLAFD)
     {
@@ -281,29 +283,32 @@
   DEBUG1 ("closing fd %d", fd);
   if (notify_table[fd].handler)
     {
-      notify_table[fd].handler (fd, notify_table[fd].value);
+      really_close = notify_table[fd].handler (fd, notify_table[fd].value);
       notify_table[fd].handler = NULL;
       notify_table[fd].value = NULL;
     }
 
   /* Then do the close.  */    
-  chan = giochannel_table[fd];
-  if (chan)
+  if (really_close)
     {
-      g_io_channel_shutdown (chan, 1, NULL);
-      g_io_channel_unref (chan);
-      giochannel_table[fd] = NULL;
+      chan = giochannel_table[fd];
+      if (chan)
+	{
+	  g_io_channel_shutdown (chan, 1, NULL);
+	  g_io_channel_unref (chan);
+	  giochannel_table[fd] = NULL;
+	}
+      else
+	_close (fd);
     }
-  else
-    _close (fd);
 
-
   return 0;
 }
 
 
 int
-_gpgme_io_set_close_notify (int fd, void (*handler)(int, void*), void *value)
+_gpgme_io_set_close_notify (int fd, _gpgme_close_notify_handler_t handler,
+			    void *value)
 {
   assert (fd != -1);
 
@@ -660,11 +665,3 @@
   free (pollfds_map);
   return count;
 }
-
-
-int
-_gpgme_io_dup (int fd)
-{
-  return _dup (fd);
-}  
-

Modified: trunk/gpgme/w32-io.c
===================================================================
--- trunk/gpgme/w32-io.c	2007-07-12 20:19:46 UTC (rev 1234)
+++ trunk/gpgme/w32-io.c	2007-07-13 00:43:17 UTC (rev 1235)
@@ -55,11 +55,12 @@
 #define MAX_READERS 20
 #define MAX_WRITERS 20
 
-static struct {
-    int inuse;
-    int fd;
-    void (*handler)(int,void*);
-    void *value;
+static struct
+{
+  int inuse;
+  int fd;
+  _gpgme_close_notify_handler_t handler;
+  void *value;
 } notify_table[256];
 DEFINE_STATIC_LOCK (notify_table_lock);
 
@@ -726,8 +727,9 @@
 _gpgme_io_close ( int fd )
 {
     int i;
-    void (*handler)(int, void*) = NULL;
+    _gpgme_close_notify_handler_t handler = NULL;
     void *value = NULL;
+    int really_close = 1;
 
     if ( fd == -1 )
         return -1;
@@ -738,7 +740,7 @@
     LOCK (notify_table_lock);
     for ( i=0; i < DIM (notify_table); i++ ) {
         if (notify_table[i].inuse && notify_table[i].fd == fd) {
-            handler = notify_table[i].handler;
+	    handler = notify_table[i].handler;
             value   = notify_table[i].value;
             notify_table[i].handler = NULL;
             notify_table[i].value = NULL;
@@ -748,9 +750,9 @@
     }
     UNLOCK (notify_table_lock);
     if (handler)
-        handler (fd, value);
+        really_close = handler (fd, value);
 
-    if ( !CloseHandle (fd_to_handle (fd)) ) { 
+    if ( really_close && !CloseHandle (fd_to_handle (fd)) ) { 
         DEBUG2 ("CloseHandle for fd %d failed: ec=%d\n",
                  fd, (int)GetLastError ());
         return -1;
@@ -760,7 +762,8 @@
 }
 
 int
-_gpgme_io_set_close_notify (int fd, void (*handler)(int, void*), void *value)
+_gpgme_io_set_close_notify (int fd, _gpgme_close_notify_handler_t handler,
+			    void *value)
 {
     int i;
 
@@ -1140,25 +1143,6 @@
   return snprintf (buf, buflen, "%d", fd);
 }
 
-
-int
-_gpgme_io_dup (int fd)
-{
-  HANDLE handle = fd_to_handle (fd);
-  HANDLE new_handle = fd_to_handle (fd);
-    
-  /* For NT we have to set the sync flag.  It seems that the only
-   * way to do it is by duplicating the handle.  Tsss.. */
-  if (!DuplicateHandle( GetCurrentProcess(), handle,
-			GetCurrentProcess(), &new_handle,
-			0, FALSE, DUPLICATE_SAME_ACCESS))
-    {
-      DEBUG1 ("** DuplicateHandle failed: ec=%d\n", (int) GetLastError());
-    }
-
-  return handle_to_fd (new_handle);
-}  
-
 
 /* The following interface is only useful for GPGME Glib.  */
 




More information about the Gnupg-commits mailing list