diff options
author | Daniel Black <grooverdan@users.sourceforge.net> | 2018-03-02 20:16:16 +1100 |
---|---|---|
committer | Daniel Black <grooverdan@users.sourceforge.net> | 2018-03-08 18:55:01 +1100 |
commit | 04ed70fa55fb75d862be469686494536458b1927 (patch) | |
tree | 5e3d825a7dee6247616c9be316866a3cdb6cdef6 /scripts | |
parent | d70573564cb2701076083ea7f55ae9539fad13b4 (diff) | |
download | mariadb-git-04ed70fa55fb75d862be469686494536458b1927.tar.gz |
MDEV-8743: wsrep_sst_common close FDs > 2
To prevent accidential overwriting of files due to mysqld file
descriptors being open we ensure where that only FDs 1, 2 and 3
are available to SST scripts. Assumed is mysqld has thse still
mapped to stdin (unused), stdout and stderr.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/wsrep_sst_common.sh | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/scripts/wsrep_sst_common.sh b/scripts/wsrep_sst_common.sh index e72b74ab6d1..5ec88bb7d0e 100755 --- a/scripts/wsrep_sst_common.sh +++ b/scripts/wsrep_sst_common.sh @@ -16,6 +16,28 @@ # This is a common command line parser to be sourced by other SST scripts +# Close file descriptors numbered above 2 just in case mysqld or the +# wsrep_provider left a file descriptor open. We don't want a broken SST +# script or called program from overwriting a tablespace because +# its file descriptor was left open. +if [ -d /proc/self/fd ]; then + for fd in /proc/self/fd/*; do + fd=${fd##*/} + # While bash would support the below syntax other sh's don't + #[ $fd -gt 2 ] && exec {fd}>&- + [ $fd -gt 2 ] && eval "exec ${fd}>&-" 2> /dev/null + done +else + upper_no_file=$(ulimit -n) + [ "$upper_no_file" = "unlimited" ] || [ -z "$upper_no_file" ] && upper_no_file=1024 + + while [ $upper_no_file -gt 2 ] + do + eval "exec ${upper_no_file}>&-" + upper_no_file=$(( "$upper_no_file" - 1 )) + done +fi + set -u WSREP_SST_OPT_BYPASS=0 |