| 1 | package App::teai::Exec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use EV; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Encode (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Config (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Fcntl qw(F_DUPFD F_GETFL F_SETFL O_NONBLOCK); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use POSIX (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use App::teai::Err; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use App::teai::Bus (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use App::teai::Config (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use App::teai::Wire (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use App::teai::Presence (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | our $VERSION = '0.08'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | my $TAIL = 4096; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | my $CHUNK = 65536; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | my $MAX_FD = 65536; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | my $REPLY_PERSIST = 60; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | my $TIMEOUT = 3600; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | my $KILL_GRACE = 5; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | my $PIPE_GRACE = 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | my $OUT_KEEP = App::teai::Wire::MAX_PAYLOAD + 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | my $BAD_UTF8 = 'input was not valid UTF-8; invalid bytes replaced'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | my %SIGNAL_EXIT = (INT => [130, 'interrupted'], TERM => [143, 'terminated'], HUP => [129, 'hangup']); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | my $ACK_TIMEOUT_MS = 5000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | my $PR_SET_PDEATHSIG = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | my $PRCTL = _prctl($Config::Config{archname}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub _knob ($name, $default) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_knob: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | my $v = $ENV{$name} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$ENV{$name} // ""
MC/DC0%0/1
$ENV{$name} // ""
$ENV{$name}
Truth table0%0/2
A
A= $ENV{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | return $v =~ /\A\d+(?:\.\d+)?\z/ && $v > 0 ? $v : $default; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$v =~ /\A\d+(?:\.\d+)?\z/u and $v > 0
MC/DC0%0/2
$v =~ /\A\d+(?:\.\d+)?\z/u and $v > 0
$v =~ /\A\d+(?:\.\d+)?\z/u
$v > 0
Truth table0%0/3
A and B
A= $v =~ /\A\d+(?:\.\d+)?\z/uB= $v > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub _msg ($e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_msg: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | return App::teai::Err::msg($e) if ref $e && eval { $e->isa('App::teai::Err') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $e and eval {
do {
$e->isa("App::teai::Err")
}
}
MC/DC0%0/2
ref $e and eval {
do {
$e->isa("App::teai::Err")
}
}
ref $e
eval {
do {
$e->isa("App::teai::Err")
}
}
Truth table0%0/3
A and B
A= ref $eB= eval {
do {
$e->isa("App::teai::Err")
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | return $e =~ s/\s+at \S+ line \d+\.?\s*\z//r =~ s/\s+\z//r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 2 | ▶ | sub _prctl ($arch) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_prctl: called CC=4 SCAR=25.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | ▶ | return 157 if $arch =~ /\Ax86_64-/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | return 167 if $arch =~ /\A(?:aarch64|riscv64)-/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | return 172 if $arch =~ /\A(?:i[3-6]86|arm)/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub run (%a) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | my $presence = App::teai::Presence->new(kind => "exec", session => $a{session}, bus => sub { $a{bus} }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my $r = eval { _run(%a) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my $e = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $presence->stop; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | die $e if ref $e || length $e; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $e or length $e
MC/DC0%0/2
ref $e or length $e
ref $e
length $e
Truth table0%0/3
A or B
A= ref $eB= length $e
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | return $r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub _run (%a) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | local $SIG{PIPE} = 'IGNORE'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my ($bus, $session, $cmd, $seq) = @a{qw(bus session cmd seq)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | my @watch = grep { $_ ne 'HUP' || ($SIG{HUP} // '') ne 'IGNORE' } sort keys %SIGNAL_EXIT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$_ ne 'HUP' || ($SIG{'HUP'} // '') ne 'IGNORE'
$SIG{"HUP"} // ""
MC/DC0%0/2
$_ ne 'HUP' || ($SIG{'HUP'} // '') ne 'IGNORE'
$_ ne 'HUP'
$SIG{"HUP"}
Truth table0%0/3
A || B
A= $_ ne 'HUP'B= $SIG{"HUP"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my $deadline = App::teai::Bus::_now() + ($a{wait} // 600); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$a{"wait"} // 600
MC/DC0%0/1
$a{"wait"} // 600
$a{"wait"}
Truth table0%0/2
A
A= $a{"wait"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | _brief_for($bus, $session, $seq, $deadline) if defined $seq; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | my $lock = _lock($bus, $session, $deadline) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | or App::teai::Err::fail(4, "session $session is being read by another process"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | my $rec = _take($bus, $session, $deadline, $seq) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | or App::teai::Err::fail(1, "no message for $session"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my ($caught, $stop, %sig); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | for my $name (@watch) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | $sig{$name} = EV::signal $name, sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | $caught //= $name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$caught //= $name
MC/DC0%0/2
$caught //= $name
$caught
$name
Truth table0%0/3
A //= B
A= $caughtB= $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | $stop->($SIGNAL_EXIT{$name}[1]) if $stop; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | _intake($bus, $rec); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | _test_pause($bus, $ENV{TEAI_TEST_PAUSE_SPAWN}, \$caught) if defined $ENV{TEAI_TEST_PAUSE_SPAWN}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my $reply; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if ($caught) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $reply = _answer($session, $rec, '', { stopped => $SIGNAL_EXIT{$caught}[1] }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | my $input = Encode::encode('UTF-8', $rec->{body} // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$rec->{"body"} // ""
MC/DC0%0/1
$rec->{"body"} // ""
$rec->{"body"}
Truth table0%0/2
A
A= $rec->{"body"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | my $res = $bus->await(sub ($done) { $stop = _spawn($cmd, $input, $a{timeout} // $TIMEOUT, \@watch, $done) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Condition0%0/3
$a{"timeout"} // $TIMEOUT
MC/DC0%0/2
$a{"timeout"} // $TIMEOUT
$a{"timeout"}
$TIMEOUT
Truth table0%0/3
A // B
A= $a{"timeout"}B= $TIMEOUT
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | undef $stop; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $reply = _reply($session, $rec, $res); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my $to = App::teai::Wire::session_subject($rec->{from}, $session); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $bus->persist($REPLY_PERSIST); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | my $sent = eval { $bus->await(sub ($done) { $bus->publish($to, $reply, $done) }); 1 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my $why = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | %sig = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | App::teai::Err::fail(3, "reply for #$rec->{seq} not sent: " . _msg($why) . '; outcome unknown to the asker') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | unless $sent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | App::teai::Err::fail(@{ $SIGNAL_EXIT{$caught} }) if $caught; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub _lock ($bus, $session, $deadline) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lock: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $poll; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | return $bus->await(sub ($done) { $poll = $bus->lock_wait($session, $deadline, $done) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub _brief_for ($bus, $session, $seq, $deadline) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_brief_for: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | my $m = $bus->await(sub ($done) { $bus->lookup($seq, $deadline, $done) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | App::teai::Err::fail(2, "#$seq is not a brief for $session") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | unless ($m->{kind} eq 'ask' || $m->{kind} eq 'msg') && $m->{to} eq $session; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$m->{"kind"} eq "ask" || $m->{"kind"} eq "msg" and $m->{"to"} eq $session
$m->{"kind"} eq "ask" or $m->{"kind"} eq "msg"
MC/DC0%0/3
$m->{"kind"} eq "ask" || $m->{"kind"} eq "msg" and $m->{"to"} eq $session
$m->{"kind"} eq "ask"
$m->{"kind"} eq "msg"
$m->{"to"} eq $session
Truth table0%0/5
A or B and C
A= $m->{"kind"} eq "ask"B= $m->{"kind"} eq "msg"C= $m->{"to"} eq $session
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | sub _test_pause ($bus, $path, $caught) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_test_pause: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if (open my $fh, '>', "$path.ready") { close $fh } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | my $poll; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | $bus->await(sub ($done) { $poll = EV::timer 0, 0.05, sub { $done->(1) if $$caught || -e "$path.go" } }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Subroutine
__ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
Condition0%0/3
$$caught or -e "$path.go"
MC/DC0%0/2
$$caught or -e "$path.go"
$$caught
-e "$path.go"
Truth table0%0/3
A or B
A= $$caughtB= -e "$path.go"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | sub _take ($bus, $session, $deadline, $seq = undef) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_take: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | return $bus->await(sub ($done) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my ($next, $up); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | my $end = sub (@r) { undef $next; undef $up; $done->(@r) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | my $take = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $o = App::teai::Bus::slice($deadline); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | $bus->fetch($session, $o, sub ($r, $e = undef) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | return App::teai::Bus::lost($e) ? $next->() : $end->(undef, $e) if defined $e; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | return $o->{no_wait} ? $end->(undef) : $next->() unless $r; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ($r->{kind} eq 'ask' || $r->{kind} eq 'msg') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$r->{"kind"} eq "ask" or $r->{"kind"} eq "msg"
MC/DC0%0/2
$r->{"kind"} eq "ask" or $r->{"kind"} eq "msg"
$r->{"kind"} eq "ask"
$r->{"kind"} eq "msg"
Truth table0%0/3
A or B
A= $r->{"kind"} eq "ask"B= $r->{"kind"} eq "msg"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | return $end->($r) if !defined $seq || $r->{seq} == $seq; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $seq or $r->{"seq"} == $seq
MC/DC0%0/2
not defined $seq or $r->{"seq"} == $seq
not defined $seq
$r->{"seq"} == $seq
Truth table0%0/3
not(A) or B
A= not defined $seqB= $r->{"seq"} == $seq
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if ($r->{seq} > $seq) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | return _confirm($bus, $deadline, 'nak', $r, sub ($ok, $e = undef) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | $end->(undef, $ok | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | ? App::teai::Bus::_err(1, "brief #$seq is not in ${session}'s inbox (next is #$r->{seq})") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | : App::teai::Bus::_err(3, "nak for #$r->{seq} not confirmed: " . _msg($e))); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | return _confirm($bus, $deadline, 'ack', $r, sub ($ok, $e = undef) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | return $end->(undef, App::teai::Bus::_err(3, "ack for #$r->{seq} not confirmed: " . _msg($e))) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | unless $ok; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | print STDERR "teai: skipped stale brief #$r->{seq}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | $next->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | if (!print STDERR Encode::encode('UTF-8', App::teai::Wire::format_human($r))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | $bus->nak($r); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | return $bus->flush(sub (@) { $end->(undef, 'output failed') }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | $bus->ack($r) or return $end->(undef, $@); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $next->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | $next = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | my $t = $bus->when_up($deadline, $take, sub ($e) { $end->(undef, $e) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | $up = $t if $t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | $next->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | sub _confirm ($bus, $deadline, $verb, $rec, $cb) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_confirm: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | my ($try, $up); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | my $end = sub (@r) { undef $try; undef $up; $cb->(@r) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | $try = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | $bus->$verb($rec) or return $end->(undef, $@); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | $bus->flush(sub ($ok, $e = undef) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | return $end->(1) if $ok; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | return $end->(undef, $e) unless App::teai::Bus::lost($e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | my $t = $bus->when_up($deadline, $try, sub ($f) { $end->(undef, $f) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | $up = $t if $t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | $try->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | sub _intake ($bus, $rec) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_intake: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | $bus->await(sub ($done) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | $bus->nats->request($rec->{reply}, '+ACK', sub ($body, $e = undef, $head = undef, @) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | return $done->(undef, $e) if defined $e; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | my ($status) = ($head // '') =~ m{\ANATS/1\.0[ \t]+([45]\d\d[^\r\n]*)}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$head // ""
MC/DC0%0/1
$head // ""
$head
Truth table0%0/2
A
A= $head
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | return $done->(undef, $status) if defined $status; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | $body //= ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$body //= ""
MC/DC0%0/1
$body //= ""
$body
Truth table0%0/2
A
A= $body
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | return $done->(1) if $body eq '' || $body eq '+OK'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$body eq "" or $body eq "+OK"
MC/DC0%0/2
$body eq "" or $body eq "+OK"
$body eq ""
$body eq "+OK"
Truth table0%0/3
A or B
A= $body eq ""B= $body eq "+OK"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | $done->(undef, 'unexpected reply: ' . substr($body, 0, 80)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | }, _knob('TEAI_TEST_ACK_TIMEOUT_MS', $ACK_TIMEOUT_MS)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | App::teai::Err::fail(3, "intake ack for #$rec->{seq} not confirmed: " . _msg($@)) unless $ok; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | sub _nonblock ($fh) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_nonblock: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my $flags = fcntl $fh, F_GETFL, 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | fcntl $fh, F_SETFL, $flags | O_NONBLOCK if defined $flags; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | sub _pdeathsig () { defined $PRCTL ? syscall($PRCTL, $PR_SET_PDEATHSIG, POSIX::SIGKILL()) : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pdeathsig: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | sub _child ($cmd, $mask, $reset, $parent, @std) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_child: not called CC=12 SCAR=48.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | my $pdeath = _pdeathsig(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | my $why = "$!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | POSIX::_exit(1) if getppid() != $parent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | $SIG{$_} = 'DEFAULT' for 'PIPE', @$reset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | POSIX::setpgid(0, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | $mask->delset($_) for POSIX::SIGINT(), POSIX::SIGTERM(), POSIX::SIGHUP(), POSIX::SIGCHLD(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | POSIX::sigprocmask(POSIX::SIG_SETMASK(), $mask); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | delete @ENV{ grep { /\ATEAI_/ } keys %ENV }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | my @fd = map { fcntl($_, F_DUPFD, 3) // die } @std; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
fcntl($_, 0, 3) // die()
MC/DC0%0/1
fcntl($_, 0, 3) // die()
fcntl($_, 0, 3)
Truth table0%0/2
A
A= fcntl($_, 0, 3)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | POSIX::dup2($fd[$_], $_) // die for 0 .. 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
POSIX::dup2($fd[$_], $_) // die()
MC/DC0%0/1
POSIX::dup2($fd[$_], $_) // die()
POSIX::dup2($fd[$_], $_)
Truth table0%0/2
A
A= POSIX::dup2($fd[$_], $_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | my $max = POSIX::sysconf(POSIX::_SC_OPEN_MAX()) // $MAX_FD; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
POSIX::sysconf(4) // $MAX_FD
MC/DC0%0/2
POSIX::sysconf(4) // $MAX_FD
POSIX::sysconf(4)
$MAX_FD
Truth table0%0/3
A // B
A= POSIX::sysconf(4)B= $MAX_FD
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | $max = $MAX_FD if $max > $MAX_FD; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | POSIX::close($_) for 3 .. $max - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | if ($pdeath == -1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | print STDERR "teai: cannot set the parent death signal: $why\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | { no warnings 'exec'; exec { $cmd->[0] } @$cmd; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | my $errno = $!; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | print STDERR "teai: cannot run $cmd->[0]: $errno\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | POSIX::_exit($errno == POSIX::EACCES() ? 126 : 127); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | POSIX::_exit(127); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | sub _zombie ($pid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_zombie: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | open my $f, "<", "/proc/$pid/stat" or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | return ((<$f> // "") =~ /.*\)\s+Z\s/s) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
readline $f // ""
MC/DC0%0/1
readline $f // ""
readline $f
Truth table0%0/2
A
A= readline $f
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | sub _spawn ($cmd, $input, $timeout, $reset, $done) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_spawn: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | my $fail = sub ($e) { $done->({ error => $e }); return }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | my ($in_r, $in_w, $out_r, $out_w, $err_r, $err_w); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | pipe($in_r, $in_w) && pipe($out_r, $out_w) && pipe($err_r, $err_w) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
pipe $in_r, $in_w and pipe $out_r, $out_w and pipe $err_r, $err_w
pipe $in_r, $in_w and pipe $out_r, $out_w
MC/DC0%0/3
pipe $in_r, $in_w and pipe $out_r, $out_w and pipe $err_r, $err_w
pipe $in_r, $in_w
pipe $out_r, $out_w
pipe $err_r, $err_w
Truth table0%0/4
A and B and C
A= pipe $in_r, $in_wB= pipe $out_r, $out_wC= pipe $err_r, $err_w
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | or return $fail->("pipe: $!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my $parent = $$; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | my $mask = POSIX::SigSet->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | POSIX::sigprocmask(POSIX::SIG_BLOCK(), POSIX::SigSet->new(POSIX::SIGINT(), POSIX::SIGTERM(), POSIX::SIGHUP()), $mask); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | my $pid = fork // do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
fork // do {
my $e = "fork: $!";
POSIX::sigprocmask(2, $mask);
return &$fail($e)
}
MC/DC0%0/2
fork // do {
my $e = "fork: $!";
POSIX::sigprocmask(2, $mask);
return &$fail($e)
}
fork
do {
my $e = "fork: $!";
POSIX::sigprocmask(2, $mask);
return &$fail($e)
}
Truth table0%0/3
A // B
A= forkB= do {
my $e = "fork: $!";
POSIX::sigprocmask(2, $mask);
return &$fail($e)
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | my $e = "fork: $!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | POSIX::sigprocmask(POSIX::SIG_SETMASK(), $mask); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | return $fail->($e); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | _child($cmd, $mask, $reset, $parent, $in_r, $out_w, $err_w) unless $pid; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | POSIX::setpgid($pid, $pid); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | POSIX::sigprocmask(POSIX::SIG_SETMASK(), $mask); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | close $_ for $in_r, $out_w, $err_w; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | _nonblock($_) for $in_w, $out_r, $err_r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | my %res = (out => '', err => '', bytes => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | my %fh = (out => $out_r, err => $err_r); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | my ($exited, $group, $off, %w) = (0, 0, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | my $close_in = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | delete $w{in}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | close $in_w if $in_w; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | undef $in_w; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | my $finish = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | return unless $exited && !%fh; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$exited and not %fh
MC/DC0%0/2
$exited and not %fh
$exited
not %fh
Truth table0%0/3
A and not(B)
A= $exitedB= not %fh
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | $close_in->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | %w = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | kill 'KILL', -$pid if $group && kill 0, -$pid; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$group and kill 0, -$pid
MC/DC0%0/2
$group and kill 0, -$pid
$group
kill 0, -$pid
Truth table0%0/3
A and B
A= $groupB= kill 0, -$pid
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | $done->(\%res); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | my $shut = sub ($key) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | delete $w{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | close delete $fh{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | my $stop = sub ($why) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | return if $exited || defined $res{stopped}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$exited or defined $res{"stopped"}
MC/DC0%0/2
$exited or defined $res{"stopped"}
$exited
defined $res{"stopped"}
Truth table0%0/3
A or B
A= $exitedB= defined $res{"stopped"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | return if _zombie($pid); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | $res{stopped} = $why; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | kill $_, -$pid for 'TERM', 'CONT'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | $w{kill} = EV::timer _knob('TEAI_TEST_KILL_GRACE', $KILL_GRACE), 0, sub { kill 'KILL', -$pid }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | $w{timeout} = EV::timer $timeout, 0, sub { $stop->('timeout') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | $w{child} = EV::child $pid, 0, sub ($cw, @) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | $cw->stop; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | $res{status} = $cw->rstatus; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | $exited = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $group = kill 0, -$pid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | delete $w{timeout}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | if (defined $res{stopped}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | kill 'KILL', -$pid if $group; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | delete $w{kill}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | if (%fh) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | $w{grace} = EV::timer $PIPE_GRACE, 0, sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | $shut->($_) for keys %fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | $finish->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | $finish->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | for my $key (keys %fh) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | my $fh = $fh{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | $w{$key} = EV::io $fh, EV::READ, sub (@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | my $buf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | my $n = sysread $fh, $buf, $CHUNK; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | return if !defined $n && ($!{EAGAIN} || $!{EINTR}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not defined $n and $!{"EAGAIN"} || $!{"EINTR"}
$!{"EAGAIN"} or $!{"EINTR"}
MC/DC0%0/3
not defined $n and $!{"EAGAIN"} || $!{"EINTR"}
not defined $n
$!{"EAGAIN"}
$!{"EINTR"}
Truth table0%0/4
not(A) and B or C
A= not defined $nB= $!{"EAGAIN"}C= $!{"EINTR"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | if (!defined $n) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | $res{error} //= ($key eq "out" ? "stdout" : "stderr") . " read failed: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$res{"error"} //= ($key eq "out" ? "stdout" : "stderr") . " read failed: $!"
MC/DC0%0/1
$res{"error"} //= ($key eq "out" ? "stdout" : "stderr") . " read failed: $!"
$res{"error"}
Truth table0%0/2
A
A= $res{"error"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | $shut->($key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | return $finish->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | if (!$n) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | $shut->($key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | return $finish->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | if ($key eq 'out') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | $res{bytes} += $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | my $room = $OUT_KEEP - length $res{out}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | $res{out} .= substr $buf, 0, $room if $room > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | $res{err} .= $buf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | if (length $res{err} > 2 * $TAIL) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | substr $res{err}, 0, length($res{err}) - $TAIL, ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | $res{cut} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | if (length $input) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | $w{in} = EV::io $in_w, EV::WRITE, sub (@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | my $n = syswrite $in_w, $input, $CHUNK, $off; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | if (defined $n) { $off += $n; return if $off < length $input } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | elsif ($!{EAGAIN} || $!{EINTR}) { return } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$!{"EAGAIN"} or $!{"EINTR"}
MC/DC0%0/2
$!{"EAGAIN"} or $!{"EINTR"}
$!{"EAGAIN"}
$!{"EINTR"}
Truth table0%0/3
A or B
A= $!{"EAGAIN"}B= $!{"EINTR"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | $close_in->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | $close_in->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | return $stop; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | sub _answer ($session, $rec, $body, $status) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_answer: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | kind => 'reply', re => $rec->{seq}, thread => $rec->{thread}, body => $body, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | agent => App::teai::Config::agent_of($session), status => $status, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | sub _reply ($session, $rec, $res) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reply: not called CC=16 SCAR=56.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | my $out = $res->{out} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$res->{"out"} // ""
MC/DC0%0/1
$res->{"out"} // ""
$res->{"out"}
Truth table0%0/2
A
A= $res->{"out"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | my $bytes = $res->{bytes} // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$res->{"bytes"} // 0
MC/DC0%0/1
$res->{"bytes"} // 0
$res->{"bytes"}
Truth table0%0/2
A
A= $res->{"bytes"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | my $over = $bytes > length $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | $out =~ s/(?:[\xC0-\xDF]|[\xE0-\xEF][\x80-\xBF]?|[\xF0-\xF7][\x80-\xBF]{0,2})\z// if $over; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | my ($body, $bad) = App::teai::Wire::text_in($out); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | my $err = $res->{err} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$res->{"err"} // ""
MC/DC0%0/1
$res->{"err"} // ""
$res->{"err"}
Truth table0%0/2
A
A= $res->{"err"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | my $cut = $res->{cut} || length $err > $TAIL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$res->{'cut'} || length $err > $TAIL
MC/DC0%0/2
$res->{'cut'} || length $err > $TAIL
$res->{'cut'}
length $err > $TAIL
Truth table0%0/3
A || B
A= $res->{'cut'}B= length $err > $TAIL
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | $err = substr $err, -$TAIL if length $err > $TAIL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | $err =~ s/\A[\x80-\xBF]{1,3}// if $cut; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | my $st = $res->{status}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | my %status = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | exit => defined $st && POSIX::WIFEXITED($st) ? POSIX::WEXITSTATUS($st) : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | signal => defined $st && POSIX::WIFSIGNALED($st) ? POSIX::WTERMSIG($st) : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | stderr_tail => (App::teai::Wire::text_in($err))[0], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | (defined $res->{error} ? (error => $res->{error}) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | (defined $res->{stopped} ? (stopped => $res->{stopped}) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
Condition0%0/6
defined $st and POSIX::WIFEXITED($st)
defined $st and POSIX::WIFSIGNALED($st)
MC/DC0%0/2
defined $st and POSIX::WIFEXITED($st)
defined $st
POSIX::WIFEXITED($st)
MC/DC0%0/2
defined $st and POSIX::WIFSIGNALED($st)
defined $st
POSIX::WIFSIGNALED($st)
Truth table0%0/3
A and B
A= defined $stB= POSIX::WIFEXITED($st)
Truth table0%0/3
A and B
A= defined $stB= POSIX::WIFSIGNALED($st)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | ($over ? (error => 'size', bytes => $bytes) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | if ($bad) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | $status{warning} = 'stdout was not valid UTF-8; invalid bytes replaced'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | print STDERR "teai: $BAD_UTF8\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | my $reply = _answer($session, $rec, $body, \%status); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | _fit($reply, $bytes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | return $reply; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | sub _fits ($p) { eval { App::teai::Wire::encode_payload($p); 1 } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fits: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | sub _fit ($reply, $bytes) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fit: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | return if _fits($reply); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | @{ $reply->{status} }{qw(error bytes)} = ('size', $bytes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | my $text = $reply->{body}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | my ($lo, $hi) = (0, length $text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | $hi = App::teai::Wire::MAX_PAYLOAD + 1 if $hi > App::teai::Wire::MAX_PAYLOAD + 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | while ($hi - $lo > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | my $mid = ($lo + $hi) >> 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | $reply->{body} = substr $text, 0, $mid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | _fits($reply) ? ($lo = $mid) : ($hi = $mid); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | $reply->{body} = substr $text, 0, $lo; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||