]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
du: promptly diagnose write errors
authorPádraig Brady <P@draigBrady.com>
Fri, 9 Jan 2026 14:20:56 +0000 (14:20 +0000)
committerPádraig Brady <P@draigBrady.com>
Sat, 10 Jan 2026 01:04:33 +0000 (01:04 +0000)
* src/du.c (print_size): Call write_error() if can't flush.
* tests/misc/write-errors.sh: Add a test case.
* NEWS: Mention the improvement.

NEWS
src/du.c
tests/misc/write-errors.sh

diff --git a/NEWS b/NEWS
index a3239537e456febb554c8941851ee50cfb70e582..63db27deed535373218a6d3231f98ead0fc51e0c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -78,6 +78,9 @@ GNU coreutils NEWS                                    -*- outline -*-
   '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.
 
@@ -88,9 +91,6 @@ GNU coreutils NEWS                                    -*- outline -*-
   'timeout' on Linux will always terminate the child in the case where the
   timeout process itself dies, like when it receives a KILL signal for example.
 
-  'wc' now exits promptly upon receiving a write error,
-  which is significant when processing many input files.
-
 ** Build-related
 
   'kill' and 'uptime' are no longer built by default.  These programs can be
index 1565c907813fc9c077cd834c3d22fc4ec514c30a..a38c96174f7e01b098047598d0cad35a9b0eade8 100644 (file)
--- a/src/du.c
+++ b/src/du.c
@@ -406,7 +406,9 @@ print_size (const struct duinfo *pdui, char const *string)
         }
     }
   printf ("\t%s%c", string, opt_nul_terminate_output ? '\0' : '\n');
-  fflush (stdout);
+  if (fflush (stdout) != 0)
+    write_error ();
+
 }
 
 /* Fill the di_mnt set with local mount point dev/ino pairs.  */
index a84cb8d7a08a68397900e8bd843eeb67088a30f9..719b17d685586af647cf4c6858290768b3a4f730 100755 (executable)
@@ -34,6 +34,7 @@ cut -z -f1- /dev/zero
 date +%${OFF64_T_MAX}c
 date --version; yes 0 | date -f-
 dd if=/dev/zero
+du --version; yes /dev/null | tr '\\\\n' '\\\\0' | du -l --files0-from=-
 expand /dev/zero
 factor --version; yes 1 | factor
 fmt /dev/zero