| 1 | # Copyright © 2008-2009 Raphaël Hertzog <hertzog@debian.org> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # Copyright © 2008 Frank Lichtenheld <djpig@debian.org> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # Copyright © 2008-2010, 2012-2015 Guillem Jover <guillem@debian.org> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # This program is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # it under the terms of the GNU General Public License as published by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # the Free Software Foundation; either version 2 of the License, or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # (at your option) any later version. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # GNU General Public License for more details. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # You should have received a copy of the GNU General Public License | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | Dpkg::IPC - helper functions for IPC | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | Dpkg::IPC offers helper functions to allow you to execute | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | other programs in an easy, yet flexible way, while hiding | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | all the gory details of IPC (Inter-Process Communication) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | from you. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | package Dpkg::IPC 1.03; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 556 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 554 | our @EXPORT = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | spawn | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | wait_child | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 556 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 556 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 556 | ▶ | use Dpkg::ErrorHandling; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 556 | ▶ | use Dpkg::Gettext; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | =item $pid = spawn(%opts) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | Creates a child process and executes another program in it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | The arguments are interpreted as a hash of options, specifying | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | how to handle the in and output of the program to execute. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | Returns the pid of the child process (unless the wait_child | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | option was given). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | Any error will cause the function to exit with one of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | L<Dpkg::ErrorHandling> functions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | Options: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | =item B<exec> (required) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | Can be either a scalar, i.e. the name of the program to be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | executed, or an array reference, i.e. the name of the program | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | plus additional arguments. Note that the program will never be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | executed via the shell, so you can't specify additional arguments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | in the scalar string and you can't use any shell facilities like | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | globbing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | =item B<from_file>, B<to_file>, B<error_to_file> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | Filename as scalar. Standard input/output/error of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | child process will be redirected to the file specified. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | =item B<from_handle>, B<to_handle>, B<error_to_handle> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | Filehandle. Standard input/output/error of the child process will be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | dup'ed from the handle. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | =item B<from_pipe>, B<to_pipe>, B<error_to_pipe> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | Scalar reference or object based on L<IO::Handle>. A pipe will be opened for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | each of the two options and either the reading (C<to_pipe> and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | C<error_to_pipe>) or the writing end (C<from_pipe>) will be returned in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | the referenced scalar. Standard input/output/error of the child process | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | will be dup'ed to the other ends of the pipes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | =item B<from_string>, B<to_string>, B<error_to_string> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | Scalar reference. Standard input/output/error of the child | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | process will be redirected to the string given as reference. Note | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | that it wouldn't be strictly necessary to use a scalar reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | for C<from_string>, as the string is not modified in any way. This was | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | chosen only for reasons of symmetry with C<to_string> and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | C<error_to_string>. C<to_string> and C<error_to_string> imply the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | C<wait_child> option. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | =item B<wait_child> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | Scalar. If containing a true value, wait_child() will be called before | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | returning. The return value of spawn() will be a true value, not the pid. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | =item B<no_check> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | Scalar. Option of the wait_child() call. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | =item B<nocheck> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | Deprecated alias for no_check. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | It emits a deprecation warning, but if it is required for backwards | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | compatibility it can be passed alongside B<no_check> and the warning | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | will not be emitted. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | =item B<timeout> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | Scalar. Option of the wait_child() call. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | =item B<chdir> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | Scalar. The child process will chdir in the indicated directory before | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | calling exec. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | =item B<env> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | Hash reference. The child process will populate %ENV with the items of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | hash before calling exec. This allows exporting environment variables. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | =item B<delete_env> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | Array reference. The child process will remove all environment variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | listed in the array before calling exec. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | =item B<sig> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | Hash reference. The child process will populate %SIG with the items of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | hash before calling exec. This allows setting signal dispositions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | =item B<delete_sig> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | Array reference. The child process will reset all signals listed in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | array to their default dispositions before calling exec. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 133958 | ▶ | sub _check_opts { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_opts: called CC=29 SCAR=43.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 133958 | my (%opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | croak 'exec parameter is mandatory in spawn()' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 133958 | ▶ | unless $opts{exec}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 133958 | my $to = my $error_to = my $from = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 133958 | foreach my $thing (qw(file handle string pipe)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 535832 | ▶ | $to++ if $opts{"to_$thing"}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 535832 | ▶ | $error_to++ if $opts{"error_to_$thing"}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 535832 | ▶ | $from++ if $opts{"from_$thing"}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 133958 | ▶ | croak 'not more than one of to_* parameters is allowed' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | if $to > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 133958 | ▶ | croak 'not more than one of error_to_* parameters is allowed' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | if $error_to > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 133958 | ▶ | croak 'not more than one of from_* parameters is allowed' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | if $from > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 133958 | foreach my $param (qw(to_string error_to_string from_string)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 401874 | ▶ | if (exists $opts{$param} and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
exists $opts{$param} and !ref($opts{$param}) || ref $opts{$param} ne "SCALAR"
not ref $opts{$param} or ref $opts{$param} ne "SCALAR"
MC/DC0%0/3
exists $opts{$param} and !ref($opts{$param}) || ref $opts{$param} ne "SCALAR"
exists $opts{$param}
not ref $opts{$param}
ref $opts{$param} ne "SCALAR"
Truth table50%2/4
A and not(B) or C
A= exists $opts{$param}B= not ref $opts{$param}C= ref $opts{$param} ne "SCALAR"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | (not ref $opts{$param} or ref $opts{$param} ne 'SCALAR')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | croak "parameter $param must be a scalar reference"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 133958 | foreach my $param (qw(to_pipe error_to_pipe from_pipe)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 401874 | ▶ | if (exists $opts{$param} and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition44%4/9
exists $opts{$param} and !ref($opts{$param}) || ref $opts{$param} ne "SCALAR" && !$opts{$param}->isa("IO::Handle")
not ref $opts{$param} or ref $opts{$param} ne "SCALAR" and not $opts{$param}->isa("IO::Handle")
ref $opts{$param} ne "SCALAR" and not $opts{$param}->isa("IO::Handle")
MC/DC0%0/4
exists $opts{$param} and !ref($opts{$param}) || ref $opts{$param} ne "SCALAR" && !$opts{$param}->isa("IO::Handle")
exists $opts{$param}
not ref $opts{$param}
ref $opts{$param} ne "SCALAR"
not $opts{$param}->isa("IO::Handle")
Truth table40%2/5
A and not(B) or C and not(D)
A= exists $opts{$param}B= not ref $opts{$param}C= ref $opts{$param} ne "SCALAR"D= not $opts{$param}->isa("IO::Handle")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | (not ref $opts{$param} or (ref $opts{$param} ne 'SCALAR' and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | not $opts{$param}->isa('IO::Handle')))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | croak "parameter $param must be a scalar reference or " . | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 'an IO::Handle object'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 133958 | ▶ | if (exists $opts{timeout} and defined($opts{timeout}) and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
exists $opts{"timeout"} and defined $opts{"timeout"} and not $opts{"timeout"} =~ /^\d+$/u
exists $opts{"timeout"} and defined $opts{"timeout"}
MC/DC0%0/3
exists $opts{"timeout"} and defined $opts{"timeout"} and not $opts{"timeout"} =~ /^\d+$/u
exists $opts{"timeout"}
defined $opts{"timeout"}
not $opts{"timeout"} =~ /^\d+$/u
Truth table50%2/4
A and B and not(C)
A= exists $opts{"timeout"}B= defined $opts{"timeout"}C= not $opts{"timeout"} =~ /^\d+$/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | $opts{timeout} !~ /^\d+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | croak 'parameter timeout must be an integer'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 133958 | ▶ | if (exists $opts{env} and ref($opts{env}) ne 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $opts{"env"} and ref $opts{"env"} ne "HASH"
MC/DC0%0/2
exists $opts{"env"} and ref $opts{"env"} ne "HASH"
exists $opts{"env"}
ref $opts{"env"} ne "HASH"
Truth table66%2/3
A and B
A= exists $opts{"env"}B= ref $opts{"env"} ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | croak 'parameter env must be a hash reference'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 133958 | ▶ | if (exists $opts{delete_env} and ref($opts{delete_env}) ne 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $opts{"delete_env"} and ref $opts{"delete_env"} ne "ARRAY"
MC/DC0%0/2
exists $opts{"delete_env"} and ref $opts{"delete_env"} ne "ARRAY"
exists $opts{"delete_env"}
ref $opts{"delete_env"} ne "ARRAY"
Truth table66%2/3
A and B
A= exists $opts{"delete_env"}B= ref $opts{"delete_env"} ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | croak 'parameter delete_env must be an array reference'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 133958 | ▶ | if (exists $opts{sig} and ref($opts{sig}) ne 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $opts{"sig"} and ref $opts{"sig"} ne "HASH"
MC/DC0%0/2
exists $opts{"sig"} and ref $opts{"sig"} ne "HASH"
exists $opts{"sig"}
ref $opts{"sig"} ne "HASH"
Truth table33%1/3
A and B
A= exists $opts{"sig"}B= ref $opts{"sig"} ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | croak 'parameter sig must be a hash reference'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 133958 | ▶ | if (exists $opts{delete_sig} and ref($opts{delete_sig}) ne 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $opts{"delete_sig"} and ref $opts{"delete_sig"} ne "ARRAY"
MC/DC0%0/2
exists $opts{"delete_sig"} and ref $opts{"delete_sig"} ne "ARRAY"
exists $opts{"delete_sig"}
ref $opts{"delete_sig"} ne "ARRAY"
Truth table33%1/3
A and B
A= exists $opts{"delete_sig"}B= ref $opts{"delete_sig"} ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | croak 'parameter delete_sig must be an array reference'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 133958 | return %opts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 133958 | ▶ | sub spawn { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
spawn: called CC=51 SCAR=41.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 133958 | my (%opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 133958 | my @prog; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 133958 | _check_opts(%opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 133958 | ▶ | $opts{close_in_child} //= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"close_in_child"} //= []
MC/DC0%0/1
$opts{"close_in_child"} //= []
$opts{"close_in_child"}
Truth table50%1/2
A
A= $opts{"close_in_child"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 133958 | ▶ | if (ref($opts{exec}) =~ /ARRAY/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 133946 | push @prog, @{$opts{exec}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } elsif (not ref($opts{exec})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 12 | push @prog, $opts{exec}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | croak 'invalid exec parameter in spawn()'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 133958 | my ($from_string_pipe, $to_string_pipe, $error_to_string_pipe); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 133958 | ▶ | if ($opts{to_string}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 27 | $opts{to_pipe} = \$to_string_pipe; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 27 | $opts{wait_child} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 133958 | ▶ | if ($opts{error_to_string}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 133924 | $opts{error_to_pipe} = \$error_to_string_pipe; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 133924 | $opts{wait_child} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 133958 | ▶ | if ($opts{from_string}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 5 | $opts{from_pipe} = \$from_string_pipe; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | # Create pipes if needed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 133958 | my ($input_pipe, $output_pipe, $error_pipe); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 133958 | ▶ | if ($opts{from_pipe}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 18 | ▶ | pipe($opts{from_handle}, $input_pipe) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | or syserr(g_('cannot create pipe for %s'), "@prog"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 18 | ${$opts{from_pipe}} = $input_pipe; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 18 | push @{$opts{close_in_child}}, $input_pipe; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 133958 | ▶ | if ($opts{to_pipe}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | pipe($output_pipe, $opts{to_handle}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 36 | ▶ | or syserr(g_('cannot create pipe for %s'), "@prog"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 36 | ${$opts{to_pipe}} = $output_pipe; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 36 | push @{$opts{close_in_child}}, $output_pipe; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 133958 | ▶ | if ($opts{error_to_pipe}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | pipe($error_pipe, $opts{error_to_handle}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 133924 | ▶ | or syserr(g_('cannot create pipe for %s'), "@prog"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 133924 | ${$opts{error_to_pipe}} = $error_pipe; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 133924 | push @{$opts{close_in_child}}, $error_pipe; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | # Fork and exec. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 133958 | my $pid = fork(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 133958 | ▶ | syserr(g_('cannot create child process for %s'), "@prog") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | unless defined $pid; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 133958 | ▶ | if (not $pid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # Define environment variables. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 535 | ▶ | if ($opts{env}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 4 | foreach (keys %{$opts{env}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 8 | $ENV{$_} = $opts{env}{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 535 | ▶ | if ($opts{delete_env}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 5 | delete $ENV{$_} foreach (@{$opts{delete_env}}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # Define signal dispositions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 535 | ▶ | if ($opts{sig}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | foreach (keys %{$opts{sig}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | $SIG{$_} = $opts{sig}{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 535 | ▶ | if ($opts{delete_sig}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | delete $SIG{$_} foreach (@{$opts{delete_sig}}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | # Change the current directory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 535 | ▶ | if ($opts{chdir}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | chdir($opts{chdir}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 5 | ▶ | or syserr(g_('cannot change directory to %s'), $opts{chdir}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # Redirect STDIN if needed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 535 | ▶ | if ($opts{from_file}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | open(STDIN, '<', $opts{from_file}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 3 | ▶ | or syserr(g_('cannot open %s'), $opts{from_file}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } elsif ($opts{from_handle}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | open(STDIN, '<&', $opts{from_handle}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 11 | ▶ | or syserr(g_('cannot reopen %s'), g_('<standard input>')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # Has been duped, can be closed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 11 | push @{$opts{close_in_child}}, $opts{from_handle}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | # Redirect STDOUT if needed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 535 | ▶ | if ($opts{to_file}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | open(STDOUT, '>', $opts{to_file}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 3 | ▶ | or syserr(g_('cannot write %s'), $opts{to_file}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } elsif ($opts{to_handle}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | open(STDOUT, '>&', $opts{to_handle}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 14 | ▶ | or syserr(g_('cannot reopen %s'), g_('<standard output>')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | # Has been duped, can be closed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 14 | push @{$opts{close_in_child}}, $opts{to_handle}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | # Redirect STDERR if needed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 535 | ▶ | if ($opts{error_to_file}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | open(STDERR, '>', $opts{error_to_file}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | or syserr(g_('cannot write %s'), $opts{error_to_file}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | } elsif ($opts{error_to_handle}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | open(STDERR, '>&', $opts{error_to_handle}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 524 | ▶ | or syserr(g_('cannot reopen %s'), g_('<standard error>')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | # Has been duped, can be closed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 524 | push @{$opts{close_in_child}}, $opts{error_to_handle}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # Close some inherited filehandles. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 535 | close($_) foreach (@{$opts{close_in_child}}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | # Execute the program. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 535 | ▶ | exec({ $prog[0] } @prog) or syserr(g_('cannot execute %s'), "@prog"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # Close handle that we cannot use any more. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 133423 | ▶ | close($opts{from_handle}) if exists $opts{from_handle}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 133423 | ▶ | close($opts{to_handle}) if exists $opts{to_handle}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 133423 | ▶ | close($opts{error_to_handle}) if exists $opts{error_to_handle}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 133423 | ▶ | if ($opts{from_string}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 4 | print { $from_string_pipe } ${$opts{from_string}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 4 | close($from_string_pipe); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 133423 | ▶ | if ($opts{to_string}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 18 | local $/ = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 18 | ${$opts{to_string}} = readline($to_string_pipe); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 133423 | ▶ | if ($opts{error_to_string}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 133400 | local $/ = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 133400 | ${$opts{error_to_string}} = readline($error_to_string_pipe); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 133423 | ▶ | if ($opts{wait_child}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 133408 | my $cmdline = "@prog"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 133408 | ▶ | if ($opts{env}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 4 | foreach (keys %{$opts{env}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 8 | $cmdline = "$_=\"" . $opts{env}{$_} . "\" $cmdline"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | # TODO: Backwards compatibility, to be removed in VERSION 2.00. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 133408 | ▶ | if (exists $opts{nocheck} && ! exists $opts{no_check}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $opts{"nocheck"} and not exists $opts{"no_check"}
MC/DC0%0/2
exists $opts{"nocheck"} and not exists $opts{"no_check"}
exists $opts{"nocheck"}
not exists $opts{"no_check"}
Truth table33%1/3
A and not(B)
A= exists $opts{"nocheck"}B= not exists $opts{"no_check"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | warnings::warnif('deprecated', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 'Dpkg::IPC::spawn() option nocheck is deprecated, ' . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 'either switch to no_check or pass nocheck alongside it'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | wait_child($pid, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | no_check => $opts{no_check} // $opts{nocheck}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | timeout => $opts{timeout}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 133408 | ▶ | cmdline => $cmdline, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$opts{"no_check"} // $opts{"nocheck"}
MC/DC50%1/2
$opts{"no_check"} // $opts{"nocheck"}
$opts{"no_check"}
$opts{"nocheck"}
Truth table66%2/3
A // B
A= $opts{"no_check"}B= $opts{"nocheck"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 133407 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 15 | return $pid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | =item wait_child($pid, %opts) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | Takes as first argument the pid of the process to wait for. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | Remaining arguments are taken as a hash of options. Returns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | nothing. Fails if the child has been ended by a signal or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | if it exited non-zero. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | Options: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | =item cmdline | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | String to identify the child process in error messages. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | Defaults to "child process". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | =item no_check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | If true do not check the return status of the child (and thus | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | do not fail it has been killed or if it exited with a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | non-zero return code). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | =item nocheck | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | Deprecated alias for no_check. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | It emits a deprecation warning, but if it is required for backwards | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | compatibility it can be passed alongside B<no_check> and the warning | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | will not be emitted. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | =item timeout | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | Set a maximum time to wait for the process, after that kill the process and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | fail with an error message. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 133423 | ▶ | sub wait_child { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wait_child: called CC=13 SCAR=27.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 133423 | my ($pid, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 133423 | ▶ | $opts{cmdline} //= g_('child process'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$opts{"cmdline"} //= g_("child process")
MC/DC0%0/2
$opts{"cmdline"} //= g_("child process")
$opts{"cmdline"}
g_("child process")
Truth table66%2/3
A //= B
A= $opts{"cmdline"}B= g_("child process")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | # TODO: Backwards compatibility, to be removed in VERSION 2.00. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 133423 | ▶ | if (exists $opts{nocheck} && ! exists $opts{no_check}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $opts{"nocheck"} and not exists $opts{"no_check"}
MC/DC0%0/2
exists $opts{"nocheck"} and not exists $opts{"no_check"}
exists $opts{"nocheck"}
not exists $opts{"no_check"}
Truth table33%1/3
A and not(B)
A= exists $opts{"nocheck"}B= not exists $opts{"no_check"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | warnings::warnif('deprecated', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 'Dpkg::IPC::wait_child() option nocheck is deprecated, ' . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 'either switch to no_check or pass nocheck alongside it'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 133423 | ▶ | $opts{no_check} //= $opts{nocheck}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$opts{"no_check"} //= $opts{"nocheck"}
MC/DC50%1/2
$opts{"no_check"} //= $opts{"nocheck"}
$opts{"no_check"}
$opts{"nocheck"}
Truth table66%2/3
A //= B
A= $opts{"no_check"}B= $opts{"nocheck"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 133423 | ▶ | croak 'no PID set, cannot wait end of process' unless $pid; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 133423 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 133423 | ▶ | local $SIG{ALRM} = sub { die "alarm\n" }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 133423 | ▶ | alarm($opts{timeout}) if defined($opts{timeout}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | $pid == waitpid($pid, 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 133423 | ▶ | or syserr(g_('cannot reap %s subprocess'), $opts{cmdline}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 133422 | ▶ | alarm(0) if defined($opts{timeout}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 133423 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 1 | ▶ | die $@ unless $@ eq "alarm\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 1 | kill 'TERM', $pid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | error(P_('%s did not complete in %d second', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | '%s did not complete in %d seconds', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | $opts{timeout}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 1 | $opts{cmdline}, $opts{timeout}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 133422 | ▶ | unless ($opts{no_check}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 17 | ▶ | subprocerr($opts{cmdline}) if $?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 554 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | =head1 CHANGES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | =head2 Version 1.03 (dpkg 1.23.0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | New options: spawn() and wait_child() now accept 'no_check'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | Deprecated options: 'nocheck' in spawn() and wait_child(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | =head2 Version 1.02 (dpkg 1.18.0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | Change options: wait_child() now kills the process when reaching the 'timeout'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | =head2 Version 1.01 (dpkg 1.17.11) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | New options: spawn() now accepts 'sig' and 'delete_sig'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | =head2 Version 1.00 (dpkg 1.15.6) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | Mark the module as public. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | L<Dpkg>, L<Dpkg::ErrorHandling>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||