| 1 | package IPC::Manager::Service::State; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 456 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 456 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 456 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 456 | ▶ | use IPC::Manager::Util qw/require_mod clone_io/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 456 | ▶ | use IPC::Manager::Serializer::JSON(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 456 | ▶ | use Long::Jump qw/setjump longjump havejump/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 456 | ▶ | use POSIX(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 456 | my $base_0 = $0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 456 | my $service_inst; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | my $_post_exec_run = sub { 255 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | sub import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | my $json = shift @ARGV; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | my $params = IPC::Manager::Serializer::JSON->deserialize($json); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | my $exec = delete $params->{exec} // {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $params->{"exec"} // {}
MC/DC0%0/1
delete $params->{"exec"} // {}
delete $params->{"exec"}
Truth table0%0/2
A
A= delete $params->{"exec"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | $params->{orig_io} = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | stderr => clone_io('>&', \*STDERR), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | stdout => clone_io('>&', \*STDOUT), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | stdin => clone_io('<&', \*STDIN), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | my $svc_class = require_mod($params->{class} // 'IPC::Manager::Service'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$params->{"class"} // "IPC::Manager::Service"
MC/DC0%0/1
$params->{"class"} // "IPC::Manager::Service"
$params->{"class"}
Truth table0%0/2
A
A= $params->{"class"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | my $new_inst = $svc_class->new(%$params); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | my $exit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | my $code = sub { _ipcm_service(%$params, new_inst => $new_inst); $exit = 0 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ($exec->{stay_in_begin}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | $exit = 255; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | $_post_exec_run = sub { $exit }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $code->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | $_post_exec_run = $code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | sub ipcm_worker { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 16 | ▶ | my ($name, $cb) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ipcm_worker: called CC=6 SCAR=19.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 16 | ▶ | croak "ipcm_service_worker() can only be called from inside a service" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$service_inst and ref $service_inst ne "CODE"
MC/DC0%0/2
$service_inst and ref $service_inst ne "CODE"
$service_inst
ref $service_inst ne "CODE"
Truth table33%1/3
A and B
A= $service_instB= ref $service_inst ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | unless $service_inst && ref($service_inst) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 16 | ▶ | my $pid = fork // die "Could not fork: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
fork // die("Could not fork: $!")
MC/DC0%0/1
fork // die("Could not fork: $!")
fork
Truth table50%1/2
A
A= fork
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 16 | ▶ | if ($pid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 12 | $service_inst->register_worker($name => $pid); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 12 | return $pid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 4 | $0 = "$0 $name"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 4 | $service_inst = $cb; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 4 | ▶ | croak "ipcm_worker: no IPCM_SERVICE jump point on the stack (worker invoked outside a running service?)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | unless havejump 'IPCM_SERVICE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 4 | longjump IPCM_SERVICE => (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | die "This should not be reachable"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | sub ipcm_service { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 269 | ▶ | my ($name, @args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ipcm_service: called CC=35 SCAR=41.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 269 | ▶ | my $return_handle = defined(wantarray) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 269 | my %params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 269 | ▶ | if (@args == 1 && ref($args[0]) eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
@args == 1 and ref $args[0] eq "CODE"
MC/DC50%1/2
@args == 1 and ref $args[0] eq "CODE"
@args == 1
ref $args[0] eq "CODE"
Truth table66%2/3
A and B
A= @args == 1B= ref $args[0] eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 16 | $params{class} = 'IPC::Manager::Service'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 16 | $params{on_all} = $args[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | ▶ | elsif (@args == 2 && ref($args[0]) eq 'HASH' && ref($args[1]) eq 'CODE') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
@args == 2 and ref $args[0] eq "HASH" and ref $args[1] eq "CODE"
@args == 2 and ref $args[0] eq "HASH"
MC/DC0%0/3
@args == 2 and ref $args[0] eq "HASH" and ref $args[1] eq "CODE"
@args == 2
ref $args[0] eq "HASH"
ref $args[1] eq "CODE"
Truth table25%1/4
A and B and C
A= @args == 2B= ref $args[0] eq "HASH"C= ref $args[1] eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | %params = %{$args[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $params{class} = 'IPC::Manager::Service'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | $params{on_all} = $args[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 253 | %params = @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 269 | my $skip_role_checks = delete $params{skip_role_checks}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 269 | my $exec = delete $params{exec}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 269 | $params{name} = $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 269 | ▶ | $params{orig_io} //= $service_inst ? $service_inst->orig_io : { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$params{"orig_io"} //= $service_inst ? $service_inst->orig_io : {"stderr", clone_io(">&", \*STDERR), "stdout", clone_io(">&", \*STDOUT), "stdin", clone_io("<&", \*STDIN)}
MC/DC0%0/2
$params{"orig_io"} //= $service_inst ? $service_inst->orig_io : {"stderr", clone_io(">&", \*STDERR), "stdout", clone_io(">&", \*STDOUT), "stdin", clone_io("<&", \*STDIN)}
$params{"orig_io"}
$service_inst ? $service_inst->orig_io : {"stderr", clone_io(">&", \*STDERR), "stdout", clone_io(">&", \*STDOUT), "stdin", clone_io("<&", \*STDIN)}
Truth table33%1/3
A //= B
A= $params{"orig_io"}B= $service_inst ? $service_inst->orig_io : {"stderr", clone_io(">&", \*STDERR), "stdout", clone_io(">&", \*STDOUT), "stdin", clone_io("<&", \*STDIN)}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | stderr => clone_io('>&', \*STDERR), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | stdout => clone_io('>&', \*STDOUT), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | stdin => clone_io('<&', \*STDIN), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } unless $exec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 269 | ▶ | if ($service_inst && !$params{redirect}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$service_inst and not $params{"redirect"}
MC/DC50%1/2
$service_inst and not $params{"redirect"}
$service_inst
not $params{"redirect"}
Truth table66%2/3
A and not(B)
A= $service_instB= not $params{"redirect"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 16 | ▶ | if (my $redir = $service_inst->redirect) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | $params{redirect} = $redir unless defined($redir->{inherit}) && !$redir->{inherit}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $redir->{"inherit"} and not $redir->{"inherit"}
MC/DC0%0/2
defined $redir->{"inherit"} and not $redir->{"inherit"}
defined $redir->{"inherit"}
not $redir->{"inherit"}
Truth table0%0/3
A and not(B)
A= defined $redir->{"inherit"}B= not $redir->{"inherit"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 269 | my $new_ipcm = delete $params{new_ipcm}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 269 | ▶ | my $handle_params = delete $params{handle_params} // {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $params{"handle_params"} // {}
MC/DC0%0/1
delete $params{"handle_params"} // {}
delete $params{"handle_params"}
Truth table50%1/2
A
A= delete $params{"handle_params"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 269 | ▶ | if ($params{ipcm_info}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | croak "'new_ipcm' and 'ipcm_info' may not be combined" if $new_ipcm; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 269 | ▶ | if ($service_inst && !$new_ipcm) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$service_inst and not $new_ipcm
MC/DC50%1/2
$service_inst and not $new_ipcm
$service_inst
not $new_ipcm
Truth table66%2/3
A and not(B)
A= $service_instB= not $new_ipcm
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 16 | $handle_params->{_peer} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 16 | $params{ipcm_info} = $service_inst->ipcm_info; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | elsif ($return_handle) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 253 | require IPC::Manager; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 253 | $handle_params->{spawn} = IPC::Manager::ipcm_spawn(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 253 | $params{ipcm_info} = $handle_params->{spawn}->info; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 253 | $params{watch_pids} = [$$]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | croak "Cannot be called in void context without providing 'ipcm_info'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 269 | ▶ | my $class = require_mod($params{class} // 'IPC::Manager::Service'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$params{"class"} // "IPC::Manager::Service"
MC/DC0%0/1
$params{"class"} // "IPC::Manager::Service"
$params{"class"}
Truth table50%1/2
A
A= $params{"class"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 269 | ▶ | croak "'$class' does not implement the 'IPC::Manager::Role::Service' role" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$skip_role_checks or Role::Tiny::does_role($class, "IPC::Manager::Role::Service")
MC/DC0%0/2
$skip_role_checks or Role::Tiny::does_role($class, "IPC::Manager::Role::Service")
$skip_role_checks
Role::Tiny::does_role($class, "IPC::Manager::Role::Service")
Truth table33%1/3
A or B
A= $skip_role_checksB= Role::Tiny::does_role($class, "IPC::Manager::Role::Service")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | unless $skip_role_checks || Role::Tiny::does_role($class, 'IPC::Manager::Role::Service'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 269 | my $new_inst = $class->new(%params); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 269 | $new_inst->pre_fork_hook(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # Forward the stay_in_begin flag (only) into the child's params. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # The 'exec' key is otherwise stripped on the parent side and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # child needs to know whether import() should call _ipcm_service | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # synchronously at BEGIN time (stay_in_begin = 1) or stash the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # closure for the -e snippet to fire at runtime. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | $exec->{json} = IPC::Manager::Serializer::JSON->serialize({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | %params, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 269 | ▶ | exec => { stay_in_begin => $exec->{stay_in_begin} ? 1 : 0 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | }) if $exec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 269 | ▶ | my $pid = fork // die "Could not fork: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
fork // die("Could not fork: $!")
MC/DC0%0/1
fork // die("Could not fork: $!")
fork
Truth table50%1/2
A
A= fork
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # In parent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 269 | ▶ | if ($pid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 148 | ▶ | return unless $return_handle || $exec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$return_handle or $exec
MC/DC50%1/2
$return_handle or $exec
$return_handle
$exec
Truth table66%2/3
A or B
A= $return_handleB= $exec
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 144 | my $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 144 | ▶ | if (delete $handle_params->{_peer}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 4 | $out = $service_inst->peer($params{name}, %$handle_params); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 140 | $out = $new_inst->handle(%$handle_params, name => "service_parent_$$"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 144 | ▶ | my $timeout = $params{timeout} || 10; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$params{'timeout'} || 10
MC/DC0%0/1
$params{'timeout'} || 10
$params{'timeout'}
Truth table50%1/2
A
A= $params{'timeout'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 144 | ▶ | croak "Timeout waiting for service to come up after ${timeout}s" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | unless $out->ready($timeout); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 144 | $out->_set_child_pid($pid); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 144 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 121 | $new_inst->post_fork_hook(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 121 | ▶ | if ($exec) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 5 | ▶ | my $cmd = $exec->{cmd} // []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$exec->{"cmd"} // []
MC/DC0%0/1
$exec->{"cmd"} // []
$exec->{"cmd"}
Truth table50%1/2
A
A= $exec->{"cmd"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 5 | my $json = $exec->{json}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | exec( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | $^X, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 5 | @{$cmd}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 5 | "-M${ \__PACKAGE__ }", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 5 | "-e" => "exit(${ \__PACKAGE__ }\::_post_exec_run())", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | $json, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 116 | @_ = (%params, new_inst => $new_inst); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 116 | goto \&_ipcm_service; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | sub _post_exec_run { $_post_exec_run->() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_post_exec_run: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | sub _ipcm_service { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 116 | ▶ | my %params = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ipcm_service: called CC=7 SCAR=22.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 116 | my $name = $params{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 116 | my $new_inst = delete $params{new_inst}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 116 | $new_inst->set_pid($$); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 116 | ▶ | $0 = delete($params{rebase_0}) ? "$base_0 $name" : "$0 $name"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # Figure out if we already had a service | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 116 | ▶ | my $prev_service = $service_inst ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # Set the new instance as the current one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 116 | $service_inst = $new_inst; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # If a service is already running on the stack, unwind back to its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # setjump so the new $service_inst replaces it rather than nesting | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # another run loop on top. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 116 | ▶ | if ($prev_service) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 8 | ▶ | croak "ipcm_service: previous service detected but no IPCM_SERVICE jump point on the stack" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | unless havejump 'IPCM_SERVICE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 8 | longjump IPCM_SERVICE => (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | die "This should not be reachable"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # Top-level service: enter the setjump loop. ipcm_worker and nested | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # ipcm_service() calls from inside the running service both unwind | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # back here via `longjump IPCM_SERVICE`, after which the loop re-runs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | # setjump() with $service_inst pointing at the replacement. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # If the running service consumes Role::Service with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # run_returns_to_caller() true, run() returning normally stores the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | # exit code in $returning_exit and lets _ipcm_service return it to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # its caller (used by the exec.stay_in_begin = 1 BEGIN-return path). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 108 | my $returning_exit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 108 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | my $jumped = setjump IPCM_SERVICE => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # Snapshot: $service_inst can be replaced before this block exits. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 120 | ▶ | my $using_service = $service_inst; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=12 SCAR=29.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 120 | my $is_code = ref($using_service) eq 'CODE'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 120 | ▶ | my $do_posix_exit = !$is_code && $using_service->use_posix_exit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
!$is_code && $using_service->use_posix_exit
MC/DC0%0/2
!$is_code && $using_service->use_posix_exit
!$is_code
$using_service->use_posix_exit
Truth table66%2/3
not(A) && B
A= !$is_codeB= $using_service->use_posix_exit
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 120 | my $exit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 120 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 120 | ▶ | if ($is_code) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 4 | $exit = $using_service->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 116 | ▶ | $exit = $using_service->run() // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$using_service->run // 0
MC/DC0%0/1
$using_service->run // 0
$using_service->run
Truth table50%1/2
A
A= $using_service->run
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 104 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 104 | ▶ | warn $@ unless $ok; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 104 | ▶ | if ( $ok | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$ok and not $is_code and $using_service->can("run_returns_to_caller") and $using_service->run_returns_to_caller
$ok and not $is_code and $using_service->can("run_returns_to_caller")
$ok and not $is_code
MC/DC0%0/4
$ok and not $is_code and $using_service->can("run_returns_to_caller") and $using_service->run_returns_to_caller
$ok
not $is_code
$using_service->can("run_returns_to_caller")
$using_service->run_returns_to_caller
Truth table20%1/5
A and not(B) and C and D
A= $okB= not $is_codeC= $using_service->can("run_returns_to_caller")D= $using_service->run_returns_to_caller
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | && !$is_code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | && $using_service->can('run_returns_to_caller') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | && $using_service->run_returns_to_caller) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | $returning_exit = \$exit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 104 | ▶ | my $code = $ok ? $exit : 255; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 104 | ▶ | if ($is_code) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | exit($code); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 104 | ▶ | $do_posix_exit ? POSIX::_exit($code) : exit($code); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 120 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | # setjump returns undef if the sub returned normally. Two | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | # cases reach here: (a) the run-returns-to-caller opt-in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | # stored an exit in $returning_exit -- break and let | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # _ipcm_service return it; (b) the (unexpected) scope-leak | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # path -- fall through to the warn + _exit(255) below. Any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # other value means longjump was called and we re-run setjump | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | # with the updated $service_inst. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 12 | ▶ | last unless $jumped; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | return $$returning_exit if $returning_exit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | # This should not be reachable.... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | eval { warn "Scope leak in service '$name' process $$" }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | POSIX::_exit(255); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 456 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||