git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 1/2] perl: redirect stderr to /dev/null instead of closing

From
Thomas Rast <trast@inf.ethz.ch>
Date
Apr 6, 2013, 08:07 UTC
Message-ID
<878v4wrsj7.fsf@linux-k42r.v.cablecom.net>
In-Reply-To
<20130405233450.GA6137@machine.or.cz>
Petr Baudis <pasky@ucw.cz> writes:
Show 5 quoted lines
> On Fri, Apr 05, 2013 at 11:57:19AM -0700, Junio C Hamano wrote:
>   The thing is, I was confused about dup2() all along as my old UNIX
> masters taught me that I must close() the original descriptor first
> and since that's what's commonly done anyway, I never thought to
> double-check. Now I did and I learned something new, thanks!

Indeed, that's the crucial point here. dup2() is defined to close the original FD first if needed.

It's much saner this way for the case of stderr, as there is no time when we have no stderr available to report errors: the FD is replace atomically from the POV of the program.

The manpage for dup2 does, however, say
   If newfd was open, any errors  that  would  have  been  reported  at
   close(2) time are lost.  A careful programmer will not use dup2() or
   dup3() without closing newfd first.
which is probably what you were referring to.
-- 
Thomas Rast
trast@{inf,student}.ethz.ch
Previous: Petr BaudisNext: Petr Baudis
Message 8 of 11 in “perl: redirect stderr to /dev/null instead of closing”
  1. perl: redirect stderr to /dev/null instead of closingThomas Rast, Apr 3, 2013
  2. Eric WongApr 4, 2013
  3. 1/2 perl: redirect stderr to /dev/null instead of closingThomas Rast, Apr 4, 2013
  4. Eric WongApr 4, 2013
  5. Petr BaudisApr 5, 2013
  6. Junio C HamanoApr 5, 2013
  7. Petr BaudisApr 5, 2013
  8. Thomas RastApr 6, 2013
  9. Petr BaudisApr 6, 2013
  10. 2/2 t9700: do not close STDERRThomas Rast, Apr 4, 2013
  11. Jonathan NiederApr 4, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.