]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
yes: avoid redundant diagnostics on write error
authorPádraig Brady <P@draigBrady.com>
Mon, 4 Apr 2016 12:17:34 +0000 (13:17 +0100)
committerPádraig Brady <P@draigBrady.com>
Thu, 21 Apr 2016 20:34:00 +0000 (21:34 +0100)
* src/yes.c (main): For large inputs only write a single
diagnostic for write errors.
* tests/misc/yes.sh: Test when /dev/full is available.

src/yes.c
tests/misc/yes.sh

index 31424cf208fa5959e0dd2ff366d28be810b6ed8b..1d2c612c91406e2dbb6ba1b54425456aa1b3769f 100644 (file)
--- a/src/yes.c
+++ b/src/yes.c
@@ -121,6 +121,7 @@ main (int argc, char **argv)
       if ((pbuf - buf) && fwrite (buf, pbuf - buf, 1, stdout) != 1)
         {
           error (0, errno, _("standard output"));
+          clearerr (stdout);
           return EXIT_FAILURE;
         }
       for (j = i; j < argc; j++)
@@ -128,6 +129,7 @@ main (int argc, char **argv)
             || putchar (j == argc - 1 ? '\n' : ' ') == EOF)
           {
             error (0, errno, _("standard output"));
+            clearerr (stdout);
             return EXIT_FAILURE;
           }
     }
index 1371593349847f3afac287353987fbcb0de6c0d5..a3027432bd5abd6fbeafe0bf6b40cc30035d26b2 100755 (executable)
@@ -30,9 +30,9 @@ for size in 1 1999 4095 4096 8191 8192 16383 16384; do
 done
 
 # Check the many small items case,
-# both fitting and overflowing the internal buffer
-external=env
-if external true $(seq 4000); then
+# both fitting and overflowing the internal buffer.
+# First check that 4000 arguments supported.
+if test 4000 -eq $(sh -c 'echo $#' 0 $(seq 4000)); then
   for i in 100 4000; do
     seq $i | paste -s -d ' ' | sed p > out.1
     yes $(seq $i) | head -n2 > out.2
@@ -40,4 +40,17 @@ if external true $(seq 4000); then
   done
 fi
 
+# Check a single appropriate diagnostic is output on write error
+if test -w /dev/full && test -c /dev/full; then
+  # The single output diagnostic expected,
+  # (without the possibly varying :strerror(ENOSPC) suffix).
+  printf '%s\n' "yes: standard output" > exp
+
+  for size in 1 16384; do
+    returns_ 1 yes "$(printf %${size}s '')" >/dev/full 2>errt
+    sed 's/\(yes:.*\):.*/\1/' errt > err
+    compare exp err || fail=1
+  done
+fi
+
 Exit $fail