bin/cfk-share-mem-proxy.pl

filter: Statementstmt 88.1% 52 / 59 Branchbran 40.0% 12 / 30 Conditioncond 14.2% 1 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 83.3% 10 / 12 Podpod n/a totaltotal 66.9% 75 / 112 CC 7 SCAR 19.7
CC
7
Cov
68%
__ANON__
20.0
__ANON__
12.0
__ANON__
2.0
CRAP 7.2
« lib/ControlFreak/Socket.pm ↑ Summary blib/lib/ControlFreak/Proxy/Process.pm »
1 #!/usr/bin/env perl
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 5 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use AnyEvent();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 ▶use ControlFreak::Proxy::Process;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 5 my $proxy;
14  
15 my %options;
16 GetOptions(
17 "p|preload=s" => \$options{preload},
18  
19 'h|help' => \$options{help},
20 'm|man' => \$options{man},
21 5 );
22  
23 5 ▶pod2usage(1) if $options{help};
Branch: 1 branch
BranchTrueFalseTotal
if $options{"help"} 0 5 5
24 5 ▶pod2usage(-verbose => 2) if $options{man};
Branch: 1 branch
BranchTrueFalseTotal
if $options{"man"} 0 5 5
25  
26 5 ▶croak "Please, specify a preload option" unless $options{preload};
Branch: 1 branch
BranchTrueFalseTotal
unless $options{"preload"} 0 5 5
27 5 my $svc_coderef;
28 5 my $ret = require $options{preload};
29 5 ▶if ($ret && ref $ret eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret and ref $ret eq "CODE") 0 5 5
Condition33%1/3
$ret and ref $ret eq "CODE"
!ll&&!rl&&r
050
MC/DC0%0/2
$ret and ref $ret eq "CODE"
$ret ref $ret eq "CODE"
Truth table33%1/3
A and B
A= $retB= ref $ret eq "CODE"
ABresult
0X0
100
111
30 0 $svc_coderef = $ret;
31 }
32 5 ▶croak "Error preloading: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 5 5
33  
34 5 ▶my $cfd = $ENV{_CFK_COMMAND_FD} or die "no command fd";
Branch: 1 branch
BranchTrueFalseTotal
my $cfd = $ENV{"_CFK_COMMAND_FD"} or die "no command fd" 5 0 5
35 5 ▶my $sfd = $ENV{_CFK_STATUS_FD} or die "no status fd";
Branch: 1 branch
BranchTrueFalseTotal
my $sfd = $ENV{"_CFK_STATUS_FD"} or die "no status fd" 5 0 5
36 5 ▶my $lfd = $ENV{_CFK_LOG_FD} or die "no log fd";
Branch: 1 branch
BranchTrueFalseTotal
my $lfd = $ENV{"_CFK_LOG_FD"} or die "no log fd" 5 0 5
37  
38 5 ▶open my $cfh, "<&=$cfd"
Branch: 1 branch
BranchTrueFalseTotal
open my $cfh, "<&=$cfd" or die "Cannot open Command filehandle, is descriptor correct?" 5 0 5
39 or die "Cannot open Command filehandle, is descriptor correct?";
40  
41 5 ▶open my $sfh, ">>&=$sfd"
Branch: 1 branch
BranchTrueFalseTotal
open my $sfh, ">>&=$sfd" or die "Cannot open Status filehandle, is descriptor correct?" 5 0 5
42 or die "Cannot open Status filehandle, is descriptor correct?";
43  
44 5 ▶open my $lfh, ">>&=$lfd"
Branch: 1 branch
BranchTrueFalseTotal
open my $lfh, ">>&=$lfd" or die "Cannot open Status filehandle, is descriptor correct?" 5 0 5
45 or die "Cannot open Status filehandle, is descriptor correct?";
46  
47 5 trap_sigs();
48  
49 5 my $sockets = ControlFreak::Proxy::Process->sockets_from_env;
50 ## FIXME: let Proxy::Process open the fd?
51 5 $proxy = ControlFreak::Proxy::Process->new(
52 command_fh => $cfh,
53 status_fh => $sfh,
54 log_fh => $lfh,
55 sockets => $sockets,
56 svc_coderef => $svc_coderef,
57 );
58  
59 5 $proxy->log('out', "$0 proxy started");
60 5 $proxy->run;
61  
62 5 ▶sub trap_sigs {
Subroutine trap_sigs: called CC=1 SCAR=2.5
63 2 ▶ $SIG{HUP} = $SIG{INT} = $SIG{TERM} = sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
64 2 my $sig = shift;
65 2 ▶ if ($proxy) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proxy) 2 0 2
66 2 $proxy->log("err", "Got signal $sig");
67 2 $proxy->shutdown;
68 }
69 2 exit 0;
70 5 };
71 0 ▶ $SIG{__WARN__} = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
72 0 ▶ my $warn = shift || "";
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
73 0 ▶ $proxy->log("err", "warn $warn") if $proxy;
Branch: 1 branch
BranchTrueFalseTotal
if $proxy 0 0 0
74 5 };
75 0 ▶ $SIG{__DIE__} = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
76 0 ▶ my $reason = shift || "";
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
77 0 ▶ return if $^S;
Branch: 1 branch
BranchTrueFalseTotal
if $^S 0 0 0
78 0 ▶ $proxy->log("err", "die $reason") if $proxy;
Branch: 1 branch
BranchTrueFalseTotal
if $proxy 0 0 0
79 0 exit -1;
80 5 };
81 }
82  
83 __END__
« lib/ControlFreak/Socket.pm ↑ Summary blib/lib/ControlFreak/Proxy/Process.pm »