Blame tests/in-eq-out-infloop

Packit 709fb3
#!/bin/sh
Packit 709fb3
# Demonstrate the disk-filling infloop when redirecting to an input file.
Packit 709fb3
. "${srcdir=.}/init.sh"; path_prepend_ ../src
Packit 709fb3
require_timeout_
Packit 709fb3
Packit 709fb3
# Use an input file large enough that the problem is reproducible in spite
Packit 709fb3
# of buffering effects.  Just larger than 256KB should be adequate.
Packit 709fb3
v=$(printf %063d 0)'
Packit 709fb3
'
Packit 709fb3
# 64 * 2^12 = 256k
Packit 709fb3
for i in 1 2 3 4 5 6 7 8 9 10 11 12; do
Packit 709fb3
  v="$v$v"
Packit 709fb3
done
Packit 709fb3
Packit 709fb3
echo "$v" > out || framework_failure_
Packit 709fb3
Packit 709fb3
for arg in out - ''; do
Packit 709fb3
  # Accommodate both 'out' and '(standard input)', as well as
Packit 709fb3
  # the multi-byte quoting we see on OS/X-based systems.
Packit 709fb3
  echo grep: input file ... is also the output > err.exp || framework_failure_
Packit 709fb3
Packit 709fb3
  # Require an exit status of 2.
Packit 709fb3
  # grep-2.8 and earlier would infloop with $arg = out.
Packit 709fb3
  # grep-2.10 and earlier would infloop with $arg = - or $arg = ''.
Packit 709fb3
  timeout 10 grep 0 $arg < out >> out 2> err; st=$?; test $st = 2 || fail=1
Packit 709fb3
  sed 's/file .* is/file ... is/' err > k && mv k err
Packit 709fb3
  # Normalize the diagnostic prefix from e.g., "/mnt/dir/grep: " to "grep: "
Packit 709fb3
  sed 's/^[^:]*: /grep: /' err > k && mv k err
Packit 709fb3
  compare err.exp err || fail=1
Packit 709fb3
Packit 709fb3
  # But with each of the following options it must not exit-2.
Packit 709fb3
  for i in -q -m1 -l -L; do
Packit 709fb3
    timeout 10 grep $i 0 $arg < out >> out 2> err; st=$?
Packit 709fb3
    test $st = 2 && fail=1
Packit 709fb3
  done
Packit 709fb3
Packit 709fb3
  timeout 10 grep -2 0 $arg < out >> out 2> err; st=$?
Packit 709fb3
  test $st = 2 || fail=1
Packit 709fb3
done
Packit 709fb3
Packit 709fb3
Exit $fail