| 1 | #Copyright 1998-2001, Randall Maas. All rights reserved. This program is free | ||||||||||||||||||||||||||||||||||||||||||
| 2 | #software; you can redistribute it and/or modify it under the same terms as | ||||||||||||||||||||||||||||||||||||||||||
| 3 | #PERL itself. | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | package CfgTie::TieRCServ_rec; | ||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use POSIX; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use CfgTie::filever; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Secure::File; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | my %ServScript; | |||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | CfgTie::TieRCService -- A module to manage Unix services | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | my %RC; | ||||||||||||||||||||||||||||||||||||||||||
| 20 | tie %RC, 'CfgTie::TieRCService'; | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | This is a straightforward interface to the control scripts in @file{/etc/rc?.d} | ||||||||||||||||||||||||||||||||||||||||||
| 25 | This package helps manage these system services. The tie hash is structured | ||||||||||||||||||||||||||||||||||||||||||
| 26 | like so: | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | { | ||||||||||||||||||||||||||||||||||||||||||
| 29 | $Service_Name => $Service_Ref, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | C<$Service_Ref> is a hash reference; the details will be covered in the next | ||||||||||||||||||||||||||||||||||||||||||
| 33 | section. C<(tied $Service_Ref)> can also be treated as an object to control | ||||||||||||||||||||||||||||||||||||||||||
| 34 | the service. That is covered in the I<Service Methods> section. | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | While fetching from the structure, and deleting services is supported (and | ||||||||||||||||||||||||||||||||||||||||||
| 37 | reflected to the system), directly storing new services is not. Currently | ||||||||||||||||||||||||||||||||||||||||||
| 38 | the method to do this is: | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | (tied %RC)->add('mynewservice'); | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | This will add the new service (to be managed as well as available) to the | ||||||||||||||||||||||||||||||||||||||||||
| 43 | run-levels. The start and kill scripts will be linked into each appropriate | ||||||||||||||||||||||||||||||||||||||||||
| 44 | run-level. The script should already exist (in the proper format) in | ||||||||||||||||||||||||||||||||||||||||||
| 45 | F</etc/rc.d/init.d> or equivalent. | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | =head2 The Service hash reference | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||||||||||||||||
| 50 | levels => [], | ||||||||||||||||||||||||||||||||||||||||||
| 51 | defaults => [], | ||||||||||||||||||||||||||||||||||||||||||
| 52 | category => [], | ||||||||||||||||||||||||||||||||||||||||||
| 53 | pid => $pid, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | path =>, | ||||||||||||||||||||||||||||||||||||||||||
| 55 | description =>, | ||||||||||||||||||||||||||||||||||||||||||
| 56 | start_priority=>, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | stop_priority =>, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | C<levels> refers to a list used to determine if the service is present for a | ||||||||||||||||||||||||||||||||||||||||||
| 61 | given run-level. | ||||||||||||||||||||||||||||||||||||||||||
| 62 | The scope of changes this list is I<system-wide>. It is persistent across | ||||||||||||||||||||||||||||||||||||||||||
| 63 | boots. | ||||||||||||||||||||||||||||||||||||||||||
| 64 | Example: | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | my $listref = (tied %{$RC{'atd'}})->levels(); | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | if ($L < scalar @{$listref} && $listref->[$L]) | ||||||||||||||||||||||||||||||||||||||||||
| 69 | {print "present at run level $L\n";} | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | =head2 Service Methods | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | C<new($service_name,$path)> I<path> is optional, and may refer either to the | ||||||||||||||||||||||||||||||||||||||||||
| 75 | folder containing the relevant control script, or may refer to the control | ||||||||||||||||||||||||||||||||||||||||||
| 76 | script itself. | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | C<start> will start the service (if not already started). | ||||||||||||||||||||||||||||||||||||||||||
| 79 | The scope of this action is I<system-wide>. | ||||||||||||||||||||||||||||||||||||||||||
| 80 | Example: C<$Obj->E<gt>C<start();> | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | C<stop> will stop the service (if running). | ||||||||||||||||||||||||||||||||||||||||||
| 84 | The scope of this action is I<system-wide>. | ||||||||||||||||||||||||||||||||||||||||||
| 85 | Example: C<$Obj->E<gt>C<stop();> | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | C<restart> will restart the service, effectively stopping it (if it is | ||||||||||||||||||||||||||||||||||||||||||
| 88 | running) and then starting it. | ||||||||||||||||||||||||||||||||||||||||||
| 89 | The scope of this action is I<system-wide>. | ||||||||||||||||||||||||||||||||||||||||||
| 90 | Example: C<$Obj->E<gt>C<restart();> | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | C<status> | ||||||||||||||||||||||||||||||||||||||||||
| 93 | The scope of this action is limited to a single I<session>. | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | C<reload> | ||||||||||||||||||||||||||||||||||||||||||
| 96 | The scope of this action is I<system-wide>. | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | =head1 Caveats | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | This can not create a new service start/kill script. At best this can only | ||||||||||||||||||||||||||||||||||||||||||
| 101 | modify an existing one, or link it into the init folders. | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | Requires C</sbin/chkconfig> to work. | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | =head1 Author | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | Randall Maas (L<randym@acm.org>) | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | package CfgTie::TieRCService; | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | # Still need a tiehash, ability to add it to a run level, change its order | ||||||||||||||||||||||||||||||||||||||||||
| 117 | # in the runlevel, remove it from the runlevel | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | #All of the service name to information is stored in | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | sub scan ($) | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
scan: called CC=6 SCAR=32.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | my $T= shift; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | my $F =CfgTie::filever::open("/sbin/chkconfig --list|"); | |||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | ▶ | return unless $F; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | while (<$F>) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | { | ||||||||||||||||||||||||||||||||||||||||||
| 128 | #We do this in the most flexible way we can think of... to allow for | ||||||||||||||||||||||||||||||||||||||||||
| 129 | # future changes to chkconfig | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | #Split the line up into its parts | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | my ($Serv,@R) = split /\s+/; | |||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | if (!$Serv) {next;} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | my @B=(0,0,0,0,0,0,0,0,0,0); | |||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | #Scan each part into an explicit run-level (used as an index) and the | ||||||||||||||||||||||||||||||||||||||||||
| 137 | #off/on which will be implicitly ignored | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | foreach my $I (@R) | |||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | {if ($I=~/^(\d+):on/i) {$B[$1]=1;}} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | #Store | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | tie %{$T->{$Serv}}, 'CfgTie::TieRCServ_rec', $Serv, \@B; | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $F->close; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | sub TIEHASH | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
TIEHASH: called CC=2 SCAR=7.4
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | my $Node={}; | |||||||||||||||||||||||||||||||||||||||||
| 151 | #Currently requires chkconfig to work | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | ▶ | if (!-e "/sbin/chkconfig") {return;} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | return bless $Node, $self; | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | sub DELETE | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DELETE: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | my $key=shift; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | if (!exists $Services{$key}) {return;} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | CfgTie::Cfgfile::system("/sbin/chkconfig --del $key"); | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | sub add | ||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my $key =shift; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | CfgTie::filever::system("/sbin/chkconfig --add $key"); | |||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | scan(\%Services); | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | sub EXISTS ($$) | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
EXISTS: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | my ($self,$key)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | return exists $Services{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | sub FETCH | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FETCH: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | my $key = shift; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | return $Services{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | sub trx {CfgTie::Cfgfile::trx(@_);} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
trx: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | sub table {CfgTie::Cfgfile::table(@_);} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
table: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | sub num2chk($) | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
num2chk: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | my @Ret; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | foreach my $I (@{$_[0]}) | |||||||||||||||||||||||||||||||||||||||||
| 191 | { | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | if ($I) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | {push @Ret, "<font face=\"Wingdings\">x</font>";} | |||||||||||||||||||||||||||||||||||||||||
| 194 | else | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | {push @Ret, "<font face=\"Wingdings\"> </font>";} | |||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | sub HTML ($) | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
HTML: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my $A=""; | |||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | foreach my $I (sort keys %Services) | |||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | {$A.= trx("<a href=\"runlevel/$I\">$I</a>",@{$Services{$I}->{levels}});} | |||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | table("Run levels", | |||||||||||||||||||||||||||||||||||||||||
| 206 | "<tr><th>Service</th><th>0</th><th>1</th><th>2</th><th>3</th><th>4</th>". | ||||||||||||||||||||||||||||||||||||||||||
| 207 | "<th>5</th><th>6</th><th>7</th><th>8</th><th>9</th></tr>\n$A",11); | ||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | package CfgTie::TieRCServ_rec; | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | sub proc_sig($$) | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
proc_sig: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | my $pid = proc_id($_[0]); | |||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | if (defined $pid) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | { | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | kill $_[1], $pid; | |||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | return -1; | |||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | sub scan_for_script($$) | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
scan_for_script: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my ($serv, $path) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | $FNum++; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | opendir FNum, $path; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | my @RCfiles = grep {/^$serv$/} (readdir(FNum)); | |||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | closedir FNum; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | if (!scalar @RCfiles) {return;} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | my ($R) = @RCfiles; | |||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | $R; | |||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | sub scan_rcscript($) | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
scan_rcscript: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | my $F = new Secure::File "<".$self->{'path'}; | |||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | while (<$F>) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | { | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | if (/^\s*\#\s*chkconfig\s*:\s*(\d+)/i) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | { | ||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | my @A=(0,0,0,0,0,0,0,0,0,0); | |||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | for (my $I=0; $I< length $1; $I++) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | {$A[substr($1,$I,1)]=1;} | |||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | $self->{defaults}=\@A; | |||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | elsif (/^\s*\#\s*description\s*:\s*([^\s].*)$/i) | ||||||||||||||||||||||||||||||||||||||||||
| 250 | { | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | my $A=$1; | |||||||||||||||||||||||||||||||||||||||||
| 252 | #read the continuation in as neccessary | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | while ($A=~/\\\s*$/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | { | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | $A=~s/\s*\\\s*$//; | |||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | my $B =<$F>; | |||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | if ($B=~/#\s*([^\s].*)$/i) {$A.=' '.$1;} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | $self->{description}=$A; | |||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | $F->close(); | |||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | sub TIEHASH | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
TIEHASH: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my ($self,$name,$levels)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | my $Node = | |||||||||||||||||||||||||||||||||||||||||
| 269 | { | ||||||||||||||||||||||||||||||||||||||||||
| 270 | levels=>$levels,'name'=>$name, | ||||||||||||||||||||||||||||||||||||||||||
| 271 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | return bless $Node, $self; | |||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | sub proc_id($) | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
proc_id: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | my $key = shift; | |||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | if (!defined $key || !-e "/var/run/$key.pid") {return undef;} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $key and -e "/var/run/$key.pid"
MC/DC0%0/2
defined $key and -e "/var/run/$key.pid"
defined $key
-e "/var/run/$key.pid"
Truth table0%0/3
A and B
A= defined $keyB= -e "/var/run/$key.pid"
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | #use the canonically process ID | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | my $F = new Secure::File "</var/run/$key.pid" or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | my ($I,$pid); | |||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | while (<$F>) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | { | ||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | if (/^(\d+)$/) {$pid=$1;} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | $F->close; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | return $pid; | |||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | sub _stat($) | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_stat: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | if (!defined $self) {return undef;} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | return stat("/var/run/".$self->{'name'}.".pid"); | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | sub EXISTS ($$) | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
EXISTS: not called CC=15 SCAR=54.8
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | my ($self,$key)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | my $lkey=lc($key); | |||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | if (exists $self->{$lkey}) {return 1;} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | if ($lkey eq 'pid') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | { | ||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | my $pid = proc_id($self->{'name'}); | |||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | if (defined $pid) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | { | ||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | $self->{pid} =$pid; | |||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||
| 314 | elsif ($lkey eq 'path') | ||||||||||||||||||||||||||||||||||||||||||
| 315 | { | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | my $Path="/etc/rc.d/init.d/"; | |||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | my $A; | |||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | if (-e $Path) {$A = scan_for_script($self->{'name'},$Path);} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | if (!defined $A) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | { | ||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | $Path="/etc/init.d/"; | |||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | if (-e $Path) {$A = scan_for_script($self->{'name'},$Path);} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | if (!defined $A) {return 0;} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | $self->{path}=$Path.'/'.$A; | |||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | ▶ | elsif ($lkey eq 'description' || $lkey eq 'defaults') | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$lkey eq "description" or $lkey eq "defaults"
MC/DC0%0/2
$lkey eq "description" or $lkey eq "defaults"
$lkey eq "description"
$lkey eq "defaults"
Truth table0%0/3
A or B
A= $lkey eq "description"B= $lkey eq "defaults"
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | { | ||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | if (!exists $self->{path}) {EXISTS($self,'path');} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | if (!exists $self->{path}) {return 0;} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | scan_rcscript($self); | |||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | return exists $self->{$lkey}; | |||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||
| 335 | elsif ($lkey eq 'stat') | ||||||||||||||||||||||||||||||||||||||||||
| 336 | { | ||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | my @A= _stat($self); | |||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | if (scalar @A) {$self->{'stat'}=[@A]; return 1;} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | sub FIRSTKEY | ||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FIRSTKEY: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | EXISTS($_[0],'pid'); | |||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | my $a = keys %{$_[0]}; | |||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | return scalar each %{$_[0]}; | |||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | sub NEXTKEY | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | {return scalar each %{$_[0]};} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
NEXTKEY: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | sub FETCH | ||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FETCH: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | my ($self,$key)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | my $lkey =lc($key); | |||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | ▶ | if (EXISTS($self,$lkey)) {return $self->{$lkey};} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | undef; | |||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | sub trx {CfgTie::Cfgfile::trx(@_);} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
trx: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | sub table {CfgTie::Cfgfile::table(@_);} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
table: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | sub HTML ($) | ||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
HTML: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 366 | #Levels it currently is in | ||||||||||||||||||||||||||||||||||||||||||
| 367 | #Description | ||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | EXISTS($self, 'description'); | |||||||||||||||||||||||||||||||||||||||||
| 369 | #Defaults | ||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | EXISTS($self, 'defaults'); | |||||||||||||||||||||||||||||||||||||||||
| 371 | #Name | ||||||||||||||||||||||||||||||||||||||||||
| 372 | #Process Id | ||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | EXISTS($self, 'pid'); | |||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | EXISTS($self, 'stat'); | |||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | #Set up the current run levels and their default settings: | ||||||||||||||||||||||||||||||||||||||||||
| 377 | my $A= table(undef, | ||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | trx('Levels:',@{$self->{levels}}). | |||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | trx('Defaults:', @{$self->{defaults}}), | |||||||||||||||||||||||||||||||||||||||||
| 380 | 10); | ||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | table("Run levels", | |||||||||||||||||||||||||||||||||||||||||
| 383 | "<tr><th>Service</th><th>0</th><th>1</th><th>2</th><th>3</th><th>4</th>". | ||||||||||||||||||||||||||||||||||||||||||
| 384 | "<th>5</th><th>6</th><th>7</th><th>8</th></tr>\n$A",10); | ||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | my $B=''; | |||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | if (exists $self->{'pid'}) {$B.= trx("Process Id:", $self->{'pid'});} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | if (exists $self->{'stat'}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | { | ||||||||||||||||||||||||||||||||||||||||||
| 390 | $B.= trx("Started on:", | ||||||||||||||||||||||||||||||||||||||||||
| 391 | POSIX::strftime("%a %b %e %H:%M:%S %Y", | ||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | localtime($self->{'stat'}->[9]))); | |||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | table($self->{'name'}, | ||||||||||||||||||||||||||||||||||||||||||
| 396 | trx("Name:", $self->{'name'}). | ||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | trx("Description:",$self->{'description'}). | |||||||||||||||||||||||||||||||||||||||||
| 398 | trx("Run Levels", $A). #Insert both tables there | ||||||||||||||||||||||||||||||||||||||||||
| 399 | $B | ||||||||||||||||||||||||||||||||||||||||||
| 400 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | sub STORE ($$) | ||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
STORE: not called CC=16 SCAR=56.1
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | my ($self,$key,$value)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | if (lc($key) ne 'level') {return;} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||
| 409 | #Identify the run levels that were enabled | ||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | my $A; | |||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | my $J=0; | |||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | foreach my $I (@{$value}) | |||||||||||||||||||||||||||||||||||||||||
| 413 | { | ||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | ▶ | if ($I == 0 || $self->{levels}->[$J] != 0 || $J >9) {$J++; next;} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$I == 0 or $self->{"levels"}[$J] != 0 or $J > 9
$I == 0 or $self->{"levels"}[$J] != 0
MC/DC0%0/3
$I == 0 or $self->{"levels"}[$J] != 0 or $J > 9
$I == 0
$self->{"levels"}[$J] != 0
$J > 9
Truth table0%0/4
A or B or C
A= $I == 0B= $self->{"levels"}[$J] != 0C= $J > 9
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | $A.=$J; | |||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | $J++; | |||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | #Identify the run levels that were disabled | ||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | my $B; | |||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | $J=0; | |||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | foreach my $I (@{$value}) | |||||||||||||||||||||||||||||||||||||||||
| 423 | { | ||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | ▶ | if ($I != 0 || $self->{levels}->[$J] == 0|| $J >9) {$J++; next;} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$I != 0 or $self->{"levels"}[$J] == 0 or $J > 9
$I != 0 or $self->{"levels"}[$J] == 0
MC/DC0%0/3
$I != 0 or $self->{"levels"}[$J] == 0 or $J > 9
$I != 0
$self->{"levels"}[$J] == 0
$J > 9
Truth table0%0/4
A or B or C
A= $I != 0B= $self->{"levels"}[$J] == 0C= $J > 9
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | $B.=$J; | |||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | $J++; | |||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | #Now commit theses.. First add it to some levels. | ||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | if (defined $A && $A && length $A) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $A and $A and length $A
defined $A and $A
MC/DC0%0/3
defined $A and $A and length $A
defined $A
$A
length $A
Truth table0%0/4
A and B and C
A= defined $AB= $AC= length $A
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | { | ||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | CfgTie::Cfgfile::system("/sbin/chkconfig --level $A ".$self->{'name'}. | |||||||||||||||||||||||||||||||||||||||||
| 433 | " on"); | ||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | #Next remove it from some levels. | ||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | ▶ | if (defined $B && $B && length $B) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $B and $B and length $B
defined $B and $B
MC/DC0%0/3
defined $B and $B and length $B
defined $B
$B
length $B
Truth table0%0/4
A and B and C
A= defined $BB= $BC= length $B
| |||||||||||||||||||||||||||||||||||||||||||
| 438 | { | ||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | CfgTie::Cfgfile::system("/sbin/chkconfig --level $B ".$self->{'name'}. | |||||||||||||||||||||||||||||||||||||||||
| 440 | " off"); | ||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | sub newt | ||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
newt: not called CC=14 SCAR=53.5
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | my ($self,$serv,$path) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | if (!defined $serv) {return bless $node, $self;} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | if (defined $path) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | { | ||||||||||||||||||||||||||||||||||||||||||
| 451 | #if the path is bad, just let it be there, but invalid.. | ||||||||||||||||||||||||||||||||||||||||||
| 452 | #Or if it points to a real file... | ||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | if (!-e $path || !-d $path) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-e $path and -d $path
MC/DC0%0/2
-e $path and -d $path
-e $path
-d $path
Truth table0%0/3
A and B
A= -e $pathB= -d $path
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | { | ||||||||||||||||||||||||||||||||||||||||||
| 455 | #The user specified a file; take the user at his word | ||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | $node->{Path}=$path; | |||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | return bless $node, $self; | |||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | ▶ | if (-e "$path/$serv") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 461 | { | ||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | $node->{Path}="$path/$serv"; | |||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | return bless $node, $self; | |||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | ▶ | if (-e "$path$serv") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 467 | { | ||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | $node->{Path}="$path$serv"; | |||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | return bless $node, $self; | |||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | my $R = scan_for_script $serv, $path; | |||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | ▶ | if (defined $R) {$node->{Path}=$R;} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | return bless $node, $self; | |||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | ▶ | if (!exists $ServScript{$serv}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 479 | { | ||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | ▶ | if (-e "/etc/rc.d/init.d/$serv") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | {$ServScript{$serv} = "/etc/rc.d/init.d/$serv";} | |||||||||||||||||||||||||||||||||||||||||
| 482 | else | ||||||||||||||||||||||||||||||||||||||||||
| 483 | { | ||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | my $RCBase; | |||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | ▶ | if (-d "/etc/rc2.d/") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | {$RCBase = "/etc/rc2.d/";} | |||||||||||||||||||||||||||||||||||||||||
| 487 | elsif (-d "/etc/rc.d/rc2.d") | ||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | {$RCBase = "/etc/rc.d/rc2.d/";} | |||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | else {return bless $node, $self;} | |||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | my $R = scan_for_script $serv, $RCBase; | |||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | ▶ | if ($R) {$ServScript{$serv} = $R;} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | ▶ | if (exists $ServScript{$serv}) {$node->{Path} = $ServScript{$serv};} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | return bless $node,$self; | |||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | BEGIN | ||||||||||||||||||||||||||||||||||||||||||
| 501 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=15.4
| |||||||||||||||||||||||||||||||||||||||||||
| 502 | #basically create the various verbs... | ||||||||||||||||||||||||||||||||||||||||||
| 503 | 1 | my $X="package CfgTie::TieRCServ_rec;\n"; | |||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||
| 505 | 1 | foreach my $I ('start','stop','restart', 'status') | |||||||||||||||||||||||||||||||||||||||||
| 506 | { | ||||||||||||||||||||||||||||||||||||||||||
| 507 | 4 | $X.= "sub $I(\$)\n{\n". | |||||||||||||||||||||||||||||||||||||||||
| 508 | " my \$self = shift;\n". | ||||||||||||||||||||||||||||||||||||||||||
| 509 | " delete \$self->{pid};\n". | ||||||||||||||||||||||||||||||||||||||||||
| 510 | " delete \$self->{'stat'};\n". | ||||||||||||||||||||||||||||||||||||||||||
| 511 | " if (exists \$self->{path})\n". | ||||||||||||||||||||||||||||||||||||||||||
| 512 | " {return system(\$self->{path}.\" $I\");}\n". | ||||||||||||||||||||||||||||||||||||||||||
| 513 | "}\n\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | ▶ | eval $X; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
restart: not called CC=2 SCAR=17.2
Subroutine
start: not called CC=2 SCAR=17.2
Subroutine
status: not called CC=2 SCAR=17.2
Subroutine
stop: not called CC=2 SCAR=17.2
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||
| 518 | sub reload($) | ||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reload: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | delete $self->{pid}; | |||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | delete $self->{status}; | |||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | ▶ | if (-x "/usr/sbin/".$self->{'name'}.".reload") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 524 | { | ||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | return system("/usr/sbin/".$self->{'name'}.".reload"); | |||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||
| 527 | else | ||||||||||||||||||||||||||||||||||||||||||
| 528 | { | ||||||||||||||||||||||||||||||||||||||||||
| 529 | #Get its pid | ||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | ▶ | if (proc_sig($self->{'name'}, 'HUP') == -1) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 531 | { | ||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | restart $self; | |||||||||||||||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||
| 537 | package CfgTie::TieRCService; | ||||||||||||||||||||||||||||||||||||||||||
| 538 | 1 | ▶ | use CfgTie::filever; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 539 | 1 | ▶ | use Secure::File; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 540 | 1 | my %Services; | |||||||||||||||||||||||||||||||||||||||||
| 541 | 1 | scan (\%Services); | |||||||||||||||||||||||||||||||||||||||||
| 542 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||