Files
sed/testsuite/read-error-stale-errno.sh
Bruno Haible 4ee49f606d tests: really skip read-error-stale-errno on Cygwin
* testsuite/read-error-stale-errno.sh: Skip when setting O_NONBLOCK on
an fd in a child process has no effect on the fd in the parent process.
Reported in https://lists.gnu.org/r/sed-devel/2026-04/msg00016.html
2026-04-23 11:51:17 -07:00

86 lines
2.9 KiB
Bash
Executable File

#!/bin/sh
# Verify ck_getdelim no longer reports a misleading strerror(errno)
# when ferror is already set from a prior I/O operation.
# Copyright (C) 2026 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
. "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed
print_ver_ sed
# Verify that O_NONBLOCK is preserved across program invocations.
# In particular, verify that when a 'dd' child process sets O_NONBLOCK
# on stdin, this flag is then active in the parent process and in all
# its future child processes.
# This is not the case on Cygwin, because the major part of the
# O_NONBLOCK state is stored in an 'fhandler_base' object, not in the
# Windows HANDLE.
mkfifo probe || framework_failure_
{ exec sleep 1; } > probe &
probe_pid=$!
(
exec < probe
dd iflag=nonblock count=0 2>/dev/null
dd bs=1 count=1 2>/dev/null
)
probe_rc=$?
kill $probe_pid 2>/dev/null; wait
rm -f probe
test $probe_rc = 0 \
&& skip_ "O_NONBLOCK is not preserved across program invocations"
# Use a FIFO with non-blocking I/O. After sed reads one line,
# the next read(2) fails with EAGAIN (not EOF, since a writer is
# still attached), setting ferror on the stream.
#
# With sed -s, test_eof's getc triggers EAGAIN, setting ferror;
# ck_getdelim is then called with ferror already set.
#
# Before the fix: "sed: read error on stdin: Resource temporarily unavailable"
# After the fix: "sed: read error on stdin"
mkfifo fifo || framework_failure_
# A writer that keeps the FIFO's write-end open.
{ printf 'hello\n'; exec sleep 99; } > fifo &
writer_pid=$!
# "dd iflag=nonblock count=0" sets O_NONBLOCK on the file description
# underlying stdin (a no-op read that just changes the flag).
# That flag is then inherited by sed.
# Skip if dd doesn't support iflag=nonblock.
(
exec < fifo
dd iflag=nonblock count=0 2>/dev/null || exit 77
sed -s -n '$p'
) 2>err
rc=$?
kill $writer_pid 2>/dev/null
wait
test $rc -eq 77 && skip_ "dd does not support iflag=nonblock"
# sed should have panicked (exit 4) due to the read error.
test $rc -eq 4 || fail=1
# The error message must mention "read error" ...
grep 'read error' err > /dev/null || fail=1
# ... but must NOT include a ": strerror" suffix, which would be misleading
# (before the fix, this was e.g., ": Resource temporarily unavailable").
grep 'read error.*: ' err && fail=1
Exit $fail