summaryrefslogtreecommitdiff
path: root/tests/in-eq-out-infloop
blob: dcb7ac05a47d1a313fbe0374fdf6eae2ba8d345f (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
34
35
#!/bin/sh
# Demonstrate the disk-filling infloop when redirecting to an input file.
. "${srcdir=.}/init.sh"; path_prepend_ ../src
require_timeout_

# Use an input file large enough that the problem is reproducible in spite
# of buffering effects.  Just larger than 256KB should be adequate.
v=$(printf %063d 0)'
'
# 64 * 2^12 = 256k
for i in 1 2 3 4 5 6 7 8 9 10 11 12; do
  v="$v$v"
done

echo "$v" > out || framework_failure_
echo 'grep: input file `out'\'' is also the output' \
    > err.exp || framework_failure_

# Require an exit status of 2.
# grep-2.8 and earlier would infloop.
timeout 10 grep 0 out >> out 2> err; st=$?
test $st = 2 || fail=1

compare err.exp err || fail=1

# But with each of the following options it must not exit-2.
for i in -q -m1 -l -L; do
  timeout 10 grep $i 0 out >> out 2> err; st=$?
  test $st = 2 && fail=1
done

timeout 10 grep -2 0 out >> out 2> err; st=$?
test $st = 2 || fail=1

Exit $fail