diff options
| author | Pádraig Brady <P@draigBrady.com> | 2025-10-28 19:30:08 +0000 |
|---|---|---|
| committer | Pádraig Brady <P@draigBrady.com> | 2025-10-29 19:03:23 +0000 |
| commit | b294aff3fe6c8ebeda02b8c77877ba618474de41 (patch) | |
| tree | 0b511881d71ce69f229d09c165f98072f1a98397 /tests | |
| parent | build: update gnulib submodule to latest (diff) | |
| download | coreutils-b294aff3fe6c8ebeda02b8c77877ba618474de41.tar.gz coreutils-b294aff3fe6c8ebeda02b8c77877ba618474de41.zip | |
sort: fix silent exit upon SIGPIPE from --compress-program
* src/sort.c (main): Ignore SIGPIPE so we've more control over
how we handle for stdout and compression programs.
(sort_die): Handle EPIPE from stdout and mimic a standard SIGPIPE,
otherwise reverting to a standard exit(SORT_FAILURE);
* tests/sort/sort-compress-proc.sh: Add a test case.
* NEWS: Mention the bug fix.
Diffstat (limited to 'tests')
| -rwxr-xr-x | tests/sort/sort-compress-proc.sh | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/tests/sort/sort-compress-proc.sh b/tests/sort/sort-compress-proc.sh index c410b7fce..203342924 100755 --- a/tests/sort/sort-compress-proc.sh +++ b/tests/sort/sort-compress-proc.sh @@ -17,7 +17,7 @@ # along with this program. If not, see <https://www.gnu.org/licenses/>. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src -print_ver_ sort +print_ver_ sort kill expensive_ # Terminate any background processes @@ -25,9 +25,9 @@ cleanup_() { kill $pid 2>/dev/null && wait $pid; } SORT_FAILURE=2 -seq -w 2000 > exp || fail=1 -tac exp > in || fail=1 -insize=$(stat -c %s - <in) || fail=1 +seq -w 2000 > exp || framework_failure_ +tac exp > in || framework_failure_ +insize=$(stat -c %s - <in) || framework_failure_ # This compressor's behavior is adjustable via environment variables. export PRE_COMPRESS= @@ -42,6 +42,24 @@ EOF chmod +x compress +# "Early exit" test +# +# In this test, the compressor exits before reading all (any) data. +# Until coreutils 9.9 'sort' could get a SIGPIPE writing to the +# exited processes and silently exit. Note the same issue can happen +# irrespective of exit status. It's more likely to happen in the +# case of the child exiting with success, and if we write more data +# (hence the --batch-size=30 and double "in"). Note we check sort doesn't +# get SIGPIPE rather than if it returns SORT_FAILURE, because there is +# the theoretical possibility that the kernel could buffer the +# amount of data we're writing here and not issue the EPIPE to sort. +# In other words we currently may not detect failures in the extreme edge case +# of writing a small amount of data to a compressor that exits 0 +# while not reading all the data presented. +PRE_COMPRESS='exit 0' \ + sort --compress-program=./compress -S 1k --batch-size=30 ./in ./in > out +test $(env kill -l $?) = 'PIPE' && fail=1 + # "Impatient exit" tests # # In these test cases, the biggest compressor (or decompressor) exits |
