Skip to content

Commit 8b54c31

Browse files
grooverdanJan Lindström
authored andcommitted
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
1 parent 930682c commit 8b54c31

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

include/my_global.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,11 @@ typedef SOCKET_SIZE_TYPE size_socket;
601601
#ifndef O_CLOEXEC
602602
#define O_CLOEXEC 0
603603
#endif
604+
#ifdef __GLIBC__
605+
#define STR_O_CLOEXEC "e"
606+
#else
607+
#define STR_O_CLOEXEC ""
608+
#endif
604609
#ifndef SOCK_CLOEXEC
605610
#define SOCK_CLOEXEC 0
606611
#endif

storage/innobase/buf/buf0dump.cc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,20 @@ buf_dump(
220220
buf_dump_status(STATUS_NOTICE, "Dumping buffer pool(s) to %s",
221221
full_filename);
222222

223-
f = fopen(tmp_filename, "w");
223+
#if defined(__GLIBC__) || defined(__WIN__) || O_CLOEXEC == 0
224+
f = fopen(tmp_filename, "w" STR_O_CLOEXEC);
225+
#else
226+
{
227+
int fd;
228+
fd = open(tmp_filename, O_CREAT | O_TRUNC | O_CLOEXEC | O_WRONLY, 0640);
229+
if (fd >= 0) {
230+
f = fdopen(fd, "w");
231+
}
232+
else {
233+
f = NULL;
234+
}
235+
}
236+
#endif
224237
if (f == NULL) {
225238
buf_dump_status(STATUS_ERR,
226239
"Cannot open '%s' for writing: %s",

storage/xtradb/buf/buf0dump.cc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,20 @@ buf_dump(
220220
buf_dump_status(STATUS_NOTICE, "Dumping buffer pool(s) to %s",
221221
full_filename);
222222

223-
f = fopen(tmp_filename, "w");
223+
#if defined(__GLIBC__) || defined(__WIN__) || O_CLOEXEC == 0
224+
f = fopen(tmp_filename, "w" STR_O_CLOEXEC);
225+
#else
226+
{
227+
int fd;
228+
fd = open(tmp_filename, O_CREAT | O_TRUNC | O_CLOEXEC | O_WRONLY, 0640);
229+
if (fd >= 0) {
230+
f = fdopen(fd, "w");
231+
}
232+
else {
233+
f = NULL;
234+
}
235+
}
236+
#endif
224237
if (f == NULL) {
225238
buf_dump_status(STATUS_ERR,
226239
"Cannot open '%s' for writing: %s",

0 commit comments

Comments
 (0)