coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: prevent seq from inflow on I/O errors


From: Pádraig Brady
Subject: Re: prevent seq from inflow on I/O errors
Date: Mon, 4 Apr 2016 12:57:49 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0

On 04/04/16 06:18, Assaf Gordon wrote:
Hello,

The attached patch add I/O error checking to seq, preventing infloop on certain 
write-error conditions.

The typical case is
       seq 1 inf > /dev/full

Nice one.
Note we'd only inf loop if seq was going to run forever anyway.
I've adjusted the NEWS accordingly.


but also a more rare case is of systems with SIGPIPE set to ignore by default
(same weird system in recent grep 
thread:http://lists.gnu.org/archive/html/bug-grep/2016-03/msg00025.html  ).

Trotting out my standard SIGPIPE response...
http://www.pixelbeat.org/programming/sigpipe_handling.html

On that weird system, commands like 'seq 999999 inf | head -n2' would run 
forever because SIGPIPE is ignored,

Note if running stuff from python you may have SIGPIPE ignored.
See link above for details.

and seq did not check for errors. (This exact command is found in 
./tests/misc/seq-precision.sh).

seq_fast() should exit() on EIO as it should only return
if nothing was output. Returning will only generate
duplicate outputs or free invalid pointers etc.
Now we could just exit() and rely on close_stdout to diagnose,
but here we should diagnose the actual error, rather than
relying on a generic "write error" because there are relatively
few output locations in this program.


+++ b/tests/misc/seq-io-errors.sh

+timed_seq_fail()
+{
+  timeout 5 seq "$@" > /dev/full 2>/dev/null
+  rc=$?
+  if test $rc -eq 1 ; then
+    :
+  elif test $rc -eq 124 ; then
+    fail=1
+  else
+    framework_failure_
+  fi
+}

The above could be simplified/standardized to:

  returns_ 1 timeout 10 seq "$@" >/dev/full 2>/dev/null

Also it's worth checking for the SIGPIPE case.

updated patch is attached.

cheers,
Pádraig.

Attachment: seq-eio.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]