From f991b55e12f1b00d328d3f26572afdf9115cdf14 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 1 Mar 2018 17:05:10 +1100 Subject: [PATCH] Galera SST scripts shouldn't access grastate.dat When SST scripts they inherit the open file descriptors. Here we use the GLIBC extensions to fopen, 'e', to ensure that forked processes don't inherit the file descriptor, and 'x' which ensure exclusive access. --- galera/src/saved_state.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/galera/src/saved_state.cpp b/galera/src/saved_state.cpp index 119621c6e..55a968cf6 100644 --- a/galera/src/saved_state.cpp +++ b/galera/src/saved_state.cpp @@ -13,6 +13,12 @@ #include #include +#ifdef __GLIBC__ +#define STR_O_EXCL_CLOEXEC "ex" +#else +#define STR_O_EXCL_CLOEXEC "" +#endif + namespace galera { @@ -44,7 +50,7 @@ SavedState::SavedState (const std::string& file) : log_warn << "Could not open state file for reading: '" << file << '\''; } - fs_ = fopen(file.c_str(), "a"); + fs_ = fopen(file.c_str(), STR_O_EXCL_CLOEXEC "a"); if (!fs_) {