From: Paul Tan <pyokagan@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org,
Johannes Schindelin <johannes.schindelin@gmx.de>,
Stefan Beller <sbeller@google.com>,
Remi Lespinet <remi.lespinet@ensimag.grenoble-inp.fr>,
Jeff King <peff@peff.net>
Subject: Re: [PATCH v2 0/3] am: let command-line options override saved options
Date: Thu, 6 Aug 2015 01:51:17 +0800 [thread overview]
Message-ID: <20150805175117.GA6759@yoshi.chippynet.com> (raw)
In-Reply-To: <xmqq37zx68uf.fsf@gitster.dls.corp.google.com>
On Wed, Aug 05, 2015 at 08:41:44AM -0700, Junio C Hamano wrote:
> Interesting. This seems to break test under prove.
>
> cd t && make T=t4153-am-resume-override-opts.sh prove
>
> does not seem to return.
The new test-terminal.perl code is the culprit. It seems that if our
wrapped process terminates before our stdin-writing fork does, our
stdin-writing process will stall. I think this occurs with prove because
prove waits until all of its child processes terminate before returning.
So, the solution may be to send a SIGTERM to our stdin-writing fork
should our wrapped process terminate before it does, in order to ensure
that it immediately exits.
The following squash fixes it for me.
Thanks,
Paul
-- >8 --
Subject: [PATCH] squash! test_terminal: redirect child process' stdin to a pty
When the child process terminates before the copy_stdio() finishes
writing all of its data to the child's stdin slave pty, it will stall.
As such, we first move the stdin-pty-writing logic out of copy_stdio()
into its own subroutine copy_stdin() so that we can manage the forked
process ourselves, and then we send SIGTERM to the forked process should
the command we are wrapping terminate before copy_stdin() finishes
writing all of its data to un-stall it.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
---
t/test-terminal.perl | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/t/test-terminal.perl b/t/test-terminal.perl
index f6fc9ae..96b6a03 100755
--- a/t/test-terminal.perl
+++ b/t/test-terminal.perl
@@ -51,24 +51,26 @@ sub xsendfile {
copy($in, $out, 4096) or $!{EIO} or die "cannot copy from child: $!";
}
-sub copy_stdio {
- my ($in, $out, $err) = @_;
+sub copy_stdin {
+ my ($in) = @_;
my $pid = fork;
if (!$pid) {
- close($out);
- close($err);
xsendfile($in, \*STDIN);
exit 0;
}
- $pid = fork;
+ close($in);
+ return $pid;
+}
+
+sub copy_stdio {
+ my ($out, $err) = @_;
+ my $pid = fork;
defined $pid or die "fork failed: $!";
if (!$pid) {
- close($in);
close($out);
xsendfile(\*STDERR, $err);
exit 0;
}
- close($in);
close($err);
xsendfile(\*STDOUT, $out);
finish_child($pid) == 0
@@ -91,5 +93,12 @@ my $pid = start_child(\@ARGV, $master_in->slave, $master_out->slave, $master_err
close $master_in->slave;
close $master_out->slave;
close $master_err->slave;
-copy_stdio($master_in, $master_out, $master_err);
-exit(finish_child($pid));
+my $in_pid = copy_stdin($master_in);
+copy_stdio($master_out, $master_err);
+my $ret = finish_child($pid);
+# If the child process terminates before our copy_stdin() process is able to
+# write all of its data to $master_in, the copy_stdin() process could stall.
+# Send SIGTERM to it to ensure it terminates.
+kill 'TERM', $in_pid;
+finish_child($in_pid);
+exit($ret);
--
2.5.0.282.gdd6b4b0
prev parent reply other threads:[~2015-08-05 17:51 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-24 17:48 "git am" and then "git am -3" regression? Junio C Hamano
2015-07-24 18:09 ` Jeff King
2015-07-26 5:03 ` Paul Tan
2015-07-26 5:21 ` Jeff King
2015-07-27 8:09 ` Matthieu Moy
2015-07-27 8:32 ` Jeff King
2015-07-27 14:21 ` Junio C Hamano
2015-07-28 16:43 ` [PATCH] am: let command-line options override saved options Paul Tan
2015-07-28 16:48 ` Junio C Hamano
2015-07-28 17:09 ` Junio C Hamano
2015-07-31 10:58 ` Paul Tan
2015-07-31 16:04 ` Junio C Hamano
2015-08-01 0:59 ` Paul Tan
2015-08-04 14:05 ` [PATCH v2 0/3] " Paul Tan
2015-08-04 21:12 ` Junio C Hamano
2015-08-04 14:08 ` Paul Tan
2015-08-04 14:08 ` [PATCH v2 1/3] test_terminal: redirect child process' stdin to a pty Paul Tan
2015-08-06 22:15 ` Eric Sunshine
2015-08-12 4:16 ` Paul Tan
2015-08-04 14:08 ` [PATCH v2 2/3] am: let command-line options override saved options Paul Tan
2015-08-04 14:08 ` [PATCH v2 3/3] am: let --signoff override --no-signoff Paul Tan
2015-08-07 9:29 ` Johannes Schindelin
2015-08-12 3:06 ` Paul Tan
2015-08-12 3:07 ` Paul Tan
2015-08-05 15:41 ` [PATCH v2 0/3] am: let command-line options override saved options Junio C Hamano
2015-08-05 17:51 ` Paul Tan [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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150805175117.GA6759@yoshi.chippynet.com \
--to=pyokagan@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=johannes.schindelin@gmx.de \
--cc=peff@peff.net \
--cc=remi.lespinet@ensimag.grenoble-inp.fr \
--cc=sbeller@google.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).