Commit f66a3159 authored by Jan Lindström's avatar Jan Lindström Committed by GitHub

Merge pull request #638 from grooverdan/10.3-MDEV-8743-fopen_o_cloexec

MDEV-8743: fopen mode e (glibc only) to prevent galera SST scripts ac…
parents 7fb03d7a fafec1a9
...@@ -591,6 +591,11 @@ typedef SOCKET_SIZE_TYPE size_socket; ...@@ -591,6 +591,11 @@ typedef SOCKET_SIZE_TYPE size_socket;
#ifndef O_CLOEXEC #ifndef O_CLOEXEC
#define O_CLOEXEC 0 #define O_CLOEXEC 0
#endif #endif
#ifdef __GLIBC__
#define STR_O_CLOEXEC "e"
#else
#define STR_O_CLOEXEC ""
#endif
#ifndef SOCK_CLOEXEC #ifndef SOCK_CLOEXEC
#define SOCK_CLOEXEC 0 #define SOCK_CLOEXEC 0
#endif #endif
......
...@@ -275,7 +275,20 @@ buf_dump( ...@@ -275,7 +275,20 @@ buf_dump(
buf_dump_status(STATUS_INFO, "Dumping buffer pool(s) to %s", buf_dump_status(STATUS_INFO, "Dumping buffer pool(s) to %s",
full_filename); 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) { if (f == NULL) {
buf_dump_status(STATUS_ERR, buf_dump_status(STATUS_ERR,
"Cannot open '%s' for writing: %s", "Cannot open '%s' for writing: %s",
...@@ -516,7 +529,7 @@ buf_load() ...@@ -516,7 +529,7 @@ buf_load()
buf_load_status(STATUS_INFO, buf_load_status(STATUS_INFO,
"Loading buffer pool(s) from %s", full_filename); "Loading buffer pool(s) from %s", full_filename);
f = fopen(full_filename, "r"); f = fopen(full_filename, "r" STR_O_CLOEXEC);
if (f == NULL) { if (f == NULL) {
buf_load_status(STATUS_INFO, buf_load_status(STATUS_INFO,
"Cannot open '%s' for reading: %s", "Cannot open '%s' for reading: %s",
......
...@@ -1043,7 +1043,7 @@ char* ...@@ -1043,7 +1043,7 @@ char*
RemoteDatafile::read_link_file( RemoteDatafile::read_link_file(
const char* link_filepath) const char* link_filepath)
{ {
FILE* file = fopen(link_filepath, "r+b"); FILE* file = fopen(link_filepath, "r+b" STR_O_CLOEXEC);
if (file == NULL) { if (file == NULL) {
return(NULL); return(NULL);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment