git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Michael Witten <mfwitten@MIT.EDU>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] git-cvsserver runs hooks/post-update
Date: Wed, 05 Dec 2007 03:18:26 -0800	[thread overview]
Message-ID: <7vtzmxs83h.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <7245A47D-143F-4DC7-8414-D8C99C0ED9C3@mit.edu> (Michael Witten's message of "Wed, 5 Dec 2007 06:07:29 -0500")

Michael Witten <mfwitten@MIT.EDU> writes:

> 	### Emulate git-receive-pack by running hooks/post-receive
> 	my $hook = $ENV{GIT_DIR}.'hooks/post-receive';
> 	if( -x $hook ) {
> 		open(my $pipe, "| $hook") || die "can't fork $!";
>
> 		local $SIG{PIPE} = sub { die 'pipe broke' };
>
> 		print $pipe "$parenthash $commithash refs/heads/$state->{module}\n";
>
> 		close $pipe || die "bad pipe: $! $?";
> 	}
>
>> Unfortunately, it turns out that open() with a pipe essentially
>> invokes system(); the solution is to fork a child process and
>> then to turn the child into the process with which communication
>> is desired via a call to exec().
>>
>> Because the rest of git-cvsserver.perl uses explicit system()
>> calls, I have been wondering if I am being overly cautious.
>
> Am I being overly cautious?

I do not think you are.  open($fh, "| $hook") can be confused with any
IFS in $hook (there is no problem with 'hooks/post-receive', but
$ENV{GIT_DIR} part can have pretty much anything other than NUL), so if
anything, you are not being careful enough.  Other parts of cvsserver
seem to be more careful by doing open($fh, '-|', @cmd), which does not
have this problem.

The execution environment of post-receive is probably wrong; I think
receive-pack runs the hooks with their $CWD = $GIT_DIR.

      reply	other threads:[~2007-12-05 11:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-05 10:59 [PATCH] git-cvsserver runs hooks/post-update Junio C Hamano
2007-12-05 11:07 ` Michael Witten
2007-12-05 11:18   ` Junio C Hamano [this message]

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=7vtzmxs83h.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=mfwitten@MIT.EDU \
    /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).