From 02a4ebd6c451d013ecc4a93a809416781fbaf6ab Mon Sep 17 00:00:00 2001 From: =?utf8?q?P=C3=A1draig=20Brady?= Date: Sat, 15 Jul 2023 21:55:23 +0100 Subject: [PATCH] join: promptly diagnose write errors * src/join.c (prjoin): Check for write errors after each line. * tests/misc/write-errors.sh: enable the test for join. * NEWS: Mention the improvement. --- NEWS | 2 +- src/join.c | 3 +++ tests/misc/write-errors.sh | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 24c018374e..b21a2b74d8 100644 --- a/NEWS +++ b/NEWS @@ -62,7 +62,7 @@ GNU coreutils NEWS -*- outline -*- irrespective of which kernel version coreutils is built against, reinstating that behaviour from coreutils-9.0. - comm, cut, od, and uniq will now exit immediately upon receiving a + comm, cut, join, od, and uniq will now exit immediately upon receiving a write error, which is significant when reading large / unbounded inputs. split now uses more tuned access patterns for its potentially large input. diff --git a/src/join.c b/src/join.c index 5b58ed4d59..afbf0307e1 100644 --- a/src/join.c +++ b/src/join.c @@ -650,6 +650,9 @@ prjoin (struct line const *line1, struct line const *line2) putchar (eolchar); } + + if (ferror (stdout)) + write_error (); } /* Print the join of the files in FP1 and FP2. */ diff --git a/tests/misc/write-errors.sh b/tests/misc/write-errors.sh index a9e112c3a8..4f17028a26 100755 --- a/tests/misc/write-errors.sh +++ b/tests/misc/write-errors.sh @@ -36,7 +36,7 @@ factor --version; yes 1 | factor # TODO: fmt /dev/zero # TODO: fold -b /dev/zero head -z -n-1 /dev/zero -# TODO: join -a 1 -z /dev/zero /dev/null +join -a 1 -z /dev/zero /dev/null # TODO: nl --version; yes | nl # TODO: numfmt --version; yes 1 | numfmt od -v /dev/zero -- 2.47.2