[git] GPGME - branch, master, updated. gpgme-1.6.0-145-g89d22f9

by Werner Koch cvs at cvs.gnupg.org
Fri May 27 22:21:00 CEST 2016


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  89d22f9229f2ecd559ac6ea91dae60eeff940fa5 (commit)
      from  3915842657f0849a038752fd7445f96081a89dd9 (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 89d22f9229f2ecd559ac6ea91dae60eeff940fa5
Author: Werner Koch <wk at gnupg.org>
Date:   Fri May 27 22:19:35 2016 +0200

    Speedup closing of fds before exec.
    
    * src/posix-io.c [__linux__]: Include dirent.h.
    (get_max_fds) [__linux__]: Try to figure out the highest used fd.
    --
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/src/posix-io.c b/src/posix-io.c
index e49c71e..f336153 100644
--- a/src/posix-io.c
+++ b/src/posix-io.c
@@ -47,6 +47,12 @@
 #include <ctype.h>
 #include <sys/resource.h>
 
+#if __linux__
+# include <sys/types.h>
+# include <dirent.h>
+#endif /*__linux__ */
+
+
 #include "util.h"
 #include "priv-io.h"
 #include "sema.h"
@@ -280,16 +286,50 @@ get_max_fds (void)
   long int fds = -1;
   int rc;
 
-#ifdef RLIMIT_NOFILE
+  /* Under Linux we can figure out the highest used file descriptor by
+   * reading /proc/self/fd.  This is in the common cases much fast than
+   * for example doing 4096 close calls where almost all of them will
+   * fail.  */
+#ifdef __linux__
   {
-    struct rlimit rl;
-    rc = getrlimit (RLIMIT_NOFILE, &rl);
-    if (rc == 0)
+    DIR *dir = NULL;
+    struct dirent *dir_entry;
+    const char *s;
+    int x;
+
+    dir = opendir ("/proc/self/fd");
+    if (dir)
       {
-	source = "RLIMIT_NOFILE";
-	fds = rl.rlim_max;
+        while ((dir_entry = readdir (dir)))
+          {
+            s = dir_entry->d_name;
+            if ( *s < '0' || *s > '9')
+              continue;
+            x = atoi (s);
+            if (x > fds)
+              fds = x;
+          }
+        closedir (dir);
       }
-  }
+    if (fds != -1)
+      {
+        fds++;
+        source = "/proc";
+      }
+    }
+#endif /* __linux__ */
+
+#ifdef RLIMIT_NOFILE
+  if (fds == -1)
+    {
+      struct rlimit rl;
+      rc = getrlimit (RLIMIT_NOFILE, &rl);
+      if (rc == 0)
+        {
+          source = "RLIMIT_NOFILE";
+          fds = rl.rlim_max;
+        }
+    }
 #endif
 #ifdef RLIMIT_OFILE
   if (fds == -1)

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

Summary of changes:
 src/posix-io.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 47 insertions(+), 7 deletions(-)


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




More information about the Gnupg-commits mailing list