From: Pádraig Brady
Date: Fri, 9 Jan 2026 14:20:56 +0000 (+0000) Subject: du: promptly diagnose write errors X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19d2d707f76d3ed6d609b9032f2729eaa5df9f51;p=thirdparty%2Fcoreutils.git du: promptly diagnose write errors * 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. --- diff --git a/NEWS b/NEWS index a3239537e4..63db27deed 100644 --- 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 diff --git a/src/du.c b/src/du.c index 1565c90781..a38c96174f 100644 --- 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. */ diff --git a/tests/misc/write-errors.sh b/tests/misc/write-errors.sh index a84cb8d7a0..719b17d685 100755 --- a/tests/misc/write-errors.sh +++ b/tests/misc/write-errors.sh @@ -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