Module: check_mk
Branch: master
Commit: 117617cc7c423a3763ef5acf46a1f10dd3bf5f8b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=117617cc7c423a…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Tue May 8 13:56:32 2018 +0200
Fixed (probably harmless?) race condition.
Change-Id: I886637fbcf2f6c628e71d7c4bdac4dd3bf62226e
---
configure.ac | 2 +-
livestatus/src/module.cc | 6 ++++++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index 5f9c9d1..6ff8253 100644
--- a/configure.ac
+++ b/configure.ac
@@ -168,7 +168,7 @@ AC_TYPE_UINT64_T
AC_FUNC_SELECT_ARGTYPES
AC_TYPE_SIGNAL
AC_FUNC_STAT
-AC_CHECK_FUNCS([memmove select socket strerror strtoul])
+AC_CHECK_FUNCS([accept4 memmove select socket strerror strtoul])
AC_ARG_WITH(nagios4,AC_HELP_STRING([--with-nagios4],[enabled compilation for nagios 4]),
[
CPPFLAGS="${CFLAGS} -DNAGIOS4"
diff --git a/livestatus/src/module.cc b/livestatus/src/module.cc
index 7f43f90..2ec373d 100644
--- a/livestatus/src/module.cc
+++ b/livestatus/src/module.cc
@@ -193,18 +193,24 @@ void *main_thread(void *data) {
int retval = poller.poll(std::chrono::milliseconds(2500));
if (retval > 0 &&
poller.isFileDescriptorSet(g_unix_socket, PollEvents::in)) {
+#if HAVE_ACCEPT4
+ int cc = accept4(g_unix_socket, nullptr, nullptr, SOCK_CLOEXEC);
+#else
int cc = accept(g_unix_socket, nullptr, nullptr);
+#endif
if (cc == -1) {
generic_error ge("cannot accept client connection");
Warning(fl_logger_livestatus) << ge;
continue;
}
+#if !HAVE_ACCEPT4
if (fcntl(cc, F_SETFD, FD_CLOEXEC) == -1) {
generic_error ge(
"cannot set close-on-exec bit on client socket");
Alert(fl_logger_livestatus) << ge;
break;
}
+#endif
if (cc > g_max_fd_ever) {
g_max_fd_ever = cc;
}