From 5f5a0b3bb60651564b7354945a6019475cce0853 Mon Sep 17 00:00:00 2001 From: Sergey Vojtovich Date: Thu, 23 May 2019 12:55:03 +0400 Subject: [PATCH] MDEV-16548 - Innodb fails to start on older kernels that don't support F_DUPFD_CLOEXEC InnoDB duplicates file descriptor returned by create_temp_file() to workaround further inconsistent use of this descriptor. Use mysys file descriptors consistently for innobase_mysql_tmpfile(NULL). Mostly close it by appropriate mysys wrappers. --- storage/innobase/dict/dict0dict.cc | 2 +- storage/innobase/lock/lock0lock.cc | 2 +- storage/innobase/os/os0file.cc | 27 +++++++++------------------ storage/innobase/srv/srv0start.cc | 8 +++++--- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/storage/innobase/dict/dict0dict.cc b/storage/innobase/dict/dict0dict.cc index 1a8e55988c2..aa4032773e6 100644 --- a/storage/innobase/dict/dict0dict.cc +++ b/storage/innobase/dict/dict0dict.cc @@ -6436,7 +6436,7 @@ void dict_sys_t::close() if (dict_foreign_err_file) { - fclose(dict_foreign_err_file); + my_fclose(dict_foreign_err_file, MYF(MY_WME)); dict_foreign_err_file = NULL; } diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc index c4b056dd613..8fedfd7303a 100644 --- a/storage/innobase/lock/lock0lock.cc +++ b/storage/innobase/lock/lock0lock.cc @@ -557,7 +557,7 @@ void lock_sys_t::close() if (!m_initialised) return; if (lock_latest_err_file != NULL) { - fclose(lock_latest_err_file); + my_fclose(lock_latest_err_file, MYF(MY_WME)); lock_latest_err_file = NULL; } diff --git a/storage/innobase/os/os0file.cc b/storage/innobase/os/os0file.cc index 5cb2c452be6..c6cc3197205 100644 --- a/storage/innobase/os/os0file.cc +++ b/storage/innobase/os/os0file.cc @@ -1131,23 +1131,14 @@ os_file_create_tmpfile() { FILE* file = NULL; WAIT_ALLOW_WRITES(); - os_file_t fd = innobase_mysql_tmpfile(NULL); + File fd = mysql_tmpfile("ib"); - if (fd != OS_FILE_CLOSED) { -#ifdef _WIN32 - int crt_fd = _open_osfhandle((intptr_t)HANDLE(fd), 0); - if (crt_fd != -1) { - file = fdopen(crt_fd, "w+b"); - if (!file) { - close(crt_fd); - } - } -#else - file = fdopen(fd, "w+b"); + if (fd >= 0) { + file = my_fdopen(fd, 0, O_RDWR|O_TRUNC|O_CREAT|FILE_BINARY, + MYF(MY_WME)); if (!file) { - close(fd); + my_close(fd, MYF(MY_WME)); } -#endif } if (file == NULL) { @@ -2145,7 +2136,7 @@ and native aio. bool AIO::is_linux_native_aio_supported() { - int fd; + File fd; io_context_t io_ctx; char name[1000]; @@ -2158,7 +2149,7 @@ AIO::is_linux_native_aio_supported() } else if (!srv_read_only_mode) { /* Now check if tmpdir supports native aio ops. */ - fd = innobase_mysql_tmpfile(NULL); + fd = mysql_tmpfile("ib"); if (fd < 0) { ib::warn() @@ -2185,7 +2176,7 @@ AIO::is_linux_native_aio_supported() strcpy(name + dirnamelen, "ib_logfile0"); - fd = open(name, O_RDONLY | O_CLOEXEC); + fd = my_open(name, O_RDONLY | O_CLOEXEC, MYF(0)); if (fd == -1) { @@ -2230,7 +2221,7 @@ AIO::is_linux_native_aio_supported() } ut_free(buf); - close(fd); + my_close(fd, MYF(MY_WME)); switch (err) { case 1: diff --git a/storage/innobase/srv/srv0start.cc b/storage/innobase/srv/srv0start.cc index dde743f58c1..541e579e2fb 100644 --- a/storage/innobase/srv/srv0start.cc +++ b/storage/innobase/srv/srv0start.cc @@ -1422,7 +1422,9 @@ dberr_t srv_start(bool create_new_db) fil_path_to_mysql_datadir, os_proc_get_number()); - srv_monitor_file = fopen(srv_monitor_file_name, "w+"); + srv_monitor_file = my_fopen(srv_monitor_file_name, + O_RDWR|O_TRUNC|O_CREAT, + MYF(MY_WME)); if (!srv_monitor_file) { ib::error() << "Unable to create " @@ -2458,7 +2460,7 @@ void innodb_shutdown() srv_shutdown_all_bg_threads(); if (srv_monitor_file) { - fclose(srv_monitor_file); + my_fclose(srv_monitor_file, MYF(MY_WME)); srv_monitor_file = 0; if (srv_monitor_file_name) { unlink(srv_monitor_file_name); @@ -2467,7 +2469,7 @@ void innodb_shutdown() } if (srv_misc_tmpfile) { - fclose(srv_misc_tmpfile); + my_fclose(srv_misc_tmpfile, MYF(MY_WME)); srv_misc_tmpfile = 0; }