1#!/bin/sh 2# Ensure we diagnose and not continue writing to 3# the output if we get a write error. 4 5# Copyright (C) 2014-2023 Free Software Foundation, Inc. 6 7# This program is free software: you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation, either version 3 of the License, or 10# (at your option) any later version. 11 12# This program is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16 17# You should have received a copy of the GNU General Public License 18# along with this program. If not, see <https://www.gnu.org/licenses/>. 19 20. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src 21print_ver_ head 22 23if ! test -w /dev/full || ! test -c /dev/full; then 24 skip_ '/dev/full is required' 25fi 26 27# We can't use /dev/zero as that's bypassed in the --lines case 28# due to lseek() indicating it has a size of zero. 29yes | head -c10M > bigseek || framework_failure_ 30 31# This is the single output diagnostic expected, 32# (without the possibly varying :strerror(ENOSPC) suffix). 33printf '%s\n' "head: error writing 'standard output'" > exp 34 35# Memory is bounded in these cases 36for item in lines bytes; do 37 for N in 0 1; do 38 # pipe case 39 yes | returns_ 1 timeout 10s head --$item=-$N > /dev/full 2> errt || fail=1 40 sed 's/\(head:.*\):.*/\1/' errt > err 41 compare exp err || fail=1 42 43 # seekable case 44 returns_ 1 timeout 10s head --$item=-$N bigseek > /dev/full 2> errt \ 45 || fail=1 46 sed 's/\(head:.*\):.*/\1/' errt > err 47 compare exp err || fail=1 48 done 49done 50 51Exit $fail 52