From: Frank Lichtenheld <frank@lichtenheld.de>
To: Jakub Narebski <jnareb@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [RFC/PATCH] gitweb: Use list form of 'open "-|"' pipeline
Date: Tue, 11 Mar 2008 19:59:16 +0100 [thread overview]
Message-ID: <20080311185916.GO10103@mail-vs.djpig.de> (raw)
In-Reply-To: <200803111830.58392.jnareb@gmail.com>
On Tue, Mar 11, 2008 at 06:30:57PM +0100, Jakub Narebski wrote:
> On Tue, 11 March 2008, Frank Lichtenheld wrote:
> > On Sat, Mar 08, 2008 at 05:57:20PM +0100, Jakub Narebski wrote:
> >>
> >> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> >> index a5df2fe..ba97a7b 100755
> >> --- a/gitweb/gitweb.perl
> >> +++ b/gitweb/gitweb.perl
> >> @@ -1455,6 +1455,35 @@ sub git_cmd_str {
> >> return join(' ', git_cmd());
> >> }
> >>
> >> +# my $fh = output_pipeline(['cmd_1', 'option'], ['cmd_2', 'argument']);
> >> +# is equivalent to (is the "list form" of) the following
> >> +# open my $fh, "-|", "cmd_1 option | cmd_2 argument"
> >> +#
> >> +# Based on http://www.perlmonks.org/?node_id=246397
>
> Note that this patch is a bit "cargo cult" (copy'n'paste) programming...
>
> > It might be worthwile to look into how e.g. IPC::Run does this.
>
> Thanks for the pointer. I look at it.
After taking a look at the IPC::Run code myself I'm not really sure it
is really "worthwile", as I put it, to try to understand that.
Creating a less flexible solution that is readable might be better.
> >> +sub output_pipeline {
> >> + my @commands_list = @_;
> >> + exit unless @commands_list;
> >> +
> >> + my $pid = open(my $fh, "-|");
> >> + #die "Couldn't fork: $!" unless defined $pid;
> >
> > Why are all the die's commented out?
>
> The goal is to have gitweb deal with errors gracefully. It should
> generate some kind of '503 Server Error' page, instead of dieing
> without output, or what would be even worse, in the middle of output.
>
> I haven't examined how it should be writen for this RFC patch, so
> I have commented out 'die' just in case. In the final version (if it
> will be decided to go this route) it should be cleaned out.
Ok, I guessed as much, but wanted to make sure ;)
> > Thw whole concept of processing the array backwards might be shorter,
> > I personally find it somewhat confusing though.
>
> I'm not sure if it is not the only possible way, as the (first) parent,
> I think, has to return filehandle. But I might be mistaken.
>
> > What happens to all these child processes anyway if one of them fails to
> > exec?
>
> Original snippet returned in addition to filehandle also list of pids.
> Perhaps I have oversimplified this snipped... or it was to simple to
> begin with.
I'm not really convinced yet that dealing with a shell is much worse
than dealing with IPC ;)
Jokes aside, my idea for implementing something like this would be to
use explicit pipe()'s and fork()'s instead of the open() magic. With
better control over the filehandles and pids you might be able to build
a more robust solution.
Gruesse,
--
Frank Lichtenheld <frank@lichtenheld.de>
www: http://www.djpig.de/
next prev parent reply other threads:[~2008-03-11 19:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-08 16:57 [RFC/PATCH] gitweb: Use list form of 'open "-|"' pipeline Jakub Narebski
2008-03-08 17:51 ` Charles Bailey
2008-03-08 18:29 ` Jakub Narebski
2008-03-11 9:01 ` Frank Lichtenheld
2008-03-11 17:30 ` Jakub Narebski
2008-03-11 18:59 ` Frank Lichtenheld [this message]
2008-03-12 2:09 ` Jay Soffian
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=20080311185916.GO10103@mail-vs.djpig.de \
--to=frank@lichtenheld.de \
--cc=git@vger.kernel.org \
--cc=jnareb@gmail.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).