]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cksum: promptly diagnose write errors
authorCollin Funk <collin.funk1@gmail.com>
Sat, 10 Jan 2026 05:17:26 +0000 (21:17 -0800)
committerCollin Funk <collin.funk1@gmail.com>
Sat, 10 Jan 2026 20:42:13 +0000 (12:42 -0800)
* 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
src/cksum.c
tests/misc/write-errors.sh

diff --git a/NEWS b/NEWS
index 63db27deed535373218a6d3231f98ead0fc51e0c..7bd3c9b34e5f5158c3ddf9902ab0355442a67d67 100644 (file)
--- 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.
 
index 2c5cdfbe1c3e692942cb78b84104a47fbefca783..7d6ff982bc1b76c08822db548daa0d5b2526d8fe 100644 (file)
@@ -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));
index e335e52d6f2e2c4b84ec148cb1f15c3f27d043f3..3773dda39f89b3c7f00108d0f2457771e9edd7da 100755 (executable)
@@ -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) || framework_failure_
+
 # 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