From: Jakub Narebski <jnareb@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Sylvain Rabot <sylvain@abstraction.fr>, git@vger.kernel.org
Subject: Re: [PATCH 2/4] gitweb: remove unnecessary test when closing file descriptor
Date: Tue, 04 Jan 2011 16:50:25 -0800 (PST) [thread overview]
Message-ID: <m3y670b2ef.fsf@localhost.localdomain> (raw)
In-Reply-To: <7vaajgdx35.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
> Sylvain Rabot <sylvain@abstraction.fr> writes:
>
> > it happens that closing file descriptor fails whereas
> > the blob is perfectly readable. According to perlman
> > the reasons could be:
> >
> > If the file handle came from a piped open, "close" will additionally
> > return false if one of the other system calls involved fails, or if the
> > program exits with non-zero status. (If the only problem was that the
> > program exited non-zero, $! will be set to 0.) Closing a pipe also waits
> > for the process executing on the pipe to complete, in case you want to
> > look at the output of the pipe afterwards, and implicitly puts the exit
> > status value of that command into $?.
> >
> > Prematurely closing the read end of a pipe (i.e. before the process writ-
> > ing to it at the other end has closed it) will result in a SIGPIPE being
> > delivered to the writer. If the other end can't handle that, be sure to
> > read all the data before closing the pipe.
> >
> > In this case we don't mind that close fails.
> >
> > Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
>
> Hmm, do you want a few helped-by lines here?
>
> I'll queue this to 'pu', but only because I do not care too much about
> this part of the codepath, not because I think this is explained well.
True, I might now agree with code, but I still don't like the
explanation...
>
> For example, what does "the reasons could be" mean? If the reasons turned
> out to be totally different, that would make this patch useless? IOW, is
> it fixing the real issue? Without knowing the reasons, how can we
> conclude that "In this case" we don't mind?
Well, "in this case" of run_highlighter() we close filehandle from
git-cat-file, which was used only to test if it passes -T test (file
is an ASCII text file (heuristic guess)), to _reopen_ it with
highlighter as a filter.
Also, with test if failed for Sylvain, with test removed it works all
right.
> Having said all that, I agree that you are seeing a failure exactly
> because of the reason you stated above with an unnecessary weak "could
> be". A filehandle to a pipe to cat-file is opened by the caller of
> blob_mimetype(), it gets peeked at with -T inside the function, then it
> gets peeked at with -B inside the caller (by the way, didn't anybody find
> this sloppy? Why isn't blob_mimetype() doing all of that itself?), and
I think the -B test is here because -T test is last resort in
blob_mimetype; depending on used mime.types one can get something
other than application/octet-stream for non-text file. But I agree
that it could have been done better.
> then after that the run_highligher closes the filehandle, because it does
> not want to read from the unadorned cat-file output at all. Of course,
> cat-file may receive SIGPIPE if we do that, and we know we don't care how
> cat-file died in that particular case.
>
> But do we care if the first cat-file died due to some other reason? Is
> there anything that catches the failure mode?
Well, the alternate would be to examine $! or %!, e.g.
> > @@ -3465,8 +3465,7 @@ sub run_highlighter {
> > my ($fd, $highlight, $syntax) = @_;
> > return $fd unless ($highlight && defined $syntax);
> >
> > close $fd
> > - or die_error(404, "Reading blob failed");
> > + or $!{EPIPE} or die_error(404, "Reading blob failed");
> > open $fd, quote_command(git_cmd(), "cat-file", "blob", $hash)." | ".
> > quote_command($highlight_bin).
> > " --xhtml --fragment --syntax $syntax |"
Though this version is cryptic (but compact).
--
Jakub Narebski
Poland
ShadeHawk on #git
next prev parent reply other threads:[~2011-01-05 0:50 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-30 21:20 [PATCH 0/4 v4] minor gitweb modifications Sylvain Rabot
2010-12-30 21:20 ` [PATCH 1/4] gitweb: add extensions to highlight feature map Sylvain Rabot
2010-12-30 21:20 ` [PATCH 2/4] gitweb: remove unnecessary test when closing file descriptor Sylvain Rabot
2011-01-05 0:15 ` Junio C Hamano
2011-01-05 0:50 ` Jakub Narebski [this message]
2010-12-30 21:20 ` [PATCH 3/4] gitweb: add css class to remote url titles Sylvain Rabot
2010-12-30 21:20 ` [PATCH 4/4] gitweb: add vim modeline header which describes gitweb coding rule Sylvain Rabot
2011-01-01 10:41 ` [PATCH 0/4 v4] minor gitweb modifications Jonathan Nieder
2011-01-01 23:02 ` Jonathan Nieder
2011-01-02 16:27 ` Sylvain Rabot
2011-01-02 17:53 ` 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=m3y670b2ef.fsf@localhost.localdomain \
--to=jnareb@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=sylvain@abstraction.fr \
/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).