From: Jeff King <peff@peff.net>
To: Travis P <git@castle.fastmail.fm>
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: How to handle terminal detection in a daemon calling git?
Date: Fri, 1 Jun 2012 05:53:33 -0400 [thread overview]
Message-ID: <20120601095333.GF32340@sigill.intra.peff.net> (raw)
In-Reply-To: <1338471582.12573.140661083191693.32060E78@webmail.messagingengine.com>
On Thu, May 31, 2012 at 08:39:42AM -0500, Travis P wrote:
> Here's what I learned this morning: it appears to work when I don't
> close STDIN.
>
> #close $_ for *STDIN, *STDOUT, *STDERR; # What I was doing. Fails.
> close $_ for *STDOUT, *STDERR; # Tried this, it works.
> *STDOUT = $log_fh;
> *STDERR = $log_fh;
Yeah, don't do that. This can cause subtle bugs in subprocesses. For
example:
1. You don't have a descriptor 0, because it is closed.
2. Some part of the program opens a new descriptor (e.g., to read a
file, making a pipe, etc). This becomes descriptor 0, because it is
the lowest unused descriptor.
3. The program wants to redirect its stdin (e.g., because it is
forking and exec'ing a child). So it calls dup2(fd, 0), closing
what was at stdin previously, which might have been valuable.
The right thing to do is to redirect stdin from /dev/null, not close it
entirely.
> > 2. We check isatty(1) for starting a pager, auto-selecting color,
> > and in recent versions of git, for column support. But none of
> > those things should be in use by git-pull anyway.
>
> Ahh, this could be it: when the pull does receive an output and I'm
> running the command in the shell, I get output with a "+-" where the
> plus is green and the minus red. So, I think that git may be trying
> to check whether color (and columns?) is supported to output.
> However, it appears that this check is sensitive to stdin being
> connected (based on test mentioned earlier here), which is surprising.
>
> Is the code that calls isatty, calling it on all 3 descriptors, even
> when STDIN is not relevant?
No, the color code just checks isatty(1). And even if it checked some
random descriptor, the worst case should be that it affects the color
flag. So I think the terminal thing is a red herring, and it is more
likely you are seeing some subtle issue like the one I described above.
-Peff
next prev parent reply other threads:[~2012-06-01 9:53 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-30 21:16 How to handle terminal detection in a daemon calling git? Travis P
2012-05-31 1:29 ` Jeff King
2012-05-31 6:22 ` Junio C Hamano
2012-05-31 13:39 ` Travis P
2012-06-01 9:53 ` Jeff King [this message]
2012-06-01 13:52 ` Travis
2012-06-02 16:51 ` Jeff King
2012-05-31 13:43 ` Travis P
2012-05-31 3:14 ` Sitaram Chamarty
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=20120601095333.GF32340@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@castle.fastmail.fm \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).