From 80b229be7187a24e14739291df54c7e15fb74fa5 Mon Sep 17 00:00:00 2001 From: Collin Funk Date: Wed, 25 Feb 2026 20:56:12 -0800 Subject: [PATCH] groups: promptly diagnose write errors * NEWS: Mention the improvement. * src/groups.c (main): Call fflush for each listed user to check for write errors. * tests/misc/io-errors.sh: Add an invocation of 'groups'. --- NEWS | 3 +++ src/groups.c | 3 +++ tests/misc/io-errors.sh | 1 + 3 files changed, 7 insertions(+) diff --git a/NEWS b/NEWS index cf1b1414e..7567a488f 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,9 @@ GNU coreutils NEWS -*- outline -*- ** Improvements + 'groups' will now exit immediately upon receiving a write error, which is + significant when listing information for many users. + 'nl' now supports multi-byte --section-delimiter characters. 'shuf -i' now operates up to two times faster on systems with unlocked stdio diff --git a/src/groups.c b/src/groups.c index faed5c810..3daf410d9 100644 --- a/src/groups.c +++ b/src/groups.c @@ -134,6 +134,9 @@ main (int argc, char **argv) if (!print_group_list (argv[optind], ruid, rgid, egid, true, ' ')) ok = false; putchar ('\n'); + + if (fflush (stdout) < 0) + write_error (); } } diff --git a/tests/misc/io-errors.sh b/tests/misc/io-errors.sh index 63649603e..29929f652 100755 --- a/tests/misc/io-errors.sh +++ b/tests/misc/io-errors.sh @@ -44,6 +44,7 @@ fmt foo fold foo fold -b foo fold -c foo +groups head -n1 foo join foo foo nl foo