Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Jun 2011 16:01:48 GMT
From:      Chris Ulrich <culrich@csnstores.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   misc/158206: /bin/sh doesn't properly return IO errors to conditionals in a script
Message-ID:  <201106231601.p5NG1mMX067549@red.freebsd.org>
Resent-Message-ID: <201106231610.p5NGAE76095959@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         158206
>Category:       misc
>Synopsis:       /bin/sh doesn't properly return IO errors to conditionals in a script
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jun 23 16:10:14 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator:     Chris Ulrich
>Release:        amd64 freebsd 8.2-RELEASE
>Organization:
CSN Stores
>Environment:
FreeBSD svn.csnzoo.com 8.2-RELEASE FreeBSD 8.2-RELEASE #0: Thu Feb 17 02:41:51 UTC 2011     root@mason.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
a /bin/sh script writing to a closed file descriptor doesn't pass the IO error it receives from the write to the script itself.


>How-To-Repeat:
write these two scripts:

#!/bin/sh
while echo -n . ; do : ; done

and

#!/bin/sh
while printf . ; do : ; done


now run each script with std-out closed, ie (assuming your interactive shell is bourne shell or similar):

$ sh ./bomb-echo.sh >&-

or 

$ sh ./bomb-printf.sh >&-


both should exit instantly because echo *should* get an error from writing to a closed file descriptor.  Instead both spin madly until they get a kill signal or you truss them (the last bit of stuff you see when you truss them is:

72238: sigprocmask(SIG_SETMASK,0x0,0x0)          = 0 (0x0)
72238: write(1,".",1)                            ERR#9 'Bad file descriptor'
72238: process exit, rval = 0

which itself is another 
>Fix:
sorry.  don't know C.

>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201106231601.p5NG1mMX067549>