Various fixes to properly handle children.

The children/parent details were somewhat reversed.  This corrects it.
This commit is contained in:
Bradley M. Kuhn 2016-04-28 18:52:07 -07:00
parent fe75b701e9
commit 722551397d

View file

@ -124,31 +124,38 @@ $SIG{CHLD} = sub {
my($errCode, $errString) = ($?, $!); my($errCode, $errString) = ($?, $!);
my $commitId = $childProcesses{$pid}; my $commitId = $childProcesses{$pid};
my $now = strftime("%Y-%m-%d %H:%M:%S", localtime); my $now = strftime("%Y-%m-%d %H:%M:%S", localtime);
print STDERR "Finished commit $commitId $childProcesses{$pid} in $pid ($!, $?) at $now\n" if $VERBOSE; print STDERR "Finished commit $commitId $childProcesses{$pid} in $pid ($errCode, \"$errString\") at $now\n" if $VERBOSE;
$finishedCommits{$commitId} = { pid => $pid, time => $now, errCode => $errCode, errString => $errString }; $finishedCommits{$commitId} = { pid => $pid, time => $now, errCode => $errCode, errString => $errString };
delete $childProcesses{$pid}; delete $childProcesses{$pid};
} }
}; };
foreach my $commitId (@unfinishedCommitIds) { foreach my $commitId (@unfinishedCommitIds) {
while (scalar(keys %childProcesses) >= $FORK_LIMIT) { my $remainingCount = scalar(keys %childProcesses);
print STDERR "Sleep a bit while children going for ", join(", ", sort values %childProcesses), "\n" if $VERBOSE; while ($remainingCount >= $FORK_LIMIT) {
print STDERR "Sleep a bit while $remainingCount children going for these commits ",
join(", ", sort values %childProcesses), "\n" if $VERBOSE;
sleep 10; sleep 10;
$remainingCount = scalar(keys %childProcesses);
} }
my $forkCount = scalar(keys %childProcesses) + 1; my $forkCount = scalar(keys %childProcesses) + 1;
my $pid = fork(); my $pid = fork();
die "cannot fork: $!" unless defined $pid; die "cannot fork: $!" unless defined $pid;
if ($pid == 0) { if ($pid == 0) { # The new child process is here
print STDERR "Launched $forkCount child to handle $commitId\n" if $VERBOSE; $0 = "$commitId git blame subprocess";
ProcessCommit($commitId, $$);
exit 0; exit 0;
} else { } else { # The parent is here
print STDERR "Launched $forkCount child to handle $commitId\n" if $VERBOSE;
$childProcesses{$pid} = $commitId; $childProcesses{$pid} = $commitId;
ProcessCommit($commitId, $pid);
} }
} }
while (scalar(keys %childProcesses) >= 0) { while (scalar(keys %childProcesses) > 0) {
print STDERR "Sleep a bit while children going for ", join(", ", sort values %childProcesses), "\n" if $VERBOSE; if ($VERBOSE) {
print STDERR "Sleep a bit because these are still running ";
foreach my $pid (keys %childProcesses) { print STDERR " $pid for $childProcesses{$pid}\n"; }
}
sleep 10; sleep 10;
} }