[git] GPGME - branch, master, updated. gpgme-1.9.0-78-g4632adf
by Werner Koch
cvs at cvs.gnupg.org
Wed Oct 4 18:21:31 CEST 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 4632adf403611b50be2b4e852a4607070935d0e5 (commit)
via b5b996b1a142abb90296f5feadf0b5b19c59f738 (commit)
via bff944842887908dfcf66469251598065c0abcff (commit)
from bd5d470cef513b2f459316869b81267cde7a9f13 (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 4632adf403611b50be2b4e852a4607070935d0e5
Author: Werner Koch <wk at gnupg.org>
Date: Wed Oct 4 18:03:54 2017 +0200
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>
diff --git a/configure.ac b/configure.ac
index 1284317..6859357 100644
--- a/configure.ac
+++ b/configure.ac
@@ -762,7 +762,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 4267713..9b7b181 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)
commit b5b996b1a142abb90296f5feadf0b5b19c59f738
Author: Colin Watson <cjwatson at debian.org>
Date: Sat Sep 16 04:16:45 2017 +0100
core: Restore get_max_fds optimization on Linux
* src/posix-io.c (get_max_fds): Restore Linux optimization, this time
using open/getdents/close rather than opendir/readdir/closedir.
--
opendir/readdir/closedir may allocate/free memory, and aren't required
to do so in an async-signal-safe way. On the other hand, opening
/proc/self/fd directly and iterating over it using getdents is safe.
(getdents is not strictly speaking documented to be async-signal-safe
because it's not in POSIX. However, the Linux implementation is
essentially just a souped-up read. Python >= 3.2.3 makes the same
assumption.)
Signed-off-by: Colin Watson <cjwatson at debian.org>
diff --git a/src/posix-io.c b/src/posix-io.c
index 14856df..4267713 100644
--- a/src/posix-io.c
+++ b/src/posix-io.c
@@ -48,6 +48,7 @@
#include <sys/resource.h>
#if __linux__
+# include <sys/syscall.h>
# include <sys/types.h>
# include <dirent.h>
#endif /*__linux__ */
@@ -279,6 +280,20 @@ _gpgme_io_set_nonblocking (int fd)
}
+#ifdef __linux__
+/* This is not declared in public headers; getdents(2) says that we must
+ * define it ourselves. */
+struct linux_dirent
+{
+ unsigned long d_ino;
+ unsigned long d_off;
+ unsigned short d_reclen;
+ char d_name[];
+};
+
+# define DIR_BUF_SIZE 1024
+#endif /* __linux__ */
+
static long int
get_max_fds (void)
{
@@ -291,39 +306,57 @@ get_max_fds (void)
* than for example doing 4096 close calls where almost all of them
* will fail.
*
- * Unfortunately we can't call opendir between 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. Thus
- * the code is not used until we can have a opendir variant which
- * does not use malloc. */
-/* #ifdef __linux__ */
-/* { */
-/* DIR *dir = NULL; */
-/* struct dirent *dir_entry; */
-/* const char *s; */
-/* int x; */
-
-/* dir = opendir ("/proc/self/fd"); */
-/* if (dir) */
-/* { */
-/* 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__ *\/ */
+ * We can't use the normal opendir/readdir/closedir interface between
+ * 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__
+ {
+ int dir_fd;
+ char dir_buf[DIR_BUF_SIZE];
+ struct linux_dirent *dir_entry;
+ int r, pos;
+ const char *s;
+ int x;
+
+ dir_fd = open ("/proc/self/fd", O_RDONLY | O_DIRECTORY);
+ if (dir_fd != -1)
+ {
+ for (;;)
+ {
+ r = syscall(SYS_getdents, dir_fd, dir_buf, DIR_BUF_SIZE);
+ if (r == -1)
+ {
+ /* Fall back to other methods. */
+ fds = -1;
+ break;
+ }
+ if (r == 0)
+ break;
+
+ for (pos = 0; pos < r; pos += dir_entry->d_reclen)
+ {
+ dir_entry = (struct linux_dirent *) (dir_buf + pos);
+ s = dir_entry->d_name;
+ if (*s < '0' || *s > '9')
+ continue;
+ /* atoi is not guaranteed to be async-signal-safe. */
+ for (x = 0; *s >= '0' && *s <= '9'; s++)
+ x = x * 10 + (*s - '0');
+ if (!*s && x > fds && x != dir_fd)
+ fds = x;
+ }
+ }
+
+ close (dir_fd);
+ }
+ if (fds != -1)
+ {
+ fds++;
+ source = "/proc";
+ }
+ }
+#endif /* __linux__ */
#ifdef RLIMIT_NOFILE
if (fds == -1)
commit bff944842887908dfcf66469251598065c0abcff
Author: Werner Koch <wk at gnupg.org>
Date: Wed Oct 4 17:25:36 2017 +0200
Register DCO for Colin Watson.
--
diff --git a/AUTHORS b/AUTHORS
index 855284a..90f6906 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -53,6 +53,8 @@ Authors with a DCO
Daniel Kahn Gillmor <dkg at fifthhorseman.net>
2014-09-24:878ul9w4j8.fsf at alice.fifthhorseman.net:
+Colin Watson <cjwatson at debian.org>
+2017-09-16:20170916031428.uypfrdojquvjteor at riva.ucam.org:
-----------------------------------------------------------------------
Summary of changes:
AUTHORS | 2 ++
configure.ac | 21 ++++++++++++
src/posix-io.c | 105 ++++++++++++++++++++++++++++++++++++++-------------------
3 files changed, 93 insertions(+), 35 deletions(-)
hooks/post-receive
--
GnuPG Made Easy
http://git.gnupg.org
More information about the Gnupg-commits
mailing list