Skip to content

Commit 04ed70f

Browse files
committed
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.
1 parent d705735 commit 04ed70f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

scripts/wsrep_sst_common.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,28 @@
1616

1717
# This is a common command line parser to be sourced by other SST scripts
1818

19+
# Close file descriptors numbered above 2 just in case mysqld or the
20+
# wsrep_provider left a file descriptor open. We don't want a broken SST
21+
# script or called program from overwriting a tablespace because
22+
# its file descriptor was left open.
23+
if [ -d /proc/self/fd ]; then
24+
for fd in /proc/self/fd/*; do
25+
fd=${fd##*/}
26+
# While bash would support the below syntax other sh's don't
27+
#[ $fd -gt 2 ] && exec {fd}>&-
28+
[ $fd -gt 2 ] && eval "exec ${fd}>&-" 2> /dev/null
29+
done
30+
else
31+
upper_no_file=$(ulimit -n)
32+
[ "$upper_no_file" = "unlimited" ] || [ -z "$upper_no_file" ] && upper_no_file=1024
33+
34+
while [ $upper_no_file -gt 2 ]
35+
do
36+
eval "exec ${upper_no_file}>&-"
37+
upper_no_file=$(( "$upper_no_file" - 1 ))
38+
done
39+
fi
40+
1941
set -u
2042

2143
WSREP_SST_OPT_BYPASS=0

0 commit comments

Comments
 (0)