X-Git-Url: https://git.madduck.net/code/myrepos.git/blobdiff_plain/791dd2c6b4bff3e46b8dd45bf1b6d0aa8d15b5bc..a80452ac1f76168ec147d8fabf742ddbb3d57326:/mr diff --git a/mr b/mr index 2b1a36c..68772a0 100755 --- a/mr +++ b/mr @@ -569,15 +569,14 @@ sub action { #{{{ } #}}} # run actions on multiple repos, in parallel -my %jobs; sub mrs { #{{{ $| = 1; + my @active; my @fhs; my @out; my $running=0; while (@fhs or @repos) { while ($running < $jobs && @repos) { - $SIG{CHLD}='DEFAULT'; $running++; my $repo = shift @repos; my $pid = open(my $fh, "-|"); @@ -585,13 +584,11 @@ sub mrs { #{{{ open(STDERR, ">&STDOUT"); exit action($action, @$repo); } - $jobs{$pid}=$repo; + push @active, $repo; push @fhs, $fh; push @out, ""; - reaper(); - $SIG{CHLD}=\&reaper; } - my ($rin, $rout) = ('','', ''); + my ($rin, $rout) = ('',''); my $nfound; foreach my $x (@fhs) { next unless defined $x; @@ -605,6 +602,7 @@ sub mrs { #{{{ my $r = ''; if (sysread($fh, $r, 1024) == 0) { close($fh); + record($active[$i], $? >> 8); $fhs[$i] = undef; $running--; print $out[$i]; @@ -614,18 +612,13 @@ sub mrs { #{{{ } } while (@fhs and !defined $fhs[0]) { + shift @active; shift @fhs; shift @out; } } } #}}} -sub reaper { #{{{ - while ((my $pid = waitpid(-1, &WNOHANG)) > 0) { - record($jobs{$pid}, $? >> 8) if exists $jobs{$pid}; - } -} #}}} - sub record { #{{{ my $dir=shift()->[0]; my $ret=shift;