Move fork processing code to earlier in file.

This commit is contained in:
Bradley M. Kuhn 2016-04-28 20:35:20 -07:00
parent 26edcca3a3
commit 90466f78e4

View file

@ -137,6 +137,25 @@ while (my $line = <STDIN>) {
$WHITELIST_COMMIT_IDS{$line} = $line; $WHITELIST_COMMIT_IDS{$line} = $line;
} }
##############################################################################
# Set up child processing and signal commits.
my %childProcesses;
my %finishedCommits;
$SIG{CHLD} = sub {
# don't change $! and $? outside handler
local ($!, $?);
while ( (my $pid = waitpid(-1, WNOHANG)) > 0 ) {
my($errCode, $errString) = ($?, $!);
my $commitId = $childProcesses{$pid};
my $now = strftime("%Y-%m-%d %H:%M:%S", localtime);
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 };
delete $childProcesses{$pid};
}
};
############################################################################## ##############################################################################
# ProcessCommit is the primary function that processes a commit to generate # ProcessCommit is the primary function that processes a commit to generate
# the blame data. If $fileListRef is defined, it should be a list reference, # the blame data. If $fileListRef is defined, it should be a list reference,
@ -219,22 +238,6 @@ if (defined $CENTRAL_COMMIT) {
exit 0; exit 0;
my %childProcesses;
my %finishedCommits;
$SIG{CHLD} = sub {
# don't change $! and $? outside handler
local ($!, $?);
while ( (my $pid = waitpid(-1, WNOHANG)) > 0 ) {
my($errCode, $errString) = ($?, $!);
my $commitId = $childProcesses{$pid};
my $now = strftime("%Y-%m-%d %H:%M:%S", localtime);
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 };
delete $childProcesses{$pid};
}
};
foreach my $commitId (keys %WHITELIST_COMMIT_IDS) { foreach my $commitId (keys %WHITELIST_COMMIT_IDS) {
my $remainingCount = scalar(keys %childProcesses); my $remainingCount = scalar(keys %childProcesses);
while ($remainingCount >= $FORK_LIMIT) { while ($remainingCount >= $FORK_LIMIT) {