diff options
author | Daniel Black <daniel@linux.vnet.ibm.com> | 2018-03-14 13:31:28 +1100 |
---|---|---|
committer | Jan Lindström <jan.lindstrom@mariadb.com> | 2018-03-15 12:07:43 +0200 |
commit | 8b54c314863e7e9861470844e09c0453800748ae (patch) | |
tree | 1178e5c268336239fb8ef0ef81c5e998797e8d5b | |
parent | 930682c4877b66417184c1787fab7941c9331c34 (diff) | |
download | mariadb-git-8b54c314863e7e9861470844e09c0453800748ae.tar.gz |
MDEV-8743: where O_CLOEXEC is available, use for innodb buf_dump
As this is the only moderately critical fopened for writing file,
create an alternate path to use open and fdopen for non-glibc platforms
that support O_CLOEXEC (BSDs).
Tested on Linux (by modifing the GLIBC defination) to take this
alternate path:
$ cd /proc/23874
$ more fdinfo/71
pos: 0
flags: 02100001
mnt_id: 24
$ ls -la fd/71
l-wx------. 1 dan dan 64 Mar 14 13:30 fd/71 -> /dev/shm/var_auto_i7rl/mysqld.1/data/ib_buffer_pool.incomplete
-rw-r--r-- | include/my_global.h | 5 | ||||
-rw-r--r-- | storage/innobase/buf/buf0dump.cc | 15 | ||||
-rw-r--r-- | storage/xtradb/buf/buf0dump.cc | 15 |
3 files changed, 33 insertions, 2 deletions
diff --git a/include/my_global.h b/include/my_global.h index 5ea761d587e..ad1527d7b37 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -601,6 +601,11 @@ typedef SOCKET_SIZE_TYPE size_socket; #ifndef O_CLOEXEC #define O_CLOEXEC 0 #endif +#ifdef __GLIBC__ +#define STR_O_CLOEXEC "e" +#else +#define STR_O_CLOEXEC "" +#endif #ifndef SOCK_CLOEXEC #define SOCK_CLOEXEC 0 #endif diff --git a/storage/innobase/buf/buf0dump.cc b/storage/innobase/buf/buf0dump.cc index 5d5be0505f6..306dcc2ec18 100644 --- a/storage/innobase/buf/buf0dump.cc +++ b/storage/innobase/buf/buf0dump.cc @@ -220,7 +220,20 @@ buf_dump( buf_dump_status(STATUS_NOTICE, "Dumping buffer pool(s) to %s", full_filename); - f = fopen(tmp_filename, "w"); +#if defined(__GLIBC__) || defined(__WIN__) || O_CLOEXEC == 0 + f = fopen(tmp_filename, "w" STR_O_CLOEXEC); +#else + { + int fd; + fd = open(tmp_filename, O_CREAT | O_TRUNC | O_CLOEXEC | O_WRONLY, 0640); + if (fd >= 0) { + f = fdopen(fd, "w"); + } + else { + f = NULL; + } + } +#endif if (f == NULL) { buf_dump_status(STATUS_ERR, "Cannot open '%s' for writing: %s", diff --git a/storage/xtradb/buf/buf0dump.cc b/storage/xtradb/buf/buf0dump.cc index 09ac460f865..0bc222d2cc2 100644 --- a/storage/xtradb/buf/buf0dump.cc +++ b/storage/xtradb/buf/buf0dump.cc @@ -220,7 +220,20 @@ buf_dump( buf_dump_status(STATUS_NOTICE, "Dumping buffer pool(s) to %s", full_filename); - f = fopen(tmp_filename, "w"); +#if defined(__GLIBC__) || defined(__WIN__) || O_CLOEXEC == 0 + f = fopen(tmp_filename, "w" STR_O_CLOEXEC); +#else + { + int fd; + fd = open(tmp_filename, O_CREAT | O_TRUNC | O_CLOEXEC | O_WRONLY, 0640); + if (fd >= 0) { + f = fdopen(fd, "w"); + } + else { + f = NULL; + } + } +#endif if (f == NULL) { buf_dump_status(STATUS_ERR, "Cannot open '%s' for writing: %s", |