summaryrefslogtreecommitdiff
path: root/update-xfonts-traditional
diff options
context:
space:
mode:
authorIan Jackson <ijackson@chiark.greenend.org.uk>2012-01-25 21:46:58 +0000
committerIan Jackson <ijackson@chiark.greenend.org.uk>2012-01-25 21:46:58 +0000
commitbd7891126edbe8500e813f10a78082b27156faef (patch)
tree8c5bc004c83d33b24481455a884341d6ee252d75 /update-xfonts-traditional
parent84358b554eaec4aca340b172152e5edc1fa75d83 (diff)
processpcfgz: completely revamped subprocess data structures and error handling
Diffstat (limited to 'update-xfonts-traditional')
-rwxr-xr-xupdate-xfonts-traditional66
1 files changed, 50 insertions, 16 deletions
diff --git a/update-xfonts-traditional b/update-xfonts-traditional
index 8791e22..2e8c0d7 100755
--- a/update-xfonts-traditional
+++ b/update-xfonts-traditional
@@ -176,6 +176,7 @@ sub processpcfgz ($$$$) {
my ($usread,$uswrite);
my ($reader,$writer);
my @children;
+ my %ch;
foreach my $proc (['gunzip'], ['pcf2bdf'], [],
['bdftopcf'],['',qw(gzip -1 -n)]) {
my $isfinal = (@$proc && $proc->[0] eq '');
@@ -201,7 +202,14 @@ sub processpcfgz ($$$$) {
close $uswrite or die $! if $uswrite;
exec $exe @$proc or die "$exe $!";
}
- push @children, [ $child, $exe, defined $usread ];
+ my $ch = {
+ Pid => $child,
+ Exe => $exe,
+ Stage => (!$exe ? 'self' : defined $usread ? 'out' : 'in'),
+ SigOK => { },
+ };
+ push @children, $ch;
+ $ch{$exe} = $ch;
close $current or die $!;
close $writer or die $!;
$current = $reader;
@@ -213,25 +221,51 @@ sub processpcfgz ($$$$) {
}
my $r = processbdf($usread,$uswrite,$logfile,$what);
my $none = $r !~ m/^\d/;
- if ($none) {
+
+ $ch{'gunzip'}{SigOK}{13} = 1;
+ # ... we never care if pcf2bdf didn't want all the output from gunzip
+
+ if ($none || !$r) {
+ # We're not going to install or use this so we can kill our
+ # input and output filters. We kill the input filters so that
+ # we don't risk waiting for them. (If the input filter died
+ # for some other reason then sending it a KILL now won't
+ # affect its exit status.) We kill the output filters (before
+ # we close the output pipe) so we don't produce messages from
+ # our output filters about corrupted data.
flush $uswrite or die $!;
- } else {
- close $uswrite or die $!;
+
+ foreach my $ch (@children) {
+ if ($ch->{Stage} ne 'self') {
+ kill 9, $ch->{Pid} or die "$ch->{Pid} $ch->{Exe} $!";
+ $ch->{SigOK}{9} = 1;
+ }
+ }
+ $ch{'pcf2bdf'}{SigOK}{13} = 1;
+ # ... we might not have read all the output from pcf2bdf, which is OK
}
+ close $uswrite or die $!;
close $usread or die $!;
- foreach my $chinfo (@children) {
- my ($child,$exe,$isoutput)=@$chinfo;
- my $sigok = 0;
- if ($none) {
- if ($isoutput) {
- $sigok = 9;
- kill 9, $child or die "$child $!";
- } else {
- $sigok = 13;
- }
+
+ foreach my $ch (@children) {
+ $!=0; waitpid($ch->{Pid}, 0) == $ch->{Pid} or
+ die "$ch->{Pid} $ch->{Exe} $!";
+ $ch->{St} = $?;
+ }
+
+ my $st_isok = sub {
+ my ($ch) = @_;
+ my $st = $ch->{St};
+ return !$st || $ch->{SigOK}{($st & ~128)};
+ };
+
+ foreach my $ch (@children) {
+ if (!$st_isok->($ch)) {
+ die "update-xfonts-traditional:".
+ " $ch->{Exe} [$ch->{Pid}] for $inpcfgz".
+ " failed $ch->{St}".
+ " (".(join ' ', keys %{ $ch->{SigOK} })." ok)\n";
}
- $!=0; waitpid($child, 0) == $child or die "$child $!";
- !$? or ($?&~128)==$sigok or die "$exe [$child] $sigok $?";
}
return $r;
}