Skip to content

Commit

Permalink
Galera SST scripts shouldn't access grastate.dat
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
grooverdan committed Mar 6, 2018
1 parent ac090bc commit 49d0927
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion galera/src/saved_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
#include <sys/file.h>
#include <fcntl.h>

#ifdef __GLIBC__
#define STR_O_EXCL_CLOEXEC "ex"
#else
#define STR_O_EXCL_CLOEXEC ""
#endif

namespace galera
{

Expand Down Expand Up @@ -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(), "a" STR_O_EXCL_CLOEXEC);

if (!fs_)
{
Expand Down

0 comments on commit 49d0927

Please sign in to comment.