From adbd5a19079bed3f68c3e6d0719ff64622625e2b Mon Sep 17 00:00:00 2001 From: Fabian Vogt Date: Thu, 12 Nov 2020 09:29:55 +0100 Subject: [PATCH] Set FD_CLOEXEC on the LMDB FD manually Currently the FD referring to the appstreacm-cache-FOO.mdb is leaked into child processes. The only way to fix is in a race-free way is by passing O_CLOEXEC when opening it inside LMDB, but that's currently not done. --- src/as-cache.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/as-cache.c b/src/as-cache.c index 831d94a9..73fd4f62 100644 --- a/src/as-cache.c +++ b/src/as-cache.c @@ -35,6 +35,8 @@ #include #include +#include +#include #include #include "as-utils-private.h" @@ -723,6 +725,7 @@ as_cache_open (AsCache *cache, const gchar *fname, const gchar *locale, GError * gboolean nosync; gboolean readonly; g_autoptr(GMutexLocker) locker = NULL; + int db_fd; /* close cache in case it was open */ as_cache_close (cache); @@ -829,6 +832,14 @@ as_cache_open (AsCache *cache, const gchar *fname, const gchar *locale, GError * goto fail; } + /* set FD_CLOEXEC manually. LMDB should do that, but it doesn't: + https://www.openldap.org/lists/openldap-bugs/201702/msg00003.html */ + if (mdb_env_get_fd (priv->db_env, &db_fd) == MDB_SUCCESS) { + int db_fd_flags = fcntl (db_fd, F_GETFD); + if (db_fd_flags != -1) + fcntl (db_fd, F_SETFD, db_fd_flags | FD_CLOEXEC); + } + /* unlink the file, so it gets removed as soon as we don't need it anymore */ if (priv->volatile_db_fname != NULL) g_unlink (priv->volatile_db_fname);