summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Lindström <jan.lindstrom@mariadb.com>2018-08-07 11:35:39 +0300
committerJan Lindström <jan.lindstrom@mariadb.com>2018-08-07 11:35:39 +0300
commit517009ca0fa5f0e5b48b3d244a0b5bb0c44e90a8 (patch)
tree40c518c02dc5795b94a4ca94b6aee54da6343a8d
parent3b37edee1a5121e9523fa8a7f483185f402905e2 (diff)
downloadmariadb-git-bb-10.1-MDEV-16548.tar.gz
MDEV-16548: Innodb fails to start on older kernels that don't support F_DUPFD_CLOEXECbb-10.1-MDEV-16548
Add runtime check that fcntl() system call really supports F_DUPFD_CLOEXEC directive.
-rw-r--r--storage/innobase/CMakeLists.txt27
-rw-r--r--storage/innobase/handler/ha_innodb.cc2
-rw-r--r--storage/xtradb/CMakeLists.txt27
-rw-r--r--storage/xtradb/handler/ha_innodb.cc2
4 files changed, 56 insertions, 2 deletions
diff --git a/storage/innobase/CMakeLists.txt b/storage/innobase/CMakeLists.txt
index 2a45f05c463..7470f2985c0 100644
--- a/storage/innobase/CMakeLists.txt
+++ b/storage/innobase/CMakeLists.txt
@@ -246,6 +246,33 @@ IF(HAVE_IB_ATOMIC_PTHREAD_T_GCC)
ADD_DEFINITIONS(-DHAVE_IB_ATOMIC_PTHREAD_T_GCC=1)
ENDIF()
+CHECK_C_SOURCE(
+"
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdlib.h>
+int main() {
+ char filename[] = "/tmp/mytemp.XXXXXX";
+ int fd = mkstemp(filename);
+ if (fd != -1) {
+ int fd2=fcntl(fd, F_DUPFD_CLOEXEC, 0);
+ if (fd2 != -1) {
+ close(fd2);
+ close(fd);
+ unlink(filename);
+ return (0);
+ }
+ close (fd);
+ unlink(filename);
+ }
+ return (1);
+}"
+HAVE_IB_F_DUPFD_CLOEXEC)
+
+IF (HAVE_IB_F_DUPFD_CLOEXEC)
+ ADD_DEFINITIONS(-DHAVE_IB_F_DUPFD_CLOEXEC=1)
+ENDIF()
+
CHECK_C_SOURCE_COMPILES("struct t1{ int a; char *b; }; struct t1 c= { .a=1, .b=0 }; main() { }" HAVE_C99_INITIALIZERS)
ENDIF(NOT MSVC)
diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
index 5667efea5df..6843d90b0a9 100644
--- a/storage/innobase/handler/ha_innodb.cc
+++ b/storage/innobase/handler/ha_innodb.cc
@@ -2414,7 +2414,7 @@ innobase_mysql_tmpfile(
}
}
#else
-#ifdef F_DUPFD_CLOEXEC
+#if defined(F_DUPFD_CLOEXEC) && defined(HAVE_IB_F_DUPFD_CLOEXEC)
fd2 = fcntl(fd, F_DUPFD_CLOEXEC, 0);
#else
fd2 = dup(fd);
diff --git a/storage/xtradb/CMakeLists.txt b/storage/xtradb/CMakeLists.txt
index f5ec6fd746d..5ec5881a247 100644
--- a/storage/xtradb/CMakeLists.txt
+++ b/storage/xtradb/CMakeLists.txt
@@ -255,6 +255,33 @@ IF(HAVE_IB_ATOMIC_PTHREAD_T_GCC)
ADD_DEFINITIONS(-DHAVE_IB_ATOMIC_PTHREAD_T_GCC=1)
ENDIF()
+CHECK_C_SOURCE(
+"
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdlib.h>
+int main() {
+ char filename[] = "/tmp/mytemp.XXXXXX";
+ int fd = mkstemp(filename);
+ if (fd != -1) {
+ int fd2=fcntl(fd, F_DUPFD_CLOEXEC, 0);
+ if (fd2 != -1) {
+ close(fd2);
+ close(fd);
+ unlink(filename);
+ return (0);
+ }
+ close (fd);
+ unlink(filename);
+ }
+ return (1);
+}"
+HAVE_IB_F_DUPFD_CLOEXEC)
+
+IF (HAVE_IB_F_DUPFD_CLOEXEC)
+ ADD_DEFINITIONS(-DHAVE_IB_F_DUPFD_CLOEXEC=1)
+ENDIF()
+
CHECK_C_SOURCE_COMPILES("struct t1{ int a; char *b; }; struct t1 c= { .a=1, .b=0 }; main() { }" HAVE_C99_INITIALIZERS)
ENDIF(NOT MSVC)
diff --git a/storage/xtradb/handler/ha_innodb.cc b/storage/xtradb/handler/ha_innodb.cc
index 3cd7cb6977b..fd62bc00ca4 100644
--- a/storage/xtradb/handler/ha_innodb.cc
+++ b/storage/xtradb/handler/ha_innodb.cc
@@ -2738,7 +2738,7 @@ innobase_mysql_tmpfile(
}
}
#else
-#ifdef F_DUPFD_CLOEXEC
+#if defined(F_DUPFD_CLOEXEC) && defined(HAVE_IB_F_DUPFD_CLOEXEC)
fd2 = fcntl(fd, F_DUPFD_CLOEXEC, 0);
#else
fd2 = dup(fd);