summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/bugs/bug-846240.t6
-rw-r--r--tests/fileio.rc61
2 files changed, 65 insertions, 2 deletions
diff --git a/tests/bugs/bug-846240.t b/tests/bugs/bug-846240.t
index 5c5fbf0147a..12e4949ef36 100644
--- a/tests/bugs/bug-846240.t
+++ b/tests/bugs/bug-846240.t
@@ -2,6 +2,7 @@
. $(dirname $0)/../include.rc
. $(dirname $0)/../volume.rc
+. $(dirname $0)/../fileio.rc
cleanup;
@@ -30,7 +31,8 @@ TEST glusterfs --volfile-server=$H0 --volfile-id=$V0 $M1;
TEST touch $M0/testfile;
# open the file with the fd as 4
-exec 4>"$M0/testfile";
+TEST fd=`fd_available`;
+TEST fd_open $fd 'w' "$M0/testfile";
# remove the file from the other mount point. If unlink is sent from
# $M0 itself, then the file will be actually opened by open-behind which
@@ -47,7 +49,7 @@ TEST rm -f $M1/testfile;
echo "data" >> $M0/testfile 2>/dev/null 1>/dev/null;
TEST [ $? -ne 0 ]
-exec 4>&-
+TEST fd_close $fd;
TEST rm -rf $MOUNTDIR/*
diff --git a/tests/fileio.rc b/tests/fileio.rc
new file mode 100644
index 00000000000..58871b3b97a
--- /dev/null
+++ b/tests/fileio.rc
@@ -0,0 +1,61 @@
+#!/bin/bash
+
+function fd_available() {
+ for i in {1..65536}; do
+ if [ ! -e /proc/$$/fd/$i ]; then
+ echo $i;
+ return 0;
+ fi
+ done
+
+ return 1;
+}
+
+function fd_open() {
+ local fd=$1;
+ local mode=$2
+ local path=$3;
+
+ case $mode in
+ r)
+ eval "exec $fd<$path";;
+ w)
+ eval "exec $fd>$path";;
+ rw)
+ eval "exec $fd<>$path";;
+ *)
+ false;;
+ esac
+}
+
+
+function fd_cat() {
+ local fd=$1;
+
+ eval "cat <&$fd";
+}
+
+
+function fd_write() {
+ local fd=$1;
+ shift;
+ local msg="$@";
+
+ eval "echo $@ >&$fd";
+}
+
+
+function fd_close() {
+ local fd=$1;
+
+ eval "exec $fd>&-";
+}
+
+
+function fd_based_example() {
+ TEST fd=`fd_available`;
+ TEST fd_open $fd "rw" $M0/filename;
+ TEST fd_cat $fd; # print existing stuff
+ TEST fd_write $fd "new stuff"; # append
+ TEST fd_close $fd;
+}