blib/lib/Langertha/Holmgang/Sim/Linux/Logrotate.pm

filter: Statementstmt 84.5% 278 / 329 Branchbran 73.6% 140 / 190 Conditioncond 56.2% 85 / 151 MC/DCmcdc 25.6% 20 / 78 Subroutinesub 93.3% 14 / 15 Podpod 100% 1 / 1 totaltotal 70.4% 538 / 764 CC 162 SCAR 40.7
CC
162
Cov
75%
_read_file
90.3
run
78.4
_rotate_one
65.5
CRAP 58.6
« blib/lib/Langertha/Holmgang/Sim/Linux/Monitoring.pm ↑ Summary blib/lib/Langertha/Holmgang/World.pm »
1 package Langertha::Holmgang::Sim::Linux::Logrotate;
2 # ABSTRACT: logrotate 3.21 (Debian 12) for the Linux simulator — reads the configuration, checks (-d), rotates (-f)
3  
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 our $VERSION = '0.001';
9  
10  
11 3 my $L = 'Langertha::Holmgang::Sim::Linux';
12 3 ▶sub _l { my $n = shift; no strict 'refs'; return &{"${L}::$n"}(@_) }
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _l: called CC=1 SCAR=0.0
13  
14 3 my %FLAG = map { $_ => 1 } qw( compress nocompress delaycompress nodelaycompress copytruncate nocopytruncate copy nocopy
15 missingok nomissingok notifempty ifempty sharedscripts nosharedscripts dateext nodateext nocreate nomail maillast mailfirst
16 shred noshred renamecopy createolddir nocreateolddir noolddir dateyesterday datehourago nosharedscripts );
17 3 my %ARG = map { $_ => 1 } qw( rotate size maxsize minsize maxage olddir su compresscmd uncompresscmd compressext compressoptions
18 dateformat extension start tabooext mail shredcycles addextension );
19 3 my %PERIOD = map { $_ => 1 } qw( hourly daily weekly monthly yearly );
20 3 my %SCRIPT = map { $_ => 1 } qw( postrotate prerotate firstaction lastaction preremove );
21 3 my @TABOO = qw( .rpmsave .rpmorig ~ .disabled .dpkg-old .dpkg-dist .dpkg-new .cfsaved .ucf-old .ucf-dist .ucf-new .rpmnew .swp .cfsaved .rhn-cfg-tmp-* );
22  
23  
24 16 ▶sub run {
Subroutine run: called CC=32 SCAR=43.6
Pod documented
25 16 my ( $dev, $av, $ctx ) = @_;
26 16 my ( $debug, $force, $verbose, @conf );
27 16 my @a = @$av;
28 16 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 33 15 48
29 33 my $x = shift @a;
30 33 ▶ if ( $x eq '-d' || $x eq '--debug' ) { $debug = 1 }
Branch: 9 branches
BranchTrueFalseTotal
if ($x eq '-d' or $x eq '--debug') { } 8 25 33
elsif ($x eq '-f' or $x eq '--force') { } 7 18 25
elsif ($x eq '-v' or $x eq '--verbose') { } 1 17 18
elsif ($x =~ /\A-[dfv]{2,}\z/) { } 0 17 17
elsif ($x eq '-s' or $x eq '--state' or $x eq '-l' or $x eq '--log' or $x eq '-m' or $x eq '--mail') { } 0 17 17
elsif ($x =~ /\A--(?:state|log|mail)=/) { } 0 17 17
elsif ($x eq '--version' or $x eq '-V') { } 1 16 17
elsif ($x eq '--help' or $x eq '-?' or $x eq '--usage') { } 0 16 16
elsif ($x =~ /\A-/) { } 0 16 16
Condition66%2/3
$x eq "-d" or $x eq "--debug"
l!l&&r!l&&!r
8025
MC/DC50%1/2
$x eq "-d" or $x eq "--debug"
$x eq "-d" $x eq "--debug"
Truth table66%2/3
A or B
A= $x eq "-d"B= $x eq "--debug"
ABresult
1X1
011
000
31 7 ▶ elsif ( $x eq '-f' || $x eq '--force' ) { $force = 1 }
Condition66%2/3
$x eq "-f" or $x eq "--force"
l!l&&r!l&&!r
7018
MC/DC50%1/2
$x eq "-f" or $x eq "--force"
$x eq "-f" $x eq "--force"
Truth table66%2/3
A or B
A= $x eq "-f"B= $x eq "--force"
ABresult
1X1
011
000
32 1 ▶ elsif ( $x eq '-v' || $x eq '--verbose' ) { $verbose = 1 }
Condition66%2/3
$x eq "-v" or $x eq "--verbose"
l!l&&r!l&&!r
1017
MC/DC50%1/2
$x eq "-v" or $x eq "--verbose"
$x eq "-v" $x eq "--verbose"
Truth table66%2/3
A or B
A= $x eq "-v"B= $x eq "--verbose"
ABresult
1X1
011
000
33 0 ▶ elsif ( $x =~ /\A-[dfv]{2,}\z/ ) { $debug = 1 if $x =~ /d/; $force = 1 if $x =~ /f/; $verbose = 1 if $x =~ /v/ }
Branch: 3 branches
BranchTrueFalseTotal
if $x =~ /d/ 0 0 0
if $x =~ /f/ 0 0 0
if $x =~ /v/ 0 0 0
34 0 ▶ elsif ( $x eq '-s' || $x eq '--state' || $x eq '-l' || $x eq '--log' || $x eq '-m' || $x eq '--mail' ) { shift @a }
Condition33%5/15
$x eq "-s" or $x eq "--state" or $x eq "-l" or $x eq "--log" or $x eq "-m" or $x eq "--mail"
l!l&&r!l&&!r
0017
$x eq "-s" or $x eq "--state" or $x eq "-l" or $x eq "--log" or $x eq "-m"
l!l&&r!l&&!r
0017
$x eq "-s" or $x eq "--state" or $x eq "-l" or $x eq "--log"
l!l&&r!l&&!r
0017
$x eq "-s" or $x eq "--state" or $x eq "-l"
l!l&&r!l&&!r
0017
$x eq "-s" or $x eq "--state"
l!l&&r!l&&!r
0017
MC/DC0%0/6
$x eq "-s" or $x eq "--state" or $x eq "-l" or $x eq "--log" or $x eq "-m" or $x eq "--mail"
$x eq "-s" $x eq "--state" $x eq "-l" $x eq "--log" $x eq "-m" $x eq "--mail"
Truth table14%1/7
A or B or C or D or E or F
A= $x eq "-s"B= $x eq "--state"C= $x eq "-l"D= $x eq "--log"E= $x eq "-m"F= $x eq "--mail"
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
35 elsif ( $x =~ /\A--(?:state|log|mail)=/ ) { }
36 1 ▶ elsif ( $x eq '--version' || $x eq '-V' ) { return ( _version(), 1 ) }
Condition66%2/3
$x eq "--version" or $x eq "-V"
l!l&&r!l&&!r
1016
MC/DC50%1/2
$x eq "--version" or $x eq "-V"
$x eq "--version" $x eq "-V"
Truth table66%2/3
A or B
A= $x eq "--version"B= $x eq "-V"
ABresult
1X1
011
000
37 0 ▶ elsif ( $x eq '--help' || $x eq '-?' || $x eq '--usage' ) { return ( _usage(), 1 ) }
Condition33%2/6
$x eq "--help" or $x eq "-?" or $x eq "--usage"
l!l&&r!l&&!r
0016
$x eq "--help" or $x eq "-?"
l!l&&r!l&&!r
0016
MC/DC0%0/3
$x eq "--help" or $x eq "-?" or $x eq "--usage"
$x eq "--help" $x eq "-?" $x eq "--usage"
Truth table25%1/4
A or B or C
A= $x eq "--help"B= $x eq "-?"C= $x eq "--usage"
ABCresult
1XX1
01X1
0011
0000
38 0 elsif ( $x =~ /\A-/ ) { return ( "logrotate: bad argument $x: unknown option\n" . _usage(), 1 ) }
39 16 else { push @conf, $x }
40 }
41 15 ▶ return ( "logrotate 3.21.0 - Copyright (C) 1995-2001 Red Hat, Inc.\nThis may be freely redistributed under the terms of the GNU General Public License\n\n"
Branch: 1 branch
BranchTrueFalseTotal
unless @conf 0 15 15
42 . _usage(), 0 ) unless @conf;
43 15 my ( @out, @logs, %seen );
44 15 my $err = 0;
45 15 ▶ push @out, 'warning: logrotate in debug mode does nothing except printing debug messages! Consider using verbose mode (-v) instead if this is not what you want.', ''
Branch: 1 branch
BranchTrueFalseTotal
if $debug 8 7 15
46 if $debug;
47 15 for my $c (@conf) {
48 16 $err += _read_config( $dev, $c, {}, \@logs, \@out, \%seen, 0 );
49 }
50 15 push @out, 'Reading state from file: /var/lib/logrotate/status', 'Allocating hash table for state file, size 64 entries';
51 15 push @out, '', 'Handling ' . scalar(@logs) . ' logs';
52 15 for my $b (@logs) {
53 15 $err += _rotate_block( $dev, $b, $ctx, \@out, debug => $debug, force => $force );
54 }
55 15 ▶ my $show = $debug || $verbose;
Condition100%3/3
$debug || $verbose
l!l&&r!l&&!r
816
MC/DC100%2/2
$debug || $verbose
$debug $verbose
Truth table100%3/3
A || B
A= $debugB= $verbose
ABresult
1X1
011
000
56 15 ▶ my @shown = $show ? @out : grep {/\Aerror:/} @out;
Branch: 1 branch
BranchTrueFalseTotal
$show ? : 9 6 15
57 15 ▶ return ( join( "\n", @shown ), $err ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$err ? : 6 9 15
58 }
59  
60 1 ▶sub _version {
Subroutine _version: called CC=1 SCAR=0.0
61 1 return join "\n", 'logrotate 3.21.0', '', ' Default mail command: /usr/bin/mail', ' Default compress command: /bin/gzip',
62 ' Default uncompress command: /bin/gunzip', ' Default compress extension: .gz', ' Default state file path: /var/lib/logrotate/status',
63 ' ACL support: yes', ' SELinux support: yes';
64 }
65  
66 0 ▶sub _usage {
Subroutine _usage: not called CC=1 SCAR=6.9
67 0 return join "\n", 'Usage: logrotate [-dfv?] [-d|--debug] [-f|--force] [-m|--mail=command] [-s|--state=statefile]',
68 ' [--skip-state-lock] [-v|--verbose] [-l|--log=logfile] [--version] [-?|--help] [--usage]',
69 ' [OPTION...] <configfile>';
70 }
71  
72 # Liest eine Konfigurationsdatei (oder ein Verzeichnis); haengt Bloecke an @$logs.
73 # Rueckgabe: Zahl der Fehler.
74 17 ▶sub _read_config {
Subroutine _read_config: called CC=11 SCAR=24.6
75 17 my ( $dev, $path, $g, $logs, $out, $seen, $depth ) = @_;
76 17 my $err = 0;
77 17 ▶ if ( _l( '_is_dir', $dev, $path ) && !_l( '_file_entry', $dev, $path ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_l("_is_dir", $dev, $path) and not _l("_file_entry", $dev, $path)) 1 16 17
Condition66%2/3
_l("_is_dir", $dev, $path) and not _l("_file_entry", $dev, $path)
!ll&&!rl&&r
1601
MC/DC50%1/2
_l("_is_dir", $dev, $path) and not _l("_file_entry", $dev, $path)
_l("_is_dir", $dev, $path) not _l("_file_entry", $dev, $path)
Truth table66%2/3
A and not(B)
A= _l("_is_dir", $dev, $path)B= not _l("_file_entry", $dev, $path)
ABresult
0X0
100
111
78 1 ▶ push @$out, "including $path" if $depth;
Branch: 1 branch
BranchTrueFalseTotal
if $depth 1 0 1
79 1 my $names = _l( '_ls_names', $dev, $path );
80 1 for my $n ( sort keys %$names ) {
81 4 ▶ my ($t) = grep { my $x = $_; $x =~ s/\*\z//; $x =~ /\A\./ ? substr( $n, -length $x ) eq $x : $n eq $x } @TABOO;
Branch: 1 branch
BranchTrueFalseTotal
$x =~ /\A\./ ? : 56 4 60
82 4 ▶ if ( $t || $n =~ /\.rhn-cfg-tmp-/ ) { push @$out, "Ignoring $n, because of " . ( $t // '.rhn-cfg-tmp-*' ) . ' ending'; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($t or $n =~ /\.rhn-cfg-tmp-/) 1 3 4
Condition60%3/5
$t or $n =~ /\.rhn-cfg-tmp-/
l!l&&r!l&&!r
103
$t // ".rhn-cfg-tmp-*"
l!l
10
MC/DC50%1/2
$t or $n =~ /\.rhn-cfg-tmp-/
$t $n =~ /\.rhn-cfg-tmp-/
MC/DC0%0/1
$t // ".rhn-cfg-tmp-*"
$t
Truth table66%2/3
A or B
A= $tB= $n =~ /\.rhn-cfg-tmp-/
ABresult
1X1
011
000
Truth table50%1/2
A
A= $t
Aresult
11
00
83 3 ▶ next if _l( '_is_dir', $dev, "$path/$n" ) && !_l( '_file_entry', $dev, "$path/$n" );
Branch: 1 branch
BranchTrueFalseTotal
if _l("_is_dir", $dev, "$path/$n") and not _l("_file_entry", $dev, "$path/$n") 0 3 3
Condition33%1/3
_l("_is_dir", $dev, "$path/$n") and not _l("_file_entry", $dev, "$path/$n")
!ll&&!rl&&r
300
MC/DC0%0/2
_l("_is_dir", $dev, "$path/$n") and not _l("_file_entry", $dev, "$path/$n")
_l("_is_dir", $dev, "$path/$n") not _l("_file_entry", $dev, "$path/$n")
Truth table33%1/3
A and not(B)
A= _l("_is_dir", $dev, "$path/$n")B= not _l("_file_entry", $dev, "$path/$n")
ABresult
0X0
100
111
84 3 $err += _read_file( $dev, "$path/$n", $n, $g, $logs, $out, $seen, $depth );
85 }
86 1 return $err;
87 }
88 16 return _read_file( $dev, $path, $path, $g, $logs, $out, $seen, $depth );
89 }
90  
91 19 ▶sub _read_file {
Subroutine _read_file: called CC=43 SCAR=45.0
92 19 my ( $dev, $path, $shown, $g, $logs, $out, $seen, $depth ) = @_;
93 19 my $e = _l( '_file_entry', $dev, $path );
94 19 my $text = _l( '_file_text', $dev, $path );
95 0 ▶ if ( !defined $text ) { push @$out, "error: cannot stat $path: No such file or directory"; return 1 }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $text) 0 19 19
96 19 push @$out, "reading config file $shown";
97 19 ▶ my $mode = oct( $e->{mode} // '0644' );
Condition100%2/2
$$e{"mode"} // "0644"
l!l
118
MC/DC100%1/1
$$e{"mode"} // "0644"
$$e{"mode"}
Truth table100%2/2
A
A= $$e{"mode"}
Aresult
11
00
98 19 ▶ if ( $mode & 022 ) { push @$out, "error: Ignoring $shown because of bad file mode - must be 0644 or 0444."; return 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($mode & 18) 1 18 19
99 0 ▶ if ( ( $e->{owner} // 'root' ) ne 'root' ) { push @$out, "error: Ignoring $shown because the file owner is wrong (should be root or user with uid 0)."; return 1 }
Branch: 1 branch
BranchTrueFalseTotal
if (($$e{"owner"} // "root") ne "root") 0 18 18
Condition50%1/2
$$e{"owner"} // "root"
l!l
018
MC/DC0%0/1
$$e{"owner"} // "root"
$$e{"owner"}
Truth table50%1/2
A
A= $$e{"owner"}
Aresult
11
00
100 18 my $err = 0;
101 18 my ( $block, $script, $pending );
102 18 my $n = 0;
103 18 for my $raw ( split /\n/, $text ) {
104 161 $n++;
105 161 ▶ if ($script) {
Branch: 1 branch
BranchTrueFalseTotal
if ($script) 20 141 161
106 20 ▶ if ( $raw =~ /\A\s*endscript\s*\z/ ) { $script = undef; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($raw =~ /\A\s*endscript\s*\z/) 10 10 20
107 10 push @{ $block->{scripts}{$script} }, $raw;
108 10 next;
109 }
110 141 ( my $l = $raw ) =~ s/\A\s+|\s+\z//g;
111 141 ▶ next if $l eq '' || $l =~ /\A#/;
Branch: 1 branch
BranchTrueFalseTotal
if $l eq "" or $l =~ /\A#/ 0 141 141
Condition33%1/3
$l eq "" or $l =~ /\A#/
l!l&&r!l&&!r
00141
MC/DC0%0/2
$l eq "" or $l =~ /\A#/
$l eq "" $l =~ /\A#/
Truth table33%1/3
A or B
A= $l eq ""B= $l =~ /\A#/
ABresult
1X1
011
000
112 141 ▶ my $cur = $block ? $block->{opt} : $g;
Branch: 1 branch
BranchTrueFalseTotal
$block ? : 120 21 141
113 141 ▶ if ($pending) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pending) 0 141 141
114 0 ▶ if ( $l eq '{' ) { $l = "$pending {"; $pending = undef }
Branch: 1 branch
BranchTrueFalseTotal
if ($l eq '{') { } 0 0 0
115 0 else { push @$out, "error: $shown:" . ( $n - 1 ) . " missing '{' after log files definition"; $err++; $pending = undef }
116 }
117 141 ▶ if ( !$block && ( $l =~ m{\A["/]} || $l =~ /\{\s*\z/ && $l !~ /\A\w+\s*\{/ ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $block and $l =~ m[\A["/]] || $l =~ /\{\s*\z/ && !($l =~ /\A\w+\s*\{/)) 17 124 141
Condition66%6/9
not $block and $l =~ m[\A["/]] || $l =~ /\{\s*\z/ && !($l =~ /\A\w+\s*\{/)
!ll&&!rl&&r
120417
$l =~ m[\A["/]] or $l =~ /\{\s*\z/ and not $l =~ /\A\w+\s*\{/
l!l&&r!l&&!r
1704
$l =~ /\{\s*\z/ and not $l =~ /\A\w+\s*\{/
!ll&&!rl&&r
400
MC/DC50%2/4
not $block and $l =~ m[\A["/]] || $l =~ /\{\s*\z/ && !($l =~ /\A\w+\s*\{/)
not $block $l =~ m[\A["/]] $l =~ /\{\s*\z/ not $l =~ /\A\w+\s*\{/
Truth table60%3/5
not(A) and B or C and not(D)
A= not $blockB= $l =~ m[\A["/]]C= $l =~ /\{\s*\z/D= not $l =~ /\A\w+\s*\{/
ABCDresult
0XXX0
100X0
10100
11XX1
10111
118 0 ▶ if ( $l !~ /\{\s*\z/ ) { $pending = $l; next }
Branch: 1 branch
BranchTrueFalseTotal
unless ($l =~ /\{\s*\z/) 0 17 17
119 17 ( my $pats = $l ) =~ s/\s*\{\s*\z//;
120 17 my @p = map { s/\A"|"\z//gr } split /\s+/, $pats;
121 17 $block = { patterns => \@p, opt => { %$g }, scripts => {}, file => $shown, line => $n };
122 # wie logrotate: dieselbe Datei (nach dem Aufloesen der Muster) nur in einem Block
123 17 my %skip;
124 17 for my $f ( map { _expand( $dev, $_ ) } @p ) {
125 17 ▶ if ( $seen->{$f} ) { push @$out, "error: $shown:$n duplicate log entry for $f"; $err++; $skip{$f} = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($$seen{$f}) 1 16 17
126 17 $seen->{$f} = 1;
127 }
128 17 $block->{skip} = \%skip;
129 17 next;
130 }
131 124 ▶ if ( $l eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l eq "}") 15 109 124
132 0 ▶ if ( !$block ) { push @$out, "error: $shown:$n unexpected }"; $err++; next }
Branch: 1 branch
BranchTrueFalseTotal
unless ($block) 0 15 15
133 15 push @$logs, $block;
134 15 $block = undef;
135 15 next;
136 }
137 109 my ( $kw, $rest ) = $l =~ /\A(\S+)\s*(.*)\z/;
138 109 ▶ if ( $SCRIPT{$kw} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($SCRIPT{$kw}) 10 99 109
139 0 ▶ if ( !$block ) { push @$out, "error: $shown:$n $kw outside of log file definition"; $err++; next }
Branch: 1 branch
BranchTrueFalseTotal
unless ($block) 0 10 10
140 10 $script = $kw;
141 10 $block->{scripts}{$kw} = [];
142 10 next;
143 }
144 99 ▶ if ( $kw eq 'include' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kw eq "include") 1 98 99
145 0 ▶ if ($block) { push @$out, "error: $shown:$n include not allowed inside a log file definition"; $err++; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($block) 0 1 1
146 1 $err += _read_config( $dev, $rest, $g, $logs, $out, $seen, $depth + 1 );
147 1 next;
148 }
149 98 ▶ if ( $PERIOD{$kw} ) { $cur->{period} = $kw; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($PERIOD{$kw}) 18 80 98
150 80 ▶ if ( $kw eq 'create' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kw eq "create") 11 69 80
151 11 my @c = split /\s+/, $rest;
152 0 ▶ if ( @c && $c[0] !~ /\A0?[0-7]{3,4}\z/ ) { push @$out, "error: $shown:$n unknown unix user $c[0]"; $err++; next }
Branch: 1 branch
BranchTrueFalseTotal
if (@c and not $c[0] =~ /\A0?[0-7]{3,4}\z/) 0 11 11
Condition66%2/3
@c and not $c[0] =~ /\A0?[0-7]{3,4}\z/
!ll&&!rl&&r
1100
MC/DC0%0/2
@c and not $c[0] =~ /\A0?[0-7]{3,4}\z/
@c not $c[0] =~ /\A0?[0-7]{3,4}\z/
Truth table66%2/3
A and not(B)
A= @cB= not $c[0] =~ /\A0?[0-7]{3,4}\z/
ABresult
0X0
100
111
153 11 $cur->{create} = [@c];
154 11 delete $cur->{nocreate};
155 11 next;
156 }
157 69 ▶ if ( $kw eq 'rotate' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kw eq "rotate") 15 54 69
158 0 ▶ if ( $rest !~ /\A-?\d+\z/ ) { push @$out, "error: $shown:$n bad rotation count '$rest'"; $err++; next }
Branch: 1 branch
BranchTrueFalseTotal
unless ($rest =~ /\A-?\d+\z/) 0 15 15
159 15 $cur->{rotate} = $rest;
160 15 next;
161 }
162 54 ▶ if ( $FLAG{$kw} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($FLAG{$kw}) 48 6 54
163 48 ( my $base = $kw ) =~ s/\Ano(?!tifempty)//;
164 48 ▶ $base = 'notifempty' if $kw eq 'ifempty';
Branch: 1 branch
BranchTrueFalseTotal
if $kw eq "ifempty" 0 48 48
165 0 ▶ if ( $kw eq 'ifempty' ) { delete $cur->{notifempty} }
Branch: 2 branches
BranchTrueFalseTotal
if ($kw eq 'ifempty') { } 0 48 48
elsif ($kw =~ /\Ano/ and $kw ne 'notifempty') { } 0 48 48
166 0 ▶ elsif ( $kw =~ /\Ano/ && $kw ne 'notifempty' ) { delete $cur->{$base}; delete $cur->{create} if $kw eq 'nocreate' }
Branch: 1 branch
BranchTrueFalseTotal
if $kw eq "nocreate" 0 0 0
Condition66%2/3
$kw =~ /\Ano/ and $kw ne "notifempty"
!ll&&!rl&&r
4260
MC/DC0%0/2
$kw =~ /\Ano/ and $kw ne "notifempty"
$kw =~ /\Ano/ $kw ne "notifempty"
Truth table66%2/3
A and B
A= $kw =~ /\Ano/B= $kw ne "notifempty"
ABresult
0X0
100
111
167 48 else { $cur->{$kw} = 1 }
168 48 next;
169 }
170 6 ▶ if ( $ARG{$kw} ) { $cur->{$kw} = $rest; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($ARG{$kw}) 3 3 6
171 3 push @$out, "error: $shown:$n unknown option '$kw' -- ignoring line";
172 3 $err++;
173 }
174 0 ▶ if ($pending) { push @$out, "error: $shown:$n missing '{' after log files definition"; $err++ }
Branch: 1 branch
BranchTrueFalseTotal
if ($pending) 0 18 18
175 0 ▶ if ($script) { push @$out, "error: $shown:$n missing endscript"; $err++ }
Branch: 1 branch
BranchTrueFalseTotal
if ($script) 0 18 18
176 18 ▶ if ($block) { push @$out, "error: $shown:$n missing '}' at end of file"; $err++ }
Branch: 1 branch
BranchTrueFalseTotal
if ($block) 2 16 18
177 18 return $err;
178 }
179  
180 # Dateien eines Musters im Zustand (Shell-Muster * und ? im letzten Teil)
181 32 ▶sub _expand {
Subroutine _expand: called CC=3 SCAR=11.0
182 32 my ( $dev, $pat ) = @_;
183 32 ▶ return ($pat) unless $pat =~ /[*?]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $pat =~ /[*?]/ 10 22 32
184 22 ( my $re = quotemeta $pat ) =~ s/\\\*/[^\/]*/g;
185 22 $re =~ s/\\\?/[^\/]/g;
186 22 ▶ return sort grep {/\A$re\z/} keys %{ $dev->{files} || {} };
Condition50%1/2
$$dev{'files'} || {}
l!l
220
MC/DC0%0/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table50%1/2
A
A= $$dev{'files'}
Aresult
11
00
187 }
188  
189 15 ▶sub _rotate_block {
Subroutine _rotate_block: called CC=29 SCAR=35.4
190 15 my ( $dev, $b, $ctx, $out, %o ) = @_;
191 15 my $opt = $b->{opt};
192 15 ▶ my $rot = $opt->{rotate} // 1;
Condition100%2/2
$$opt{"rotate"} // 1
l!l
141
MC/DC100%1/1
$$opt{"rotate"} // 1
$$opt{"rotate"}
Truth table100%2/2
A
A= $$opt{"rotate"}
Aresult
11
00
193 15 my $err = 0;
194 my $crit = $o{force} ? 'forced from command line' : ( $opt->{period} // 'weekly' ) eq 'daily' ? 'after 1 days'
195 15 ▶ : ( $opt->{period} // 'weekly' ) eq 'hourly' ? 'hourly' : $opt->{period} // 'weekly';
Branch: 3 branches
BranchTrueFalseTotal
$o{'force'} ? : 7 8 15
($$opt{'period'} // 'weekly') eq 'daily' ? : 7 1 8
($$opt{'period'} // 'weekly') eq 'hourly' ? : 0 1 1
Condition50%3/6
$$opt{"period"} // "weekly"
l!l
80
$$opt{"period"} // "weekly"
l!l
10
$$opt{"period"} // "weekly"
l!l
10
MC/DC0%0/1
$$opt{"period"} // "weekly"
$$opt{"period"}
MC/DC0%0/1
$$opt{"period"} // "weekly"
$$opt{"period"}
MC/DC0%0/1
$$opt{"period"} // "weekly"
$$opt{"period"}
Truth table50%1/2
A
A= $$opt{"period"}
Aresult
11
00
Truth table50%1/2
A
A= $$opt{"period"}
Aresult
11
00
Truth table50%1/2
A
A= $$opt{"period"}
Aresult
11
00
196 15 push @$out, '', 'rotating pattern: ' . join( ' ', @{ $b->{patterns} } ) . " $crit ($rot rotations)";
197 15 ▶ push @$out, 'empty log files ' . ( $opt->{notifempty} ? 'are not' : 'are' ) . ' rotated, old logs are removed';
Branch: 1 branch
BranchTrueFalseTotal
$$opt{'notifempty'} ? : 6 9 15
198 15 my @files = grep { !$b->{skip}{$_} } map { _expand( $dev, $_ ) } @{ $b->{patterns} };
199 15 my @done;
200 15 for my $f (@files) {
201 14 push @$out, "considering log $f";
202 14 my $e = _l( '_file_entry', $dev, $f );
203 14 ▶ if ( !$e ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($e) 1 13 14
204 1 ▶ if ( $opt->{missingok} ) { push @$out, " log $f does not exist -- skipping" }
Branch: 1 branch
BranchTrueFalseTotal
if ($$opt{'missingok'}) { } 1 0 1
205 0 else { push @$out, "error: stat of $f failed: No such file or directory"; $err++ }
206 1 next;
207 }
208 13 ( my $dir = $f ) =~ s{/[^/]+\z}{};
209 13 ▶ my $d = ( $dev->{dirs} || {} )->{$dir} || {};
Condition100%4/4
($$dev{'dirs'} || {})->{$dir} || {}
l!l
67
$$dev{'dirs'} || {}
l!l
67
MC/DC100%1/1
($$dev{'dirs'} || {})->{$dir} || {}
$$dev{'dirs'}
Truth table100%2/2
A
A= $$dev{'dirs'}
Aresult
11
00
210 13 ▶ my $dm = oct( $d->{mode} // '0755' );
Condition100%2/2
$$d{"mode"} // "0755"
l!l
67
MC/DC100%1/1
$$d{"mode"} // "0755"
$$d{"mode"}
Truth table100%2/2
A
A= $$d{"mode"}
Aresult
11
00
211 13 ▶ if ( !$opt->{su} && ( $dm & 002 || ( $dm & 020 && ( $d->{group} // 'root' ) ne 'root' ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $$opt{"su"} and $dm & 2 || $dm & 16 && ($$d{"group"} // "root") ne "root") 2 11 13
Condition72%8/11
not $$opt{"su"} and $dm & 2 || $dm & 16 && ($$d{"group"} // "root") ne "root"
!ll&&!rl&&r
382
$dm & 2 or $dm & 16 and ($$d{"group"} // "root") ne "root"
l!l&&r!l&&!r
028
$dm & 16 and ($$d{"group"} // "root") ne "root"
!ll&&!rl&&r
802
$$d{"group"} // "root"
l!l
20
MC/DC50%2/4
not $$opt{"su"} and $dm & 2 || $dm & 16 && ($$d{"group"} // "root") ne "root"
not $$opt{"su"} $dm & 2 $dm & 16 $$d{"group"}
Truth table60%3/5
not(A) and B or C and D
A= not $$opt{"su"}B= $dm & 2C= $dm & 16D= $$d{"group"}
ABCDresult
0XXX0
100X0
10100
11XX1
10111
212 2 push @$out, "error: skipping \"$f\" because parent directory has insecure permissions (It's world writable or writable by group which is not \"root\") Set \"su\" directive in the config file to tell logrotate which user/group should be used for rotation.";
213 2 $err++;
214 2 next;
215 }
216 11 push @$out, ' Now: 2026-10-20 14:00', ' Last rotated at 2026-10-20 00:00';
217 11 ▶ if ( !$o{force} ) { push @$out, ' log does not need rotating (log has been rotated at 2026-10-20 00:00, which is less than a day ago)'; next }
Branch: 1 branch
BranchTrueFalseTotal
unless ($o{"force"}) 4 7 11
218 0 ▶ if ( $opt->{notifempty} && _l( '_file_size', $e ) == 0 ) { push @$out, ' log does not need rotating (log is empty)'; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($$opt{"notifempty"} and _l("_file_size", $e) == 0) 0 7 7
Condition66%2/3
$$opt{"notifempty"} and _l("_file_size", $e) == 0
!ll&&!rl&&r
430
MC/DC0%0/2
$$opt{"notifempty"} and _l("_file_size", $e) == 0
$$opt{"notifempty"} _l("_file_size", $e) == 0
Truth table66%2/3
A and B
A= $$opt{"notifempty"}B= _l("_file_size", $e) == 0
ABresult
0X0
100
111
219 7 push @$out, ' log needs rotating';
220 7 push @done, $f;
221 }
222 15 ▶ return $err unless @done;
Branch: 1 branch
BranchTrueFalseTotal
unless @done 8 7 15
223 7 my $shared = $opt->{sharedscripts};
224 14 ▶ my $run = sub {
Subroutine __ANON__: called CC=10 SCAR=27.0
225 14 my ( $which, $arg ) = @_;
226 14 ▶ my $lines = $b->{scripts}{$which} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $lines = $$b{"scripts"}{$which} or return 5 9 14
227 5 push @$out, "running $which script";
228 5 ▶ return if $o{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $o{"debug"} 1 4 5
229 4 for my $line (@$lines) {
230 4 ( my $x = $line ) =~ s/\A\s+//;
231 4 ▶ next if $x eq '' || $x =~ /\A#/;
Branch: 1 branch
BranchTrueFalseTotal
if $x eq "" or $x =~ /\A#/ 0 4 4
Condition33%1/3
$x eq "" or $x =~ /\A#/
l!l&&r!l&&!r
004
MC/DC0%0/2
$x eq "" or $x =~ /\A#/
$x eq "" $x =~ /\A#/
Truth table33%1/3
A or B
A= $x eq ""B= $x =~ /\A#/
ABresult
1X1
011
000
232 4 ▶ $x =~ s/\$1\b/$arg/g if defined $arg;
Branch: 1 branch
BranchTrueFalseTotal
if defined $arg 4 0 4
233 4 my ( $so, $ok ) = $L->_run_inner( $dev, $x, $ctx );
234 4 ▶ push @$out, $so if defined $so && length $so;
Branch: 1 branch
BranchTrueFalseTotal
if defined $so and length $so 0 4 4
Condition33%1/3
defined $so and length $so
!ll&&!rl&&r
040
MC/DC0%0/2
defined $so and length $so
defined $so length $so
Truth table33%1/3
A and B
A= defined $soB= length $so
ABresult
0X0
100
111
235 0 ▶ if ( !$ok ) { push @$out, "error: error running shared $which script for '" . join( ' ', @{ $b->{patterns} } ) . "'"; $err++; last }
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 4 4
236 }
237 7 };
238 7 ▶ $run->( 'prerotate', join ' ', @{ $b->{patterns} } ) if $shared;
Branch: 1 branch
BranchTrueFalseTotal
if $shared 3 4 7
239 7 for my $f (@done) {
240 7 ▶ $run->( 'prerotate', $f ) unless $shared;
Branch: 1 branch
BranchTrueFalseTotal
unless $shared 4 3 7
241 7 _rotate_one( $dev, $f, $opt, $out, $o{debug} );
242 7 ▶ $run->( 'postrotate', $f ) unless $shared;
Branch: 1 branch
BranchTrueFalseTotal
unless $shared 4 3 7
243 }
244 7 ▶ $run->( 'postrotate', join ' ', @{ $b->{patterns} } ) if $shared;
Branch: 1 branch
BranchTrueFalseTotal
if $shared 3 4 7
245 7 return $err;
246 }
247  
248 3 ▶sub _gz { my ($e) = @_; my %n = %$e; $n{size} = _l( '_human', int( _l( '_file_size', $e ) / 10 ) + 1 ); $n{content} = ''; delete $n{open_by}; return \%n }
Subroutine _gz: called CC=1 SCAR=0.0
249  
250 7 ▶sub _rotate_one {
Subroutine _rotate_one: called CC=40 SCAR=41.8
251 7 my ( $dev, $f, $opt, $out, $debug ) = @_;
252 7 ▶ my $rot = $opt->{rotate} // 1;
Condition50%1/2
$$opt{"rotate"} // 1
l!l
70
MC/DC0%0/1
$$opt{"rotate"} // 1
$$opt{"rotate"}
Truth table50%1/2
A
A= $$opt{"rotate"}
Aresult
11
00
253 7 my $files = $dev->{files};
254 7 my $comp = $opt->{compress};
255 7 ▶ my $delay = $comp && $opt->{delaycompress};
Condition66%2/3
$comp && $$opt{'delaycompress'}
!ll&&!rl&&r
106
MC/DC50%1/2
$comp && $$opt{'delaycompress'}
$comp $$opt{'delaycompress'}
Truth table66%2/3
A && B
A= $compB= $$opt{'delaycompress'}
ABresult
0X0
100
111
256 7 push @$out, "rotating log $f, log->rotateCount is $rot", "dateext suffix '-20261020'", "glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'";
257 7 ▶ push @$out, 'compressing log with: /bin/gzip' if $comp;
Branch: 1 branch
BranchTrueFalseTotal
if $comp 6 1 7
258 # aeltere Generationen weiterschieben, die letzte faellt weg
259 7 ▶ for ( my $i = $rot; $i >= 1; $i-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 1) 37 7 44
260 37 for my $ext ( '.gz', '' ) {
261 74 my $src = "$f.$i$ext";
262 74 ▶ next unless exists $files->{$src};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$files{$src} 64 10 74
263 10 ▶ if ( $i == $rot ) { push @$out, "removing old log $src"; delete $files->{$src} unless $debug; next }
Branch: 2 branches
BranchTrueFalseTotal
if ($i == $rot) 3 7 10
unless $debug 2 1 3
264 7 ▶ my $dst = "$f." . ( $i + 1 ) . ( $ext eq '' && $comp && $i == 1 && $delay ? '.gz' : $ext );
Branch: 1 branch
BranchTrueFalseTotal
$ext eq '' && $comp && $i == 1 && $delay ? : 4 3 7
Condition66%6/9
$ext eq "" and $comp and $i == 1 and $delay
!ll&&!rl&&r
304
$ext eq "" and $comp and $i == 1
!ll&&!rl&&r
304
$ext eq "" and $comp
!ll&&!rl&&r
304
MC/DC25%1/4
$ext eq "" and $comp and $i == 1 and $delay
$ext eq "" $comp $i == 1 $delay
Truth table40%2/5
A and B and C and D
A= $ext eq ""B= $compC= $i == 1D= $delay
ABCDresult
0XXX0
10XX0
110X0
11100
11111
265 7 push @$out, "renaming $src to $dst (rotatecount $rot, logstart 1, i $i),";
266 7 ▶ next if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 2 5 7
267 5 my $e = delete $files->{$src};
268 5 ▶ $files->{$dst} = $dst =~ /\.gz\z/ && $src !~ /\.gz\z/ ? _gz( ref $e ? $e : { content => $e } ) : $e;
Branch: 2 branches
BranchTrueFalseTotal
$dst =~ /\.gz\z/ && !($src =~ /\.gz\z/) ? : 3 2 5
ref $e ? : 3 0 3
Condition66%2/3
$dst =~ /\.gz\z/ and not $src =~ /\.gz\z/
!ll&&!rl&&r
023
MC/DC50%1/2
$dst =~ /\.gz\z/ and not $src =~ /\.gz\z/
$dst =~ /\.gz\z/ not $src =~ /\.gz\z/
Truth table66%2/3
A and not(B)
A= $dst =~ /\.gz\z/B= not $src =~ /\.gz\z/
ABresult
0X0
100
111
269 }
270 }
271 7 ▶ my $one = "$f.1" . ( $comp && !$delay ? '.gz' : '' );
Branch: 1 branch
BranchTrueFalseTotal
$comp && !$delay ? : 0 7 7
Condition66%2/3
$comp and not $delay
!ll&&!rl&&r
160
MC/DC0%0/2
$comp and not $delay
$comp not $delay
Truth table66%2/3
A and not(B)
A= $compB= not $delay
ABresult
0X0
100
111
272 7 my $e = _l( '_file_entry', $dev, $f );
273 7 ▶ if ( $opt->{copytruncate} || $opt->{copy} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$opt{"copytruncate"} or $$opt{"copy"}) 2 5 7
Condition66%2/3
$$opt{"copytruncate"} or $$opt{"copy"}
l!l&&r!l&&!r
205
MC/DC50%1/2
$$opt{"copytruncate"} or $$opt{"copy"}
$$opt{"copytruncate"} $$opt{"copy"}
Truth table66%2/3
A or B
A= $$opt{"copytruncate"}B= $$opt{"copy"}
ABresult
1X1
011
000
274 2 push @$out, "copying $f to $f.1";
275 2 ▶ push @$out, "truncating $f" if $opt->{copytruncate};
Branch: 1 branch
BranchTrueFalseTotal
if $$opt{"copytruncate"} 2 0 2
276 2 ▶ return if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 2 2
277 2 my %c = %$e;
278 2 delete $c{open_by};
279 2 ▶ $files->{$one} = $comp && !$delay ? _gz( \%c ) : \%c;
Branch: 1 branch
BranchTrueFalseTotal
$comp && !$delay ? : 0 2 2
Condition66%2/3
$comp and not $delay
!ll&&!rl&&r
110
MC/DC0%0/2
$comp and not $delay
$comp not $delay
Truth table66%2/3
A and not(B)
A= $compB= not $delay
ABresult
0X0
100
111
280 2 ▶ if ( $opt->{copytruncate} ) { my %t = %$e; $t{content} = ''; $t{size} = '0'; $files->{$f} = \%t }
Branch: 1 branch
BranchTrueFalseTotal
if ($$opt{"copytruncate"}) 2 0 2
281 2 return;
282 }
283 5 push @$out, "renaming $f to $f.1";
284 5 ▶ my $cr = $opt->{create} && !$opt->{nocreate};
Condition33%1/3
$$opt{'create'} && !$$opt{'nocreate'}
!ll&&!rl&&r
005
MC/DC0%0/2
$$opt{'create'} && !$$opt{'nocreate'}
$$opt{'create'} !$$opt{'nocreate'}
Truth table33%1/3
A && not(B)
A= $$opt{'create'}B= !$$opt{'nocreate'}
ABresult
0X0
100
111
285 5 ▶ my ( $m, $u, $g ) = @{ $opt->{create} || [] };
Condition50%1/2
$$opt{'create'} || []
l!l
50
MC/DC0%0/1
$$opt{'create'} || []
$$opt{'create'}
Truth table50%1/2
A
A= $$opt{'create'}
Aresult
11
00
286 5 ▶ $m //= $e->{mode} // '0644';
Condition25%1/4
$m //= $$e{"mode"} // "0644"
l!l
50
$$e{"mode"} // "0644"
l!l
00
MC/DC0%0/1
$m //= $$e{"mode"} // "0644"
$m
Truth table50%1/2
A
A= $m
Aresult
11
00
287 5 ▶ $u //= $e->{owner} // 'root';
Condition25%1/4
$u //= $$e{"owner"} // "root"
l!l
50
$$e{"owner"} // "root"
l!l
00
MC/DC0%0/1
$u //= $$e{"owner"} // "root"
$u
Truth table50%1/2
A
A= $u
Aresult
11
00
288 5 ▶ $g //= $e->{group} // 'root';
Condition25%1/4
$g //= $$e{"group"} // "root"
l!l
50
$$e{"group"} // "root"
l!l
00
MC/DC0%0/1
$g //= $$e{"group"} // "root"
$g
Truth table50%1/2
A
A= $g
Aresult
11
00
289 5 ▶ push @$out, sprintf( 'creating new %s mode = %04o uid = %d gid = %d', $f, oct $m, _l( '_uid', $dev, $u ), _l( '_gid', $dev, $g ) ) if $cr;
Branch: 1 branch
BranchTrueFalseTotal
if $cr 5 0 5
290 5 ▶ return if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 1 4 5
291 4 my %r = %$e;
292 4 ▶ $r{opened_as} = $f if defined $r{open_by}; # der Dienst schreibt weiter hierhin, bis er neu oeffnet
Branch: 1 branch
BranchTrueFalseTotal
if defined $r{"open_by"} 4 0 4
293 4 delete $files->{$f};
294 4 $files->{"$f.1"} = \%r;
295 0 ▶ if ( $comp && !$delay ) { $files->{$one} = _gz( \%r ); delete $files->{"$f.1"} }
Branch: 1 branch
BranchTrueFalseTotal
if ($comp and not $delay) 0 4 4
Condition33%1/3
$comp and not $delay
!ll&&!rl&&r
040
MC/DC0%0/2
$comp and not $delay
$comp not $delay
Truth table33%1/3
A and not(B)
A= $compB= not $delay
ABresult
0X0
100
111
296 4 ▶ $files->{$f} = { content => '', size => '0', mode => sprintf( '%04o', oct $m ), owner => $u, group => $g, mtime => 'Oct 20 14:00' } if $cr;
Branch: 1 branch
BranchTrueFalseTotal
if $cr 4 0 4
297 4 return;
298 }
299  
300 3 1;
301  
302 __END__
« blib/lib/Langertha/Holmgang/Sim/Linux/Monitoring.pm ↑ Summary blib/lib/Langertha/Holmgang/World.pm »