[Pkg-gnupg-commit] [gpgme] 02/04: use getdents64 instead of getdents

Daniel Kahn Gillmor dkg at fifthhorseman.net
Wed Oct 11 03:40:09 UTC 2017


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository gpgme.

commit 1d13a7442347c1982d408ac58f16fabff6ac04bf
Author: Daniel Kahn Gillmor <dkg at fifthhorseman.net>
Date:   Tue Oct 10 23:25:37 2017 -0400

    use getdents64 instead of getdents
---
 ...Restore-get_max_fds-optimization-on-Linux.patch |   1 +
 ...disabling-the-use-of-SYS_getdents-for-Lin.patch | 111 +++++++++++++++++++++
 ...tdents64-syscall-on-linux-instead-of-getd.patch |  67 +++++++++++++
 debian/patches/series                              |   4 +-
 4 files changed, 182 insertions(+), 1 deletion(-)

diff --git a/debian/patches/reduce-spurious-close/0049-core-Restore-get_max_fds-optimization-on-Linux.patch b/debian/patches/0049-core-Restore-get_max_fds-optimization-on-Linux.patch
similarity index 98%
rename from debian/patches/reduce-spurious-close/0049-core-Restore-get_max_fds-optimization-on-Linux.patch
rename to debian/patches/0049-core-Restore-get_max_fds-optimization-on-Linux.patch
index b671e5a..2e9ede7 100644
--- a/debian/patches/reduce-spurious-close/0049-core-Restore-get_max_fds-optimization-on-Linux.patch
+++ b/debian/patches/0049-core-Restore-get_max_fds-optimization-on-Linux.patch
@@ -16,6 +16,7 @@ essentially just a souped-up read.  Python >= 3.2.3 makes the same
 assumption.)
 
 Signed-off-by: Colin Watson <cjwatson at debian.org>
+(cherry picked from commit b5b996b1a142abb90296f5feadf0b5b19c59f738)
 ---
  src/posix-io.c | 99 ++++++++++++++++++++++++++++++++++++++--------------------
  1 file changed, 66 insertions(+), 33 deletions(-)
diff --git a/debian/patches/0050-core-Allow-disabling-the-use-of-SYS_getdents-for-Lin.patch b/debian/patches/0050-core-Allow-disabling-the-use-of-SYS_getdents-for-Lin.patch
new file mode 100644
index 0000000..0e9e890
--- /dev/null
+++ b/debian/patches/0050-core-Allow-disabling-the-use-of-SYS_getdents-for-Lin.patch
@@ -0,0 +1,111 @@
+From: Werner Koch <wk at gnupg.org>
+Date: Wed, 4 Oct 2017 18:03:54 +0200
+Subject: core: Allow disabling the use of SYS_getdents for Linux.
+
+* configure.ac (USE_LINUX_GETDENTS): New ac_define.  Add option
+--disable-linux-getdents.
+* src/posix-io.c: Make use of USE_LINUX_GETDENTS.
+
+Signed-off-by: Werner Koch <wk at gnupg.org>
+(cherry picked from commit 4632adf403611b50be2b4e852a4607070935d0e5)
+---
+ configure.ac   | 21 +++++++++++++++++++++
+ src/posix-io.c | 14 ++++++++------
+ 2 files changed, 29 insertions(+), 6 deletions(-)
+
+diff --git a/configure.ac b/configure.ac
+index 510aae1..3f36a15 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -781,7 +781,28 @@ fi
+ AM_CONDITIONAL(HAVE_UISERVER, test "$uiserver" != "no")
+ 
+ 
++# Option --disable-linux-getdents
++#
++# By default we use SYS_getdents on Linux to optimize fd closing
++# before an exec.  This option allows to switch this optimization off.
++use_linux_getdents=yes
++AC_ARG_ENABLE(linux-getdents,
++              AC_HELP_STRING([--disable-linux-getdents],
++                             [do not use SYS_getdents on Linux]),
++              use_linux_getdents=$enableval)
++if test "$use_linux_getdents" = "yes"; then
++    case "${host}" in
++        *-*-linux*)
++           AC_DEFINE(USE_LINUX_GETDENTS,1,
++                     [Defined if SYS_getdents can be used on Linux])
++           ;;
++    esac
++fi
++
++
++#
+ # Add a few constants to help porting to W32
++#
+ AH_VERBATIM([SEPCONSTANTS],
+ [
+ /* Separators as used in $PATH and file name.  */
+diff --git a/src/posix-io.c b/src/posix-io.c
+index dfed68c..d33b2af 100644
+--- a/src/posix-io.c
++++ b/src/posix-io.c
+@@ -47,11 +47,11 @@
+ #include <ctype.h>
+ #include <sys/resource.h>
+ 
+-#if __linux__
++#ifdef USE_LINUX_GETDENTS
+ # include <sys/syscall.h>
+ # include <sys/types.h>
+ # include <dirent.h>
+-#endif /*__linux__ */
++#endif /*USE_LINUX_GETDENTS*/
+ 
+ 
+ #include "util.h"
+@@ -60,6 +60,7 @@
+ #include "ath.h"
+ #include "debug.h"
+ 
++
+ 

+ void
+ _gpgme_io_subsystem_init (void)
+@@ -280,7 +281,7 @@ _gpgme_io_set_nonblocking (int fd)
+ }
+ 
+ 
+-#ifdef __linux__
++#ifdef USE_LINUX_GETDENTS
+ /* This is not declared in public headers; getdents(2) says that we must
+  * define it ourselves.  */
+ struct linux_dirent
+@@ -292,7 +293,8 @@ struct linux_dirent
+ };
+ 
+ # define DIR_BUF_SIZE 1024
+-#endif /* __linux__ */
++#endif /*USE_LINUX_GETDENTS*/
++
+ 
+ static long int
+ get_max_fds (void)
+@@ -310,7 +312,7 @@ get_max_fds (void)
+    * fork and exec in a multi-threaded process because opendir uses
+    * malloc and thus a mutex which may deadlock with a malloc in another
+    * thread.  However, the underlying getdents system call is safe.  */
+-#ifdef __linux__
++#ifdef USE_LINUX_GETDENTS
+   {
+     int dir_fd;
+     char dir_buf[DIR_BUF_SIZE];
+@@ -356,7 +358,7 @@ get_max_fds (void)
+         source = "/proc";
+       }
+     }
+-#endif /* __linux__ */
++#endif /*USE_LINUX_GETDENTS*/
+ 
+ #ifdef RLIMIT_NOFILE
+   if (fds == -1)
diff --git a/debian/patches/0051-core-use-getdents64-syscall-on-linux-instead-of-getd.patch b/debian/patches/0051-core-use-getdents64-syscall-on-linux-instead-of-getd.patch
new file mode 100644
index 0000000..1d129a3
--- /dev/null
+++ b/debian/patches/0051-core-use-getdents64-syscall-on-linux-instead-of-getd.patch
@@ -0,0 +1,67 @@
+From: Daniel Kahn Gillmor <dkg at fifthhorseman.net>
+Date: Tue, 10 Oct 2017 23:18:41 -0400
+Subject: core: use getdents64 syscall on linux instead of getdents.
+
+* src/posix-io.c (get_max_fds): use getdents64 instead of getdents.
+--
+
+getdents64 was introduced in linux 2.4, so it should be widely
+available.  some Linux architectures which post-date 2.4 (e.g. arm64)
+appear to not have getdents at all, so it's probably better to use the
+more modern interface.
+
+Signed-off-by: Daniel Kahn Gillmor <dkg at fifthhorseman.net>
+---
+ src/posix-io.c | 15 ++++++++-------
+ 1 file changed, 8 insertions(+), 7 deletions(-)
+
+diff --git a/src/posix-io.c b/src/posix-io.c
+index d33b2af..4185981 100644
+--- a/src/posix-io.c
++++ b/src/posix-io.c
+@@ -282,13 +282,14 @@ _gpgme_io_set_nonblocking (int fd)
+ 
+ 
+ #ifdef USE_LINUX_GETDENTS
+-/* This is not declared in public headers; getdents(2) says that we must
++/* This is not declared in public headers; getdents64(2) says that we must
+  * define it ourselves.  */
+-struct linux_dirent
++struct linux_dirent64
+ {
+-  unsigned long d_ino;
+-  unsigned long d_off;
++  ino64_t d_ino;
++  off64_t d_off;
+   unsigned short d_reclen;
++  unsigned char d_type;
+   char d_name[];
+ };
+ 
+@@ -316,7 +317,7 @@ get_max_fds (void)
+   {
+     int dir_fd;
+     char dir_buf[DIR_BUF_SIZE];
+-    struct linux_dirent *dir_entry;
++    struct linux_dirent64 *dir_entry;
+     int r, pos;
+     const char *s;
+     int x;
+@@ -326,7 +327,7 @@ get_max_fds (void)
+       {
+         for (;;)
+           {
+-            r = syscall(SYS_getdents, dir_fd, dir_buf, DIR_BUF_SIZE);
++            r = syscall(SYS_getdents64, dir_fd, dir_buf, DIR_BUF_SIZE);
+             if (r == -1)
+               {
+                 /* Fall back to other methods.  */
+@@ -338,7 +339,7 @@ get_max_fds (void)
+ 
+             for (pos = 0; pos < r; pos += dir_entry->d_reclen)
+               {
+-                dir_entry = (struct linux_dirent *) (dir_buf + pos);
++                dir_entry = (struct linux_dirent64 *) (dir_buf + pos);
+                 s = dir_entry->d_name;
+                 if (*s < '0' || *s > '9')
+                   continue;
diff --git a/debian/patches/series b/debian/patches/series
index c05b8b8..5161ee2 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -46,4 +46,6 @@ python-3.6/0045-Try-to-find-python-3.6-as-well.patch
 0046-python-Improve-keylist-test.patch
 0047-python-Support-parallel-build-in-tests.patch
 0048-Fix-a-couple-of-bugs-pointed-out-by-clang-compiler-w.patch
-reduce-spurious-close/0049-core-Restore-get_max_fds-optimization-on-Linux.patch
+0049-core-Restore-get_max_fds-optimization-on-Linux.patch
+0050-core-Allow-disabling-the-use-of-SYS_getdents-for-Lin.patch
+0051-core-use-getdents64-syscall-on-linux-instead-of-getd.patch

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gpgme.git



More information about the Pkg-gnupg-commit mailing list