From: Thomas Rast <trast@inf.ethz.ch>
To: Petr Baudis <pasky@ucw.cz>
Cc: Junio C Hamano <gitster@pobox.com>, <git@vger.kernel.org>,
Eric Wong <normalperson@yhbt.net>,
Marcin Owsiany <marcin@owsiany.pl>
Subject: Re: [PATCH v2 1/2] perl: redirect stderr to /dev/null instead of closing
Date: Sat, 6 Apr 2013 10:07:40 +0200 [thread overview]
Message-ID: <878v4wrsj7.fsf@linux-k42r.v.cablecom.net> (raw)
In-Reply-To: <20130405233450.GA6137@machine.or.cz> (Petr Baudis's message of "Sat, 6 Apr 2013 01:34:51 +0200")
Petr Baudis <pasky@ucw.cz> writes:
> 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
next prev parent reply other threads:[~2013-04-06 16:59 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-03 22:26 [PATCH] perl: redirect stderr to /dev/null instead of closing Thomas Rast
2013-04-04 1:16 ` Eric Wong
2013-04-04 20:41 ` [PATCH v2 1/2] " Thomas Rast
2013-04-04 21:14 ` Eric Wong
2013-04-05 14:48 ` Petr Baudis
2013-04-05 18:57 ` Junio C Hamano
2013-04-05 23:34 ` Petr Baudis
2013-04-06 8:07 ` Thomas Rast [this message]
2013-04-06 10:34 ` Petr Baudis
2013-04-04 20:41 ` [PATCH v2 2/2] t9700: do not close STDERR Thomas Rast
2013-04-04 21:11 ` Jonathan Nieder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878v4wrsj7.fsf@linux-k42r.v.cablecom.net \
--to=trast@inf.ethz.ch \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=marcin@owsiany.pl \
--cc=normalperson@yhbt.net \
--cc=pasky@ucw.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.