- eval {
- if (defined $initiator_tempdir) {
- rmtree $initiator_tempdir;
- mkdir $initiator_tempdir, 0700 or die "$initiator_tempdir: $!";
- $i_tmp = $initiator_tempdir;
- } else {
- $i_tmp = tempdir();
- }
- my $pid = open2(\*RO, \*RI, @cmd);
- changedir $i_tmp;
- initiator_expect { m/^dgit-remote-push-ready/ };
- for (;;) {
- my ($icmd,$iargs) = initiator_expect {
- m/^(\S+)(?: (.*))?$/;
- ($1,$2);
- };
- i_method "i_resp", $icmd, $iargs;
- }
- };
+
+ if (defined $initiator_tempdir) {
+ rmtree $initiator_tempdir;
+ mkdir $initiator_tempdir, 0700 or die "$initiator_tempdir: $!";
+ $i_tmp = $initiator_tempdir;
+ } else {
+ $i_tmp = tempdir();
+ }
+ $i_child_pid = open2(\*RO, \*RI, @cmd);
+ changedir $i_tmp;
+ initiator_expect { m/^dgit-remote-push-ready/ };
+ for (;;) {
+ my ($icmd,$iargs) = initiator_expect {
+ m/^(\S+)(?: (.*))?$/;
+ ($1,$2);
+ };
+ i_method "i_resp", $icmd, $iargs;
+ }
+
+ my $pid = $i_child_pid;
+ $i_child_pid = undef; # prevents killing some other process with same pid
+ printdebug "waiting for remote child $pid...";
+ my $got = waitpid $pid, 0;
+ die $! unless $got == $pid;
+ die "remote child failed $?" if $?;
+