summaryrefslogtreecommitdiff
path: root/regress/usr.bin/tail/follow-renames.sh
blob: efa6121acf945550138b2691b7ba7999b5cc8095 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/sh

# test if tail follows a file descriptor across renames

#set TMPDIR to a nfs-based dir for nfs testing
local DIR=$(mktemp -d)
echo DIR=${DIR}

local NAME=${0##*/}
local OUT=${DIR}/${NAME%%.sh}.out
echo bar > ${DIR}/bar

# retry until file appears for nfs
local RET=1
while [ ${RET} == 1 ] ; do
	tail -f ${DIR}/bar > ${OUT} &
	RET=$?
	PID=$!
	sleep 1
done

mv ${DIR}/bar ${DIR}/bar2
echo 'bar2' >> ${DIR}/bar2
mv ${DIR}/bar2 ${DIR}/bar
echo 'bar' >> ${DIR}/bar

# hey nfs !
sleep 5
kill ${PID}
diff -u ${OUT} ${0%%.sh}.out || exit 1

# cleanup if okay
rm -Rf ${DIR}