Skip to content

Commit 2e81161

Browse files
committed
Merge #21250: build: make HAVE_O_CLOEXEC available outside LevelDB (bugfix)
9bac713 build: make HAVE_O_CLOEXEC available outside LevelDB (bugfix) (Sebastian Falbesoner) 584fd91 init: only use pipe2 if availabile, check in configure (Sebastian Falbesoner) Pull request description: The result of the O_CLOEXEC availability check is currently only set in the Makefile and passed to LevelDB (see `LEVELDB_CPPFLAGS_INT` in `src/Makefile.leveldb.include`), but not defined to be used in our codebase. This means that code within the preprocessor conditional `#if HAVE_O_CLOEXEC` was actually never compiled. On the master branch this is currently used for pipe creation in `src/shutdown.cpp`, PR #21007 moves this part to a new module (I found the issue while testing that PR). The fix is similar to the one in #19803, which solved the same problem for HAVE_FDATASYNC. In the course of working on the PR it turned out that pipe2 is not available an all platforms, hence a configure check and a corresponding define HAVE_PIPE2 is introduced and used. The PR can be tested by anyone with a system that has pipe2 and O_CLOEXEC available by putting gibberish into the HAVE_O_CLOEXEC block: on master, everything should compile fine, on PR, the compiler should abort with an error. At least that's my naive way of testing preprocessor logic, happy to hear more sophisticated ways :-) ACKs for top commit: laanwj: Code review ACK 9bac713 Tree-SHA512: aec89faf6ba52b6f014c610ebef7b725d9e967207d58b42a4a71afc9f1268fcb673ecc85b33a2a3debba8105a304dd7edaba4208c5373fcef2ab83e48a170051
2 parents 1b045b5 + 9bac713 commit 2e81161

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

configure.ac

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,8 @@ AC_CHECK_DECLS([strnlen])
925925
dnl Check for daemon(3), unrelated to --with-daemon (although used by it)
926926
AC_CHECK_DECLS([daemon])
927927

928+
AC_CHECK_DECLS([pipe2])
929+
928930
AC_CHECK_DECLS([le16toh, le32toh, le64toh, htole16, htole32, htole64, be16toh, be32toh, be64toh, htobe16, htobe32, htobe64],,,
929931
[#if HAVE_ENDIAN_H
930932
#include <endian.h>
@@ -1149,6 +1151,7 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <fcntl.h>]],
11491151
[ AC_MSG_RESULT(yes); HAVE_O_CLOEXEC=1 ],
11501152
[ AC_MSG_RESULT(no); HAVE_O_CLOEXEC=0 ]
11511153
)
1154+
AC_DEFINE_UNQUOTED([HAVE_O_CLOEXEC], [$HAVE_O_CLOEXEC], [Define to 1 if O_CLOEXEC flag is available.])
11521155

11531156
dnl crc32c platform checks
11541157
AC_MSG_CHECKING(for __builtin_prefetch)

src/shutdown.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static int g_shutdown_pipe[2] = {-1, -1};
3232
bool InitShutdownState()
3333
{
3434
#ifndef WIN32
35-
#if HAVE_O_CLOEXEC
35+
#if HAVE_O_CLOEXEC && HAVE_DECL_PIPE2
3636
// If we can, make sure that the file descriptors are closed on exec()
3737
// to prevent interference.
3838
if (pipe2(g_shutdown_pipe, O_CLOEXEC) != 0) {

0 commit comments

Comments
 (0)