complete-run: Bugfix: Don’t call recv inside a callback when cleanly exiting i3

This commit is contained in:
Michael Stapelberg 2011-11-07 20:56:36 +00:00
parent dbd6440432
commit fdf7b1706c
1 changed files with 34 additions and 19 deletions

View File

@ -139,7 +139,9 @@ sub take_job {
my $time_before_start = [gettimeofday]; my $time_before_start = [gettimeofday];
my $pid; my $pid;
if (!$dont_start) { if ($dont_start) {
$activate_cv->send(1);
} else {
$pid = activate_i3( $pid = activate_i3(
unix_socket_path => "/tmp/nested-$display-activation", unix_socket_path => "/tmp/nested-$display-activation",
display => $display, display => $display,
@ -161,20 +163,33 @@ sub take_job {
# Dont bother killing i3 when we havent started it # Dont bother killing i3 when we havent started it
return if $dont_start; return if $dont_start;
my $kill_cv = AnyEvent->condvar;
# When measuring code coverage, try to exit i3 cleanly (otherwise, .gcda # When measuring code coverage, try to exit i3 cleanly (otherwise, .gcda
# files are not written) and fallback to killing it # files are not written) and fallback to killing it
if ($coverage_testing) { if ($coverage_testing || $valgrind) {
my $exited = 0; my $exited = 0;
eval { say "[$display] Exiting i3 cleanly...";
say "Exiting i3 cleanly..."; my $i3 = i3("/tmp/nested-$display");
i3("/tmp/nested-$display")->command('exit')->recv; $i3->connect->cb(sub {
$exited = 1; if (!$_[0]->recv) {
}; # Could not connect to i3, just kill -9 it
return if $exited; kill(9, $pid) or die "Could not kill i3 using kill($pid)";
$kill_cv->send();
} else {
# Connected. Now send exit and continue once thats acked.
$i3->command('exit')->cb(sub {
$kill_cv->send();
});
}
});
} else {
# No coverage testing or valgrind? Just kill -9 i3.
kill(9, $pid) or die "Could not kill i3 using kill($pid)";
$kill_cv->send();
} }
say "[$display] killing i3"; return $kill_cv;
kill(9, $pid) or die "could not kill i3";
}; };
# This will be called as soon as i3 is running and answered to our # This will be called as soon as i3 is running and answered to our
@ -224,21 +239,21 @@ sub take_job {
$aggregator->add($test, $parser); $aggregator->add($test, $parser);
push @done, [ $test, $output ]; push @done, [ $test, $output ];
$kill_i3->(); my $exitcv = $kill_i3->();
$exitcv->cb(sub {
undef $_ for @watchers; undef $_ for @watchers;
if (@done == $num) { if (@done == $num) {
$cv->send; $cv->send;
} else { } else {
take_job($display); take_job($display);
} }
});
} }
); );
push @watchers, $w; push @watchers, $w;
} }
}); });
$activate_cv->send(1) if $dont_start;
} }
$cv->recv; $cv->recv;