« blib/lib/Lemonldap/NG/Common/Conf/Serializer.pm
↑ Summary
blib/lib/Lemonldap/NG/Common/Logger/Sentry.pm »
| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use POSIX; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Pod::Usage; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | our $VERSION = "2.22.0"; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | # Options | ||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | my $opts = {}; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | my $help; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | my $opt_user = '__APACHEUSER__'; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | my $opt_group = '__APACHEGROUP__'; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | my @CMDLINE = @ARGV; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | GetOptions( | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 'daemon' => \$opts->{daemon}, | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 'defer-dir=s' => \$opts->{deferDir}, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 'debug' => \$opts->{debug}, | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 'delay=s' => \$opts->{delay}, | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 'group|g=s' => \$opts->{group}, | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 'help|h' => \$help, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 'ini-file=s' => \$opts->{iniFile}, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 'syslog-facility' => \$opts->{syslogFacility}, | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 'user|u=s' => \$opts->{user}, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | ) or pod2usage( -exitcode => 1, -verbose => 0 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | foreach my $opt ( keys %$opts ) { | |||||||||||||||||||||||||||||||||||||||||
| 31 | 8 | ▶ | $opts->{$opt} //= $ENV{ 'LLNG_LOKI_' . uc($opt) }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$opts->{$opt} //= $ENV{'LLNG_LOKI_' . uc($opt)}
MC/DC50%1/2
$opts->{$opt} //= $ENV{'LLNG_LOKI_' . uc($opt)}
$opts->{$opt}
$ENV{'LLNG_LOKI_' . uc($opt)}
Truth table66%2/3
A //= B
A= $opts->{$opt}B= $ENV{'LLNG_LOKI_' . uc($opt)}
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | pod2usage( -exitcode => 0, -verbose => 2 ) if $help; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | ▶ | $opts->{delay} ||= 60 if $opts->{daemon}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$opts->{"delay"} ||= 60
MC/DC0%0/1
$opts->{"delay"} ||= 60
$opts->{"delay"}
Truth table0%0/2
A
A= $opts->{"delay"}
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | $opts->{deferDir} ||= &_getDeferDir; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opts->{"deferDir"} ||= &_getDeferDir
MC/DC0%0/2
$opts->{"deferDir"} ||= &_getDeferDir
$opts->{"deferDir"}
&_getDeferDir
Truth table33%1/3
A ||= B
A= $opts->{"deferDir"}B= &_getDeferDir
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | ▶ | mkdir $opts->{deferDir} unless -e $opts->{deferDir}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | die "Missing directory $opts->{deferDir}" unless -d $opts->{deferDir}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | die "Cannot write into $opts->{deferDir}" unless -w $opts->{deferDir}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | ▶ | die 'Missing --defer-dir' unless $opts->{deferDir}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | # Change owner if asked | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | POSIX::nice(10); | |||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | ▶ | if ( $opts->{group} || $opts->{user} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$opts->{"group"} or $opts->{"user"}
MC/DC0%0/2
$opts->{"group"} or $opts->{"user"}
$opts->{"group"}
$opts->{"user"}
Truth table33%1/3
A or B
A= $opts->{"group"}B= $opts->{"user"}
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my ( $gid, $uid ); | |||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if ( $opts->{group} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $gid = getgrnam( $opts->{group} ); | |||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | POSIX::setgid($gid); | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ( $opts->{user} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | $uid = getpwnam( $opts->{user} ); | |||||||||||||||||||||||||||||||||||||||||
| 56 | chown( $uid, ( $gid // [ stat( $opts->{deferDir} ) ]->[5] ), | ||||||||||||||||||||||||||||||||||||||||||
| 57 | $opts->{deferDir} ) | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | and chmod( 0700, $opts->{deferDir} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$gid // [stat $opts->{"deferDir"}]->[5]
MC/DC0%0/2
$gid // [stat $opts->{"deferDir"}]->[5]
$gid
[stat $opts->{"deferDir"}]->[5]
Truth table0%0/3
A // B
A= $gidB= [stat $opts->{"deferDir"}]->[5]
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | POSIX::setuid( scalar( getpwnam( $opts->{user} ) ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if $opts->{user}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | my ( | ||||||||||||||||||||||||||||||||||||||||||
| 62 | undef, undef, undef, undef, undef, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | undef, undef, $homedir, undef | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ) = getpwnam( $opts->{user} ); | |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | $ENV{HOME} = $homedir if $homedir; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | ▶ | &daemonize if $opts->{daemon}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | require HTTP::Request; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | require JSON; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | require LWP::UserAgent; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | require Sys::Syslog; | |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | my $j = JSON->new->canonical; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | my $syslogOpened; | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub _log { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_log: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my ( $level, $msg ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ( $opts->{daemon} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | unless ($syslogOpened) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | Sys::Syslog::openlog( 'LLNG-Loki', 'cons,pid,ndelay', | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | $opts->{syslogFacility} || 'daemon' ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts->{'syslogFacility'} || 'daemon'
MC/DC0%0/1
$opts->{'syslogFacility'} || 'daemon'
$opts->{'syslogFacility'}
Truth table0%0/2
A
A= $opts->{'syslogFacility'}
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $syslogOpened++; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | Sys::Syslog::syslog( $level, $msg ); | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | print STDERR "[$level] $msg\n"; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 4 | ▶ | sub debug { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debug: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | map { _log( 'debug', $_ ) } @_ if $opts->{debug}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub warning { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
warning: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | map { _log( 'warning', $_ ) } @_; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | map { _log( 'err', $_ ) } @_; | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | sub _getDeferDir { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_getDeferDir: not called CC=4 SCAR=26.1
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | require Lemonldap::NG::Common::Conf; | |||||||||||||||||||||||||||||||||||||||||
| 111 | my $ca = Lemonldap::NG::Common::Conf->new( { ( | ||||||||||||||||||||||||||||||||||||||||||
| 112 | $opts->{iniFile} | ||||||||||||||||||||||||||||||||||||||||||
| 113 | ? ( confFile => $opts->{iniFile} ) | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | : () | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | die $Lemonldap::NG::Common::Conf::msg unless ($ca); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my $conf = $ca->getConf('all'); | |||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | my $localConf = $ca->getLocalConf( 'all', $_[0]->{iniFile} ); | |||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $conf = { %$conf, %$localConf }; | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | unless ( $conf->{lokiDeferDir} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | die 'Missing lokiDeferDir'; | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | debug "Conf downloaded from Lemonldap::NG::Common::Conf: $conf->{cfgNum}"; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | return $conf->{lokiDeferDir}; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 2 | ▶ | sub sendLogs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sendLogs: called CC=26 SCAR=37.0
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 2 | my $i; | |||||||||||||||||||||||||||||||||||||||||
| 134 | 2 | my $ret = 1; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 2 | ▶ | if ( opendir my $dh, $opts->{deferDir} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | debug "Checking for logs into $opts->{deferDir}"; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 2 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | my ( %logs, %filesToDel, @headers, $hdr_done, %streams, %urls ); | |||||||||||||||||||||||||||||||||||||||||
| 139 | 2 | ▶ | while ( my $name = readdir($dh) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 7 | $i++; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 7 | my $fn = "$opts->{deferDir}/$name"; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 7 | ▶ | next if $name =~ m#^\.# or !-f $fn; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$name =~ /^\./ or not -f $fn
MC/DC50%1/2
$name =~ /^\./ or not -f $fn
$name =~ /^\./
not -f $fn
Truth table66%2/3
A or not(B)
A= $name =~ /^\./B= not -f $fn
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 3 | my $fh; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 3 | ▶ | unless ( open $fh, '<', $fn ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | error "Unable to open $fn: $!"; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | $ret = 0; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | goto END; | |||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 3 | my $tmp = <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 3 | ▶ | unless ($tmp) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | debug "Empty file $fn"; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | goto END; | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 3 | chomp $tmp; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 3 | my ( $meth, $url ) = split( /\s+/, $tmp, 2 ); | |||||||||||||||||||||||||||||||||||||||||
| 156 | 3 | ▶ | unless ( $meth and $url and $meth eq 'POST' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$meth and $url and $meth eq "POST"
$meth and $url
MC/DC0%0/3
$meth and $url and $meth eq "POST"
$meth
$url
$meth eq "POST"
Truth table25%1/4
A and B and C
A= $methB= $urlC= $meth eq "POST"
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | warning "Not a valid file $fn"; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | goto END; | |||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | # Get headers; | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 3 | ▶ | while ( my $line = <$fh> ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 6 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 6 | $line =~ s/\r//g; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 6 | ▶ | unless ($line) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 3 | $hdr_done = 1; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 3 | last; | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 3 | ▶ | next if $hdr_done; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 1 | my ( $k, $v ) = split( /:\s+/, $line ); | |||||||||||||||||||||||||||||||||||||||||
| 171 | 1 | ▶ | push @headers, $k, $v if $v and lc($k) ne 'content-length'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$v and lc $k ne "content-length"
MC/DC0%0/2
$v and lc $k ne "content-length"
$v
lc $k ne "content-length"
Truth table33%1/3
A and B
A= $vB= lc $k ne "content-length"
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | # Get content | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 3 | my $content; | |||||||||||||||||||||||||||||||||||||||||
| 176 | { | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 3 | local $/ = undef; | |||||||||||||||||||||||||||||||||||||||||
| 178 | 3 | ▶ | while ( my $line = <$fh> ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 3 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 3 | $line =~ s/[\r\n]//g; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 3 | ▶ | next unless $line; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 3 | $content = eval { $j->decode($line)->{streams} }; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 3 | ▶ | if ( $@ or not $content ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$@ or not $content
MC/DC0%0/2
$@ or not $content
$@
not $content
Truth table33%1/3
A or not(B)
A= $@B= not $content
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | warning "Malformed line ($fn): $line"; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 3 | ▶ | next unless $content; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 3 | foreach my $stream (@$content) { | |||||||||||||||||||||||||||||||||||||||||
| 191 | 3 | my $k = $j->encode( $stream->{stream} ); | |||||||||||||||||||||||||||||||||||||||||
| 192 | 3 | push @{ $logs{$k} }, @{ $stream->{values} }; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 3 | push @{ $filesToDel{$k} }, $fn; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 3 | ▶ | $streams{$k} ||= $stream->{stream}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$streams{$k} ||= $stream->{"stream"}
MC/DC0%0/2
$streams{$k} ||= $stream->{"stream"}
$streams{$k}
$stream->{"stream"}
Truth table66%2/3
A ||= B
A= $streams{$k}B= $stream->{"stream"}
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 3 | ▶ | $urls{$k} ||= $url; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$urls{$k} ||= $url
MC/DC0%0/2
$urls{$k} ||= $url
$urls{$k}
$url
Truth table66%2/3
A ||= B
A= $urls{$k}B= $url
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 3 | END: close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 2 | my $ua = LWP::UserAgent->new; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 2 | $ua->env_proxy; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 2 | foreach my $key ( keys %logs ) { | |||||||||||||||||||||||||||||||||||||||||
| 202 | my $req = HTTP::Request->new( | ||||||||||||||||||||||||||||||||||||||||||
| 203 | POST => $urls{$key}, | ||||||||||||||||||||||||||||||||||||||||||
| 204 | \@headers, | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | #HTTP::Headers->new(@{$headers{$key}}), | ||||||||||||||||||||||||||||||||||||||||||
| 207 | $j->encode( { | ||||||||||||||||||||||||||||||||||||||||||
| 208 | streams => [ { | ||||||||||||||||||||||||||||||||||||||||||
| 209 | stream => $streams{$key}, | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 2 | values => $logs{$key}, | |||||||||||||||||||||||||||||||||||||||||
| 211 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 212 | ] | ||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 215 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 2 | my $resp = $ua->request($req); | |||||||||||||||||||||||||||||||||||||||||
| 217 | 2 | ▶ | if ( $resp->is_success ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 2 | debug "Logs $key sent"; | |||||||||||||||||||||||||||||||||||||||||
| 219 | 2 | ▶ | unlink( @{ $filesToDel{$key} } ) or warning $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | $ret = 0; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | error "Fail to send logs: " . $resp->status_line; | |||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | error "Unable to open $opts->{deferDir}: $!"; | |||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 2 | return $ret; | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | sub daemonize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
daemonize: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | open STDIN, '<', '/dev/null' or die "Can't read /dev/null: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | open STDOUT, '>', '/dev/null' or die "Can't write to /dev/null: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | open STDERR, '>', '/dev/null' or die "Can't write to /dev/null: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | defined( my $pid = fork ) or die "Can't fork: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | exit if $pid; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | setsid() or die "Can't start a new session: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | defined( $pid = fork ) or die "Can't fork again: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | exit if $pid; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | umask 0; | |||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | if ( $opts->{pidFile} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | open my $fh, '>', $opts->{pidFile} | ||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | or die "Can't write $opts->{pidFile} $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | print $fh "$$\n"; | |||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | $0 = join ' ', $0, @CMDLINE; | |||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | ## MAIN | ||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | 1 | ▶ | if ( $opts->{delay} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | $SIG{$_} = \&sendLogs foreach (qw(ALRM USR1 USR2)); | |||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | $SIG{$_} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | debug "End asked"; | |||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | exit( &sendLogs ? 0 : 1 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | foreach (qw(INT TERM QUIT KILL ABRT HUP)); | |||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | &sendLogs; | |||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | sleep $opts->{delay}; | |||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||
| 271 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 1 | ▶ | &sendLogs || exit 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
&sendLogs || exit 1
MC/DC0%0/1
&sendLogs || exit 1
&sendLogs
Truth table50%1/2
A
A= &sendLogs
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | __END__ | ||||||||||||||||||||||||||||||||||||||||||