NetBSD-Bugs archive

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

Re: bin/51123: /bin/sh fails to close file (N>&-) in some cases (+FIX)



On May 8,  7:20am, kre%munnari.OZ.AU@localhost (Robert Elz) wrote:
-- Subject: Re: bin/51123: /bin/sh fails to close file (N>&-) in some cases (

| From: Robert Elz <kre%munnari.OZ.AU@localhost>
| To: gnats-bugs%NetBSD.org@localhost
| Cc: 
| Subject: Re: bin/51123: /bin/sh fails to close file (N>&-) in some cases (+FIX)
| Date: Sun, 08 May 2016 14:17:44 +0700
| 
|      Date:        Sun,  8 May 2016 04:15:00 +0000 (UTC)
|      From:        kre%munnari.OZ.AU@localhost
|      Message-ID:  <20160508041500.2E11C7A473%mollari.NetBSD.org@localhost>
|  
|    | >Fix:
|    | 	Apply the following patch (against current).
|  
|  I have a different patch.  This one works just as well for solving the
|  problem in the PR, but also allows
|  
|  	ls >/dev/stdout
|  
|  to work.   That's been broken forever - except, as it happens in the cases
|  where the bug from this PR exists (so echo hello >/dev/stdout works, as
|  does for ... do ... done >/dev/stdout etc, since the bug was installed in 
|  2014.)
|  
|  The problem is/was that the fd we are redirecting was closed, then the
|  file was opened, but "close(1); open("/dev/stdout",...)" is pretty much
|  guaranteed to fail.   The bug from the PR (which "forgot" to do the close
|  in some cases) allowed it to work.
|  
|  The same applies to </dev/stdin and 2>/dev/stderr of course.   (I don't
|  want to even imagine why anyone wants to do any of this, but apparently
|  some people do...)
|  
|  The patch appended handles the PR problem in a different way, and as a side
|  effect, never closes the fd before we open the replacement.   This can 
|  sometimes save a system call, as we used to do "close(), open(), dup2()"
|  and now we just do "open(), dup2()" in the normal case.   But only sometimes
|  save, as if open happens to return the fd we want to use, which would be
|  common when that fd was 0, 1, or 2, and has just been closed, the dup2()
|  was not needed, so now we're swapping a close() for a dup2().
|  
|  This patch applies to current in CVS (simply ignoring the previous patch
|  which was never committed.)
|  
|  kre

Fine...

christos


Home | Main Index | Thread Index | Old Index