There isn't really a good case for the non --check case. If a system
has a small limit on the maximum number of arguments it will run too
quickly.

-- 8< ---

* src/cksum.c (output_file, digest_check): Check if standard output has
it's error flag set after printing.
* tests/misc/write-errors.sh: Add a test case that would previously run
forever.
* NEWS: Mention the improvement. Reorder alphabetically.
---
 NEWS                       | 6 +++---
 src/cksum.c                | 6 ++++++
 tests/misc/write-errors.sh | 3 +++
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index 63db27dee..7bd3c9b34 100644
--- a/NEWS
+++ b/NEWS
@@ -73,14 +73,14 @@ GNU coreutils NEWS                                    -*- 
outline -*-
   'cksum' now validates its options more consistently.
   E.g., `cksum --text --tag` now fails like `cksum --tag --text` already did.
 
+  'cksum', 'du', and 'wc' now exit promptly upon receiving a write
+  error, which is significant when processing many input files.
+
   csplit, ls, and sort, now handle a more complete set of terminating signals.
 
   'du' now processes directories with 10,000 or more entries up to 9 times
   faster on the Lustre file system.
 
-  'du', and 'wc' now exit promptly upon receiving a write error,
-  which is significant when processing many input files.
-
   'pinky' will now exit immediately upon receiving a write error, which is
   significant when reading large plan or project files.
 
diff --git a/src/cksum.c b/src/cksum.c
index 2c5cdfbe1..7d6ff982b 100644
--- a/src/cksum.c
+++ b/src/cksum.c
@@ -1266,6 +1266,9 @@ output_file (char const *file, int binary_file, void 
const *digest,
     }
 
   putchar (delim);
+
+  if (ferror (stdout))
+    write_error ();
 }
 #endif
 
@@ -1447,6 +1450,9 @@ digest_check (char const *checkfile_name)
                     printf (": %s\n", _("OK"));
                 }
             }
+
+          if (ferror (stdout))
+            write_error ();
         }
     }
   while (!feof (checkfile_stream) && !ferror (checkfile_stream));
diff --git a/tests/misc/write-errors.sh b/tests/misc/write-errors.sh
index e335e52d6..43397e4fa 100755
--- a/tests/misc/write-errors.sh
+++ b/tests/misc/write-errors.sh
@@ -24,11 +24,14 @@ if ! test -w /dev/full || ! test -c /dev/full; then
   skip_ '/dev/full is required'
 fi
 
+dev_null_hash=$(cksum -a sha3 -l 256 /dev/null)
+
 # Writers that may output data indefinitely.
 # First word in command line is checked against built programs.
 # Escapes must be double escaped.
 printf '%s' "\
 cat /dev/zero
+cksum --version; yes \"${dev_null_hash}\" | cksum --check
 comm -z /dev/zero /dev/zero
 cut -z -c1- /dev/zero
 cut -z -f1- /dev/zero
-- 
2.52.0


Reply via email to