Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set FD_CLOEXEC on the LMDB FD manually #287

Merged
merged 1 commit into from Nov 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -35,6 +35,8 @@

#include <lmdb.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <glib/gstdio.h>

#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);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove the extra brackets? If there's just a single line following an if statement, they should be omitted in AppStream's coding style


/* 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);