script/lockerd

filter: Statementstmt 50.0% 27 / 54 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 64.2% 9 / 14 Podpod n/a totaltotal 42.8% 36 / 84 SCAR 10.7
CC
2
Cov
39%
sig_HUP
6.0
__ANON__
2.0
__ANON__
2.0
CRAP 2.9
« script/pidstatd ↑ Summary
1 #!/usr/bin/perl -w
2 # See copyright, etc in below POD section.
3 ######################################################################
4  
5 2 require 5.004;
6 2 ▶use lib './blib/lib'; # testing
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use IPC::Locker::Server;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶BEGIN { $ENV{PATH} = '/usr/ucb:/bin' } # Secure path
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 ######################################################################
15 # configuration
16  
17 ######################################################################
18 # globals
19  
20 2 ▶use vars qw($Pid);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 ######################################################################
23 # main
24  
25 2 my $Debug = 0;
26 2 my %server_params = ();
27 2 my $opt_fork = 1;
28  
29 2 ▶if (!GetOptions (
Branch: 1 branch
BranchTrueFalseTotal
unless (&GetOptions("help", \&main::usage, "debug", \&main::debug, "version", \&main::version, "host=s", sub { $server_params{"host"} = $_[1]; } , "port=i", sub { $server_params{"port"} = $_[1]; } , "path=s", sub { $server_params{"port"} = $_[1]; $server_params{"family"} = "UNIX"; } , "fork!", \$opt_fork)) 0 0 0
30 "help" => \&usage,
31 "debug" => \&debug,
32 "version" => \&version,
33 0 ▶ "host=s" => sub {$server_params{host} = $_[1];},
Subroutine __ANON__: not called CC=1 SCAR=6.9
34 0 ▶ "port=i" => sub {$server_params{port} = $_[1];},
Subroutine __ANON__: not called CC=1 SCAR=6.9
35 0 ▶ "path=s" => sub {$server_params{port} = $_[1];
Subroutine __ANON__: not called CC=1 SCAR=6.9
36 0 $server_params{family}='UNIX';},
37 "fork!" => \$opt_fork,
38 )) {
39 0 die "%Error: Bad usage, try 'lockerd --help'\n";
40 }
41  
42 # Must be after we've done --help
43 0 $0 = 'lockerd'; # So ps and pidof can find this daemon
44  
45 # Loop in case something kills us
46 0 $SIG{HUP} = \&sig_HUP;
47 0 $SIG{CHLD} = \&sig_HUP;
48 0 while (1) {
49 0 ▶ print "Starting server\n" if $Debug;
Branch: 1 branch
BranchTrueFalseTotal
if $Debug 0 0 0
50 0 ▶ $Pid = fork if $opt_fork;
Branch: 1 branch
BranchTrueFalseTotal
if $opt_fork 0 0 0
51 0 ▶ unless ($Pid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($main::Pid) 0 0 0
52 0 IPC::Locker::Server->new(%server_params)->start_server ();
53 0 exit(0);
54 }
55 0 ▶ waitpid($Pid,0) if $Pid;
Branch: 1 branch
BranchTrueFalseTotal
if $main::Pid 0 0 0
56 0 ▶ warn "%Warning: Server aborted, status=$?\n" if $Debug;
Branch: 1 branch
BranchTrueFalseTotal
if $Debug 0 0 0
57 0 sleep(1);
58 0 ▶ kill 9, $Pid if $Pid;
Branch: 1 branch
BranchTrueFalseTotal
if $main::Pid 0 0 0
59 0 $Pid = 0;
60 0 sleep(1);
61 }
62  
63 0 exit (0);
64  
65 sub sig_HUP {
66 0 ▶ kill 9, $Pid if $Pid;
Subroutine sig_HUP: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if $main::Pid 0 0 0
67 0 $Pid = 0;
68 }
69  
70 ######################################################################
71  
72 sub usage {
73 1 ▶ pod2usage(-verbose=>2, -exitval=>2, -output=>\*STDOUT, -noperldoc=>1);
Subroutine usage: called CC=1 SCAR=1.2
74 0 exit(1);
75 }
76  
77 sub version {
78 1 ▶ print "Version: $IPC::Locker::VERSION\n";
Subroutine version: called CC=1 SCAR=0.0
79 1 exit (1);
80 }
81  
82 sub debug {
83 0 ▶ $Debug = 1;
Subroutine debug: not called CC=1 SCAR=6.9
84 0 $IPC::Locker::Server::Debug = 1;
85 0 $IPC::PidStat::Debug = 1;
86 }
87  
88 ######################################################################
89 __END__
« script/pidstatd ↑ Summary