[git] GPGME - branch, master, updated. gpgme-1.8.0-55-g51bd69f

by Werner Koch cvs at cvs.gnupg.org
Fri Feb 3 13:59:01 CET 2017


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GnuPG Made Easy".

The branch, master has been updated
       via  51bd69f216a9e2930eeba4b5f6c20e952a381720 (commit)
      from  93a59070c699d569d1eac7ba22355fe3f5d10882 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 51bd69f216a9e2930eeba4b5f6c20e952a381720
Author: Werner Koch <wk at gnupg.org>
Date:   Fri Feb 3 13:56:23 2017 +0100

    core: Optimize fork/exec for *BSD and Solaris.
    
    * configure.ac (closefrom): Add to ac_check_funcs.
    * src/posix-io.c (_gpgme_io_spawn): Use closefrom.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/configure.ac b/configure.ac
index 9903751..f28480b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -694,7 +694,7 @@ fi
 #
 
 # Check for getgid etc
-AC_CHECK_FUNCS(getgid getegid)
+AC_CHECK_FUNCS(getgid getegid closefrom)
 
 
 # Replacement functions.
diff --git a/src/posix-io.c b/src/posix-io.c
index cabb3e5..a351806 100644
--- a/src/posix-io.c
+++ b/src/posix-io.c
@@ -459,10 +459,9 @@ _gpgme_io_spawn (const char *path, char *const argv[], unsigned int flags,
       /* Intermediate child to prevent zombie processes.  */
       if ((pid = fork ()) == 0)
 	{
-	  int max_fds = get_max_fds ();
-	  int fd;
-
 	  /* Child.  */
+          int max_fds = -1;
+          int fd;
 	  int seen_stdin = 0;
 	  int seen_stdout = 0;
 	  int seen_stderr = 0;
@@ -470,15 +469,40 @@ _gpgme_io_spawn (const char *path, char *const argv[], unsigned int flags,
 	  if (atfork)
 	    atfork (atforkvalue, 0);
 
-	  /* First close all fds which will not be inherited.  */
-	  for (fd = 0; fd < max_fds; fd++)
-	    {
-	      for (i = 0; fd_list[i].fd != -1; i++)
-		if (fd_list[i].fd == fd)
-		  break;
-	      if (fd_list[i].fd == -1)
-		close (fd);
-	    }
+          /* First close all fds which will not be inherited.  If we
+           * have closefrom(2) we first figure out the highest fd we
+           * do not want to close, then call closefrom, and on success
+           * use the regular code to close all fds up to the start
+           * point of closefrom.  Note that Solaris' closefrom does
+           * not return errors.  */
+#ifdef HAVE_CLOSEFROM
+          {
+            fd = -1;
+            for (i = 0; fd_list[i].fd != -1; i++)
+              if (fd_list[i].fd > fd)
+                fd = fd_list[i].fd;
+            fd++;
+#ifdef __sun
+            closefrom (fd);
+            max_fds = fd;
+#else /*!__sun */
+            while ((i = closefrom (fd)) && errno == EINTR)
+              ;
+            if (!i || errno == EBADF)
+              max_fds = fd;
+#endif /*!__sun*/
+          }
+#endif /*HAVE_CLOSEFROM*/
+          if (max_fds == -1)
+            max_fds = get_max_fds ();
+          for (fd = 0; fd < max_fds; fd++)
+            {
+              for (i = 0; fd_list[i].fd != -1; i++)
+                if (fd_list[i].fd == fd)
+                  break;
+              if (fd_list[i].fd == -1)
+                close (fd);
+            }
 
 	  /* And now dup and close those to be duplicated.  */
 	  for (i = 0; fd_list[i].fd != -1; i++)

-----------------------------------------------------------------------

Summary of changes:
 configure.ac   |  2 +-
 src/posix-io.c | 48 ++++++++++++++++++++++++++++++++++++------------
 2 files changed, 37 insertions(+), 13 deletions(-)


hooks/post-receive
-- 
GnuPG Made Easy
http://git.gnupg.org




More information about the Gnupg-commits mailing list