| 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
| |||||||||||||||||||||||||||||
| 24 | 5 | ▶ | pod2usage(-verbose => 2) if $options{man}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 5 | ▶ | croak "Please, specify a preload option" unless $options{preload}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 5 | my $svc_coderef; | |||||||||||||||||||||||||||
| 28 | 5 | my $ret = require $options{preload}; | |||||||||||||||||||||||||||
| 29 | 5 | ▶ | if ($ret && ref $ret eq 'CODE') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ret and ref $ret eq "CODE"
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"
| |||||||||||||||||||||||||||||
| 30 | 0 | $svc_coderef = $ret; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | 5 | ▶ | croak "Error preloading: $@" if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 5 | ▶ | my $cfd = $ENV{_CFK_COMMAND_FD} or die "no command fd"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 5 | ▶ | my $sfd = $ENV{_CFK_STATUS_FD} or die "no status fd"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 5 | ▶ | my $lfd = $ENV{_CFK_LOG_FD} or die "no log fd"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 5 | ▶ | open my $cfh, "<&=$cfd" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | or die "Cannot open Command filehandle, is descriptor correct?"; | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 5 | ▶ | open my $sfh, ">>&=$sfd" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | or die "Cannot open Status filehandle, is descriptor correct?"; | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 5 | ▶ | open my $lfh, ">>&=$lfd" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | $proxy->log("err", "warn $warn") if $proxy; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | return if $^S; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | $proxy->log("err", "die $reason") if $proxy; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | exit -1; | |||||||||||||||||||||||||||
| 80 | 5 | }; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | __END__ | ||||||||||||||||||||||||||||