From 4ee2f20bc6c8371e3039c4db6c22d89cd6c1dbed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 20 Aug 2018 11:33:54 +0200 Subject: [PATCH 01/10] [perlcritic] fix lib/Munin/Plugin warnings --- Makefile | 2 +- lib/Munin/Plugin/Pgsql.pm | 10 ++++++---- lib/Munin/Plugin/SNMP.pm | 2 ++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index f99b8627e5..6afe0cba65 100644 --- a/Makefile +++ b/Makefile @@ -58,7 +58,7 @@ install: $(BUILD_SCRIPT) .PHONY: perlcritic perlcritic: #TODO: apply to scripts/ and lib/Munin/Master/ - perlcritic lib/Munin/Node + perlcritic lib/Munin/Node lib/Munin/Plugin .PHONY: lint lint: diff --git a/lib/Munin/Plugin/Pgsql.pm b/lib/Munin/Plugin/Pgsql.pm index 8e6a220cf7..21fc57695b 100644 --- a/lib/Munin/Plugin/Pgsql.pm +++ b/lib/Munin/Plugin/Pgsql.pm @@ -105,6 +105,8 @@ package Munin::Plugin::Pgsql; use strict; use warnings; +use English qw(-no_match_vars); + use Munin::Plugin; =head2 Initialization @@ -449,7 +451,7 @@ sub _connect() { return 1 if ($self->{dbh}); - if (eval "require DBI; require DBD::Pg;") { + if (eval {require DBI; require DBD::Pg;}) { # By default, connect to database template1, because it exists on both old # and new versions of PostgreSQL, unless the database should be controlled @@ -469,7 +471,7 @@ sub _connect() { $err_str =~ s/[\r\n\t]/ /g; $err_str =~ s/\h+/ /g; $err_str =~ s/ $//; - $self->{connecterror} = $err_str; + $self->{connecterror} = $err_str; return 0; } } @@ -595,14 +597,14 @@ sub replace_wildcard_parameters { sub wildcard_parameter { my ($self, $paramnum) = @_; - return undef unless (defined $self->{basename}); + return unless (defined $self->{basename}); $paramnum = 0 unless (defined $paramnum); if ($0 =~ /$self->{basename}(.*)$/) { # If asking for first parameter, and there's no filter on it, # return undef. - return undef if ($1 eq "ALL" && $paramnum == 0); + return if ($1 eq "ALL" && $paramnum == 0); # If asking for unsplit, return that (internal use only, really) return $1 if ($paramnum == -1); diff --git a/lib/Munin/Plugin/SNMP.pm b/lib/Munin/Plugin/SNMP.pm index 5ecb71048a..f18ec784d7 100644 --- a/lib/Munin/Plugin/SNMP.pm +++ b/lib/Munin/Plugin/SNMP.pm @@ -54,6 +54,8 @@ package Munin::Plugin::SNMP; use strict; use warnings; +use English qw(-no_match_vars); + use Net::SNMP; use Munin::Plugin; From af988c985b24824e93cebdd7af90fea407f4010a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 20 Aug 2018 12:23:13 +0200 Subject: [PATCH 02/10] [perlcritic] fix lib/Munin/Common warnings --- Makefile | 2 +- lib/Munin/Common/Logger.pm | 4 ++- lib/Munin/Common/SyncDictFile.pm | 30 +++++++++++++---------- lib/Munin/Common/TLS.pm | 42 ++++++++++++++++---------------- lib/Munin/Common/TLSClient.pm | 4 +-- lib/Munin/Common/TLSServer.pm | 2 +- lib/Munin/Common/Timeout.pm | 8 +++--- 7 files changed, 49 insertions(+), 43 deletions(-) diff --git a/Makefile b/Makefile index 6afe0cba65..4a39095910 100644 --- a/Makefile +++ b/Makefile @@ -58,7 +58,7 @@ install: $(BUILD_SCRIPT) .PHONY: perlcritic perlcritic: #TODO: apply to scripts/ and lib/Munin/Master/ - perlcritic lib/Munin/Node lib/Munin/Plugin + perlcritic lib/Munin/Node lib/Munin/Plugin lib/Munin/Common .PHONY: lint lint: diff --git a/lib/Munin/Common/Logger.pm b/lib/Munin/Common/Logger.pm index 2ff0ce5e0f..2bb2d5132b 100644 --- a/lib/Munin/Common/Logger.pm +++ b/lib/Munin/Common/Logger.pm @@ -20,6 +20,8 @@ our @EXPORT use Params::Validate qw(validate SCALAR); use POSIX; +use English qw(-no_match_vars); + sub _program_name { my @path = split( '/', $0 ); return $path[-1]; @@ -47,7 +49,7 @@ my $screen_format = sub { chomp $message; - return sprintf( "%s [%s][%06d]: %s\n", _timestamp, $level, $$, $message ); + return sprintf( "%s [%s][%06d]: %s\n", _timestamp, $level, $PID, $message ); }; my $file_format = $screen_format; diff --git a/lib/Munin/Common/SyncDictFile.pm b/lib/Munin/Common/SyncDictFile.pm index 5d2116687e..c6fb949eae 100644 --- a/lib/Munin/Common/SyncDictFile.pm +++ b/lib/Munin/Common/SyncDictFile.pm @@ -1,4 +1,8 @@ package Munin::Common::SyncDictFile; + +use strict; +use warnings; + require Tie::Hash; our @ISA = qw(Tie::Hash); @@ -28,7 +32,7 @@ sub STORE { my ($self, $key, $value) = @_; DEBUG("STORE($key, $value)"); $key = escape_key($key); - + use IO::File; my $fh = _lock_write($self->{filename}, "r"); @@ -41,7 +45,7 @@ sub STORE { # Print the read line, but ignore the key we are currently storing print $fh_tmp "$line\n" unless $line =~ m/^$key:/; } - + # Print the stored key at the end DEBUG("Print the stored $key:$value"); print $fh_tmp "$key:$value\n"; @@ -73,7 +77,7 @@ sub FETCH { # Return the first key in the hash. sub FIRSTKEY { - my ($self) = @_; + my ($self) = @_; DEBUG("FIRSTKEY()"); my $fh = _lock_read($self->{filename}); @@ -88,11 +92,11 @@ sub FIRSTKEY { # Return the next key in the hash. sub NEXTKEY { - my ($self, $lastkey) = @_; - DEBUG("NEXTKEY($lastkey)"); + my ($self, $key) = @_; + DEBUG("NEXTKEY($key)"); $key = escape_key($key); my $fh = _lock_read($self->{filename}); - + # Read the file to find a key while(my $line = <$fh>) { chomp($line); @@ -105,7 +109,7 @@ sub NEXTKEY { return $1; } else { # EOF - return undef; + return; } } } @@ -139,16 +143,16 @@ sub DELETE { # Clear all values from the tied hash this. sub CLEAR { - my ($self) = @_; + my ($self) = @_; DEBUG("CLEAR()"); my $fh = $self->_lock_write(); } sub SCALAR { - my ($self) = @_; + my ($self) = @_; DEBUG("SCALAR()"); my $fh = _lock_read($self->{filename}); - + # Read the file to read the number of lines my $nb_lines = 0; while(my $line = <$fh>) { @@ -177,15 +181,15 @@ sub _lock_write { use Fcntl qw(:flock); use IO::File; - - my $fh = IO::File->new($filename, $mode) + + my $fh = IO::File->new($filename, $mode) or die "Cannot open tied file '$filename' - $!"; flock($fh, LOCK_EX) or die "Cannot lock tied file '$filename' - $!"; return $fh; } sub DEBUG { - print STDOUT "[DEBUG] @_" . "\n" if $DEBUG_ENABLED; + print STDOUT "[DEBUG] @_" . "\n" if $DEBUG_ENABLED; } # XXX - collision if there is a ____ diff --git a/lib/Munin/Common/TLS.pm b/lib/Munin/Common/TLS.pm index f0186abab8..54d8d7532a 100644 --- a/lib/Munin/Common/TLS.pm +++ b/lib/Munin/Common/TLS.pm @@ -53,15 +53,15 @@ sub _start_tls { my $self = shift; my %tls_verified = ( - level => 0, + level => 0, cert => "", - verified => 0, - required_depth => $self->{tls_vdepth}, + verified => 0, + required_depth => $self->{tls_vdepth}, verify => $self->{tls_verify}, ); DEBUG("[TLS] Enabling TLS.") if $self->{DEBUG}; - + $self->_load_net_ssleay() or return 0; @@ -71,16 +71,16 @@ sub _start_tls { $self->_load_private_key() or return 0; - + $self->_load_certificate(); $self->_load_ca_certificate(); - + $self->_initial_communication() or return 0; - + $self->_set_peer_requirements(\%tls_verified); - + if (! ($self->{tls_session} = Net::SSLeay::new($self->{tls_context}))) { ERROR("Could not create TLS: $!"); @@ -103,7 +103,7 @@ sub _load_net_ssleay { eval { require Net::SSLeay; }; - if ($@) { + if ($EVAL_ERROR) { ERROR("TLS enabled but Net::SSLeay unavailable."); return 0; } @@ -146,8 +146,8 @@ sub _load_private_key { if (defined $self->{tls_priv} and length $self->{tls_priv}) { if (-e $self->{tls_priv} or $self->{tls_paranoia} eq "paranoid") { - if (Net::SSLeay::CTX_use_PrivateKey_file($self->{tls_context}, - $self->{tls_priv}, + if (Net::SSLeay::CTX_use_PrivateKey_file($self->{tls_context}, + $self->{tls_priv}, &Net::SSLeay::FILETYPE_PEM)) { $self->{private_key_loaded} = 1; } @@ -211,7 +211,7 @@ sub _set_peer_requirements { if (defined $err and length $err) { WARNING("in set_verify_depth: $err"); } - Net::SSLeay::CTX_set_verify ($self->{tls_context}, + Net::SSLeay::CTX_set_verify ($self->{tls_context}, $self->{tls_verify} ? &Net::SSLeay::VERIFY_PEER : &Net::SSLeay::VERIFY_NONE, $self->_tls_verify_callback($tls_verified)); @@ -219,7 +219,7 @@ sub _set_peer_requirements { if (defined $err and length $err) { WARNING("in set_verify: $err"); } - + return 1; } @@ -228,7 +228,7 @@ sub _tls_verify_callback { my ($self, $tls_verified) = @_; return sub { - my ($ok, $subj_cert, $issuer_cert, $depth, + my ($ok, $subj_cert, $issuer_cert, $depth, $errorcode, $arg, $chain) = @_; $tls_verified->{"level"}++; @@ -238,7 +238,7 @@ sub _tls_verify_callback { DEBUG("[TLS] Verified certificate.") if $self->{DEBUG}; return 1; # accept } - + if (!($tls_verified->{"verify"})) { DEBUG("[TLS] Certificate failed verification, but we aren't verifying.") if $self->{DEBUG}; $tls_verified->{"verified"} = 1; @@ -321,7 +321,7 @@ sub _accept_or_connect { } elsif ($self->{"tls_match"} and Net::SSLeay::dump_peer_certificate($self->{tls_session}) !~ /$self->{tls_match}/) - { + { ERROR("Could not match pattern \"" . $self->{tls_match} . "\" in dump of certificate."); $self->_on_unmatched_cert(); @@ -342,7 +342,7 @@ sub _accept_or_connect { sub _initial_communication { my ($self) = @_; croak "Abstract method called '_initial_communication', " - . "needs to be defined in child" + . "needs to be defined in child" if ref $self eq __PACKAGE__; } @@ -351,7 +351,7 @@ sub _initial_communication { sub _use_key_if_present { my ($self) = @_; croak "Abstract method called '_use_key_if_present', " - . "needs to be defined in child" + . "needs to be defined in child" if ref $self eq __PACKAGE__; } @@ -365,7 +365,7 @@ sub _on_unmatched_cert {} sub read { my ($self) = @_; - croak "Tried to do an encrypted read, but a TLS session is not started" + croak "Tried to do an encrypted read, but a TLS session is not started" unless $self->session_started(); my $read = Net::SSLeay::read($self->{tls_session}); @@ -384,7 +384,7 @@ sub read { sub write { my ($self, $text) = @_; - croak "Tried to do an encrypted write, but a TLS session is not started" + croak "Tried to do an encrypted write, but a TLS session is not started" unless $self->session_started(); DEBUG("DEBUG: > $text") if $self->{DEBUG}; @@ -395,7 +395,7 @@ sub write { ERROR("[TLS] Warning in write: $err"); return 0; } - + return 1; } diff --git a/lib/Munin/Common/TLSClient.pm b/lib/Munin/Common/TLSClient.pm index fbf68e79bd..53b8d83506 100644 --- a/lib/Munin/Common/TLSClient.pm +++ b/lib/Munin/Common/TLSClient.pm @@ -11,7 +11,7 @@ use Munin::Common::Logger; sub new { my ($class, $args) = @_; - + my $self = $class->SUPER::new($args); $self->{remote_key} = 0; @@ -28,7 +28,7 @@ sub start_tls { sub _initial_communication { my ($self) = @_; - + $self->{write_func}("STARTTLS\n"); my $tlsresponse = $self->{read_func}(); if (!defined $tlsresponse) { diff --git a/lib/Munin/Common/TLSServer.pm b/lib/Munin/Common/TLSServer.pm index f81c6ee9d1..daaeb411f5 100644 --- a/lib/Munin/Common/TLSServer.pm +++ b/lib/Munin/Common/TLSServer.pm @@ -31,7 +31,7 @@ sub _initial_communication { else { $self->{write_func}("TLS MAYBE\n"); } - + return 1; } diff --git a/lib/Munin/Common/Timeout.pm b/lib/Munin/Common/Timeout.pm index 3772e7cbdc..c1ce8534b7 100644 --- a/lib/Munin/Common/Timeout.pm +++ b/lib/Munin/Common/Timeout.pm @@ -26,9 +26,9 @@ my $current_timeout_epoch; sub do_with_timeout { my ($timeout, $block) = @_; - croak 'Argument exception: $timeout' + croak 'Argument exception: $timeout' unless $timeout && $timeout =~ /^\d+$/; - croak 'Argument exception: $block' + croak 'Argument exception: $block' unless ref $block eq 'CODE'; my $new_timeout_epoch = time + $timeout; @@ -41,7 +41,7 @@ sub do_with_timeout { if ($new_timeout_epoch <= time) { # Yey ! Time's up already, don't do anything, just : "farewell !" - return undef; + return; } # Ok, going under new timeout setting @@ -75,7 +75,7 @@ sub do_with_timeout { # And handle the return code if ($err) { - return undef if $err eq "alarm\n"; + return if $err eq "alarm\n"; die $err; # Propagate any other exceptions } From 2273393cc5e6c602ea83717c3f83879a435fd1ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 20 Aug 2018 12:26:31 +0200 Subject: [PATCH 03/10] [perlcritic] fix lib/Munin/Master warnings --- Makefile | 4 ++-- lib/Munin/Master/Config.pm | 4 ++-- lib/Munin/Master/Graph.pm | 9 ++++++--- lib/Munin/Master/HTML.pm | 5 +++-- lib/Munin/Master/Host.pm | 2 +- lib/Munin/Master/LimitsOld.pm | 16 ++++++++-------- lib/Munin/Master/Node.pm | 21 +++++++++++---------- lib/Munin/Master/Update.pm | 4 ++-- lib/Munin/Master/UpdateWorker.pm | 15 ++++++++------- lib/Munin/Master/Utils.pm | 8 ++++---- 10 files changed, 47 insertions(+), 41 deletions(-) diff --git a/Makefile b/Makefile index 4a39095910..c0efa45b0c 100644 --- a/Makefile +++ b/Makefile @@ -57,8 +57,8 @@ install: $(BUILD_SCRIPT) #TODO: merge with lint target, when done .PHONY: perlcritic perlcritic: - #TODO: apply to scripts/ and lib/Munin/Master/ - perlcritic lib/Munin/Node lib/Munin/Plugin lib/Munin/Common + #TODO: apply to scripts/ + perlcritic lib/ .PHONY: lint lint: diff --git a/lib/Munin/Master/Config.pm b/lib/Munin/Master/Config.pm index 206cf9b3ea..240d407606 100644 --- a/lib/Munin/Master/Config.pm +++ b/lib/Munin/Master/Config.pm @@ -544,7 +544,7 @@ sub look_up { $value = $value->{groups}{$group}; } else { - return undef; + return; } } @@ -555,7 +555,7 @@ sub look_up { return $value->{hosts}{$host}; }; - return undef; + return; } diff --git a/lib/Munin/Master/Graph.pm b/lib/Munin/Master/Graph.pm index 433783a1b5..5f9d9c7844 100644 --- a/lib/Munin/Master/Graph.pm +++ b/lib/Munin/Master/Graph.pm @@ -26,6 +26,8 @@ use warnings; package Munin::Master::Graph; +use English qw(-no_match_vars); + use Time::HiRes; use POSIX; @@ -104,7 +106,7 @@ my %CONTENT_TYPES = ( sub is_ext_handled { my $ext = shift; - return undef unless $ext; + return unless $ext; return defined $CONTENT_TYPES{uc($ext)}; } @@ -612,7 +614,7 @@ sub handle_request { my $buffer; # No buffering wanted when sending the file - local $| = 1; + local $OUTPUT_AUTOFLUSH = 1; while (sysread($rrd_fh, $buffer, 40 * 1024)) { print $buffer; } } @@ -682,7 +684,7 @@ sub RRDs_graph { waitpid( $chld_pid, 0 ); - my $child_exit_status = ($? >> 8); + my $child_exit_status = ($CHILD_ERROR >> 8); return $child_exit_status; } @@ -776,6 +778,7 @@ sub RRDs_graph_or_dump { print $out_fh " \"columns\": " . (scalar @$columns) . ",\n"; print $out_fh " \"legend\": [\n"; my $index = 0; + ## no critic ControlStructures::ProhibitMutatingListFunctions my @json_columns = map { s/\\l$//; $_; } @{ $columns }; # Remove trailing "\l" for my $column ( @json_columns ) { print $out_fh " \"$column\""; diff --git a/lib/Munin/Master/HTML.pm b/lib/Munin/Master/HTML.pm index d851d09e6e..9ad933d68d 100755 --- a/lib/Munin/Master/HTML.pm +++ b/lib/Munin/Master/HTML.pm @@ -689,8 +689,9 @@ sub _get_params_services_for_comparison { my @nodes; $sth_node->execute($service_name, $grp_id); while (my ($node_name, $node_url, $srv_url, $srv_label) = $sth_node->fetchrow_array) { - my $_srv_url = "$srv_url.html" if defined $srv_url; - my $_img_url = "/$srv_url-$comparison.$graph_ext" if defined $srv_url; + my ($_srv_url, $_img_url); + $_srv_url = "$srv_url.html" if defined $srv_url; + $_img_url = "/$srv_url-$comparison.$graph_ext" if defined $srv_url; push @nodes, { R_PATH => '', NODENAME => $node_name, diff --git a/lib/Munin/Master/Host.pm b/lib/Munin/Master/Host.pm index 2494903ba8..7268e8e237 100644 --- a/lib/Munin/Master/Host.pm +++ b/lib/Munin/Master/Host.pm @@ -20,7 +20,7 @@ sub new { port => 4949, update => 1, use_node_name => 0, - + %$attributes, }; diff --git a/lib/Munin/Master/LimitsOld.pm b/lib/Munin/Master/LimitsOld.pm index a5ffb10d68..26f3cb3bf6 100644 --- a/lib/Munin/Master/LimitsOld.pm +++ b/lib/Munin/Master/LimitsOld.pm @@ -241,8 +241,8 @@ Options: # Get the host of the service in question sub get_host_node { - my $service = shift || return undef; - my $parent = munin_get_parent($service) || return undef; + my $service = shift || return; + my $parent = munin_get_parent($service) || return; if (munin_has_subservices($parent)) { return get_host_node($parent); @@ -265,7 +265,7 @@ sub get_notify_name { # Joined "sub-path" under host level sub get_full_service_name { - my $service = shift || return undef; + my $service = shift || return; my $parent = munin_get_parent($service); my $name = get_notify_name($service); @@ -279,7 +279,7 @@ sub get_full_service_name { # Joined group path above host level sub get_full_group_path { - my $group = shift || return undef; + my $group = shift || return; my $parent = munin_get_parent($group); my $name = get_notify_name($group); @@ -467,7 +467,7 @@ sub process_service { $hash->{'state_changed'} = 0; $state = $onfield->{"state"}; $extinfo = $onfield->{$state}; - + # Start counting the number of consecutive UNKNOWN # values seen. $num_unknowns = 1; @@ -649,9 +649,9 @@ sub generate_service_message { DEBUG "[DEBUG] generating service message: " . join('::', @{munin_get_node_loc($hash)}); - my $children = + my $children = munin_get_children( - munin_get_node(\%notes, + munin_get_node(\%notes, munin_get_node_loc($hash))); if ( defined($children) ) { @@ -783,7 +783,7 @@ sub generate_service_message { # See https://github.com/munin-monitoring/munin/issues/382 # and https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=291168. close(STDOUT); - exec($cmd) or WARN "[WARNING] Failed to exec for contact $c in pid $$"; + exec($cmd) or WARN "[WARNING] Failed to exec for contact $c in pid $PID"; exit; } } diff --git a/lib/Munin/Master/Node.pm b/lib/Munin/Master/Node.pm index 0d2fe9f313..c0256273b1 100644 --- a/lib/Munin/Master/Node.pm +++ b/lib/Munin/Master/Node.pm @@ -17,6 +17,7 @@ use Munin::Common::Logger; use Time::HiRes qw( gettimeofday tv_interval ); use IO::Socket::INET6; +use English qw(-no_match_vars); my $config = Munin::Master::Config->instance()->{config}; # Quick version, to enable "DEBUG ... if $debug" constructs @@ -85,7 +86,7 @@ sub _do_connect { PeerAddr => $uri->host, PeerPort => $self->{port} || 4949, LocalAddr => $config->{local_address}, - Proto => 'tcp', + Proto => 'tcp', MultiHomed => 1, Timeout => $config->{timeout} ); @@ -175,7 +176,7 @@ sub _run_starttls_if_required { read_func => sub { _node_read_single($self) }, tls_ca_cert => $config->{tls_ca_certificate}, tls_cert => $config->{tls_certificate}, - tls_paranoia => $tls_requirement, + tls_paranoia => $tls_requirement, tls_priv => $config->{tls_private_key}, tls_vdepth => $config->{tls_verify_depth}, tls_verify => $config->{tls_verify_certificate}, @@ -370,7 +371,7 @@ sub parse_service_config { $correct++; # Special case for dirtyconfig my ($ds_name, $value, $when) = ($1, $2, $now); - + $ds_name = $self->_sanitise_fieldname($ds_name); if ($value =~ /^(\d+):(.+)$/) { $when = $1; @@ -382,14 +383,14 @@ sub parse_service_config { $data_source_config->{$service}{$ds_name} ||= {}; $data_source_config->{$service}{$ds_name}{when} ||= []; $data_source_config->{$service}{$ds_name}{value} ||= []; - + # Saving the timed value in the datastructure push @{$data_source_config->{$service}{$ds_name}{when}}, $when; push @{$data_source_config->{$service}{$ds_name}{value}}, $value; } elsif ($line =~ m{\A ([^\.]+)\.([^\s]+) \s+ (.+?) \s* $}xms) { $correct++; - + my ($ds_name, $ds_var, $ds_val) = ($1, $2, $3); $ds_name = $self->_sanitise_fieldname($ds_name); $data_source_config->{$service}{$ds_name} ||= {}; @@ -578,7 +579,7 @@ sub parse_service_data { elsif ($line =~ m{\A ([^\.]+)\.extinfo \s+ (.+?) \s* $}xms) { # Extinfo is used in munin-limits my ($data_source, $value) = ($1, $2); - + $correct++; $data_source = $self->_sanitise_fieldname($data_source); @@ -595,7 +596,7 @@ sub parse_service_data { } } if ($errors) { - my $percent = ($errors / ($errors + $correct)) * 100; + my $percent = ($errors / ($errors + $correct)) * 100; $percent = sprintf("%.2f", $percent); WARN "[WARNING] $errors lines had errors while $correct lines were correct ($percent%) in data from 'fetch $plugin' on $nodedesignation"; } @@ -612,7 +613,7 @@ sub fetch_service_data { $self->_node_write_single("fetch $plugin\n"); my $lines = $self->_node_read($uw_handle_data); - + my $elapsed = tv_interval($t0); my $nodedesignation = $self->{host}."/".$self->{address}."/".$self->{port}; INFO "data: $elapsed sec for '$plugin' on $nodedesignation"; @@ -638,7 +639,7 @@ sub _sanitise_plugin_name { my ($self, $name) = @_; $name =~ s/[^_A-Za-z0-9]/_/g; - + return $name; } @@ -714,7 +715,7 @@ sub _node_read_fast { return _node_read(@_) if $self->{tls}; # Disable Buffering here, to be able to use sysread() - local $| = 1; + local $OUTPUT_AUTOFLUSH = 1; my $io_src = $self->{reader}; my $buf; diff --git a/lib/Munin/Master/Update.pm b/lib/Munin/Master/Update.pm index 688052a987..81820d54a7 100644 --- a/lib/Munin/Master/Update.pm +++ b/lib/Munin/Master/Update.pm @@ -131,7 +131,7 @@ sub _do_with_lock_and_timing { if (!open ($self->{STATS}, '>', "$config->{dbdir}/munin-update.stats.tmp")) { WARN "[WARNING] Could not open STATS to $config->{dbdir}/munin-update.stats.tmp: $!"; # Use /dev/null instead - if the admin won't fix he won't care - open($self->{STATS}, '>', "/dev/null") or + open($self->{STATS}, '>', "/dev/null") or LOGCROAK "[FATAL] Could not open STATS to /dev/null (fallback for not being able to open $config->{dbdir}/munin-update.stats.tmp): $!"; } @@ -221,7 +221,7 @@ sub _handle_worker_result { LOGCROAK("[FATAL] Handle_worker_result got handed a failed worker result"); } - my ($worker_id, $time_used, $service_configs) + my ($worker_id, $time_used, $service_configs) = ($res->[0], $res->[1]{time_used}, $res->[1]{service_configs}); my $update_time = sprintf("%.2f", $time_used); diff --git a/lib/Munin/Master/UpdateWorker.pm b/lib/Munin/Master/UpdateWorker.pm index 64b4e04025..5748735558 100644 --- a/lib/Munin/Master/UpdateWorker.pm +++ b/lib/Munin/Master/UpdateWorker.pm @@ -85,7 +85,7 @@ sub do_work { # Having a local handle looks easier my $node = $self->{node}; - INFO "[INFO] starting work in $$ for $nodedesignation.\n"; + INFO "[INFO] starting work in $PID for $nodedesignation.\n"; my $done = $node->do_in_session(sub { # A I/O timeout results in a violent exit. Catch and handle. @@ -221,7 +221,7 @@ FETCH_OK: }); # do_in_session # This handles failure in do_in_session, - return undef if ! $done || ! $done->{exit_value}; + return if ! $done || ! $done->{exit_value}; return { time_used => Time::HiRes::time - $update_time, @@ -675,7 +675,8 @@ sub uw_handle_config { # Delegate the FETCH part my $update_rate = "300"; # XXX - should use the correct version - my $timestamp = $self->uw_handle_fetch($plugin, $now, $update_rate, \@fetch_data) if (@fetch_data); + my $timestamp; + $timestamp = $self->uw_handle_fetch($plugin, $now, $update_rate, \@fetch_data) if (@fetch_data); $last_timestamp = $timestamp if $timestamp && $timestamp > $last_timestamp; $self->{dbh}->commit() unless $self->{dbh}->{AutoCommit}; @@ -842,7 +843,7 @@ sub get_config_for_service { } # Not found - return undef; + return; } @@ -1154,11 +1155,11 @@ sub convert_to_float sub dump_to_file { my ($filename, $obj) = @_; - open(DUMPFILE, ">> $filename"); + open(my $DUMPFILE, q{>>}, "$filename"); - print DUMPFILE Dumper($obj); + print $DUMPFILE Dumper($obj); - close(DUMPFILE); + close($DUMPFILE); } sub _get_default_address diff --git a/lib/Munin/Master/Utils.pm b/lib/Munin/Master/Utils.pm index b48245ccc2..cff5eb2583 100644 --- a/lib/Munin/Master/Utils.pm +++ b/lib/Munin/Master/Utils.pm @@ -109,9 +109,9 @@ sub munin_getlock { my $pid = ; if (defined($pid)) { - + DEBUG "[DEBUG] Lock contained pid '$pid'"; - + # Make sure it's a proper pid if ($pid =~ /^(\d+)$/ and $1 != 1) { $pid = $1; @@ -129,8 +129,8 @@ sub munin_getlock { seek(LOCK, 0, 0); } DEBUG "[DEBUG] Writing out PID to lock file $lockname"; - print LOCK $$; # we want the pid inside for later use - if (defined($pid) && length $$ < length $pid) { + print LOCK $PID; # we want the pid inside for later use + if (defined($pid) && length $PID < length $pid) { # Since pid was defined we need to truncate in case len($) < len($pid) truncate(LOCK, tell(LOCK)) } From 1e5357d8fe673d82bf641349356198f2ec38559c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 20 Aug 2018 12:18:08 +0200 Subject: [PATCH 04/10] [perlcritic] fix script/ warnings --- Makefile | 3 +-- script/munin-async | 13 +++++++------ script/munin-asyncd | 31 ++++++++++++++++--------------- script/munin-httpd | 8 ++++---- script/munin-node | 2 ++ script/munin-node-configure | 7 +++++-- script/munin-run | 2 ++ script/munin-update | 3 ++- 8 files changed, 39 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index c0efa45b0c..580230d124 100644 --- a/Makefile +++ b/Makefile @@ -57,8 +57,7 @@ install: $(BUILD_SCRIPT) #TODO: merge with lint target, when done .PHONY: perlcritic perlcritic: - #TODO: apply to scripts/ - perlcritic lib/ + perlcritic lib/ script/ .PHONY: lint lint: diff --git a/script/munin-async b/script/munin-async index 4d20f461dc..e8f1ce8081 100755 --- a/script/munin-async +++ b/script/munin-async @@ -20,6 +20,7 @@ use strict; use warnings; +use English qw(-no_match_vars); use Sys::Hostname; use Data::Dumper; use Getopt::Long; @@ -32,7 +33,7 @@ use Munin::Common::Logger; use Munin::Common::Utils qw( is_valid_hostname ); # Disable buffering -$| = 1; +$OUTPUT_AUTOFLUSH = 1; my $SPOOLDIR = $Munin::Common::Defaults::MUNIN_SPOOLDIR; my $hostname; @@ -141,14 +142,14 @@ sub cleanup { sub cat_file { my $filename = shift; return if ! -r $filename; - - open(FILE, "$filename"); - while() { + + open(my $file, '<', "$filename"); + while(<$file>) { # remove line starting with . next if m/^\./; - print $_; + print $_; } - close(FILE); + close($file); } __END__ diff --git a/script/munin-asyncd b/script/munin-asyncd index 556447a45a..72201a9a57 100755 --- a/script/munin-asyncd +++ b/script/munin-asyncd @@ -20,6 +20,7 @@ use strict; use warnings; +use English qw(-no_match_vars); use IO::Socket; use IO::File; use File::Path qw(mkpath); @@ -85,7 +86,7 @@ $minrate = $update_rate if ! defined $minrate; $verbose = 1 if $debug; unless (-d $SPOOLDIR) { - mkpath($SPOOLDIR, { verbose => $verbose, } ) + mkpath($SPOOLDIR, { verbose => $verbose, } ) or LOGCROAK("Cannot create '$SPOOLDIR': $!"); } @@ -129,11 +130,11 @@ my $process_name = "main"; my $plugins = {}; { - INFO("[$$][$process_name] Reading config from $host"); - my $sock = new IO::Socket::INET( - PeerAddr => "$host", + INFO("[$PID][$process_name] Reading config from $host"); + my $sock = new IO::Socket::INET( + PeerAddr => "$host", Proto => 'tcp' - ) || die "Error creating socket: $!"; + ) || die "Error creating socket: $!"; local $0 = "munin-asyncd [$metahostname] [list]"; DEBUG("[sock][>] cap multigraph dirtyconfig"); @@ -206,7 +207,7 @@ MAIN: while($keepgoing) { $when_next = $should_be_next; } - DEBUG("[$$][$process_name] $plugin: should_have_been $should_have_been (" . + DEBUG("[$PID][$process_name] $plugin: should_have_been $should_have_been (" . localtime($should_have_been) . "), should_be_next: $should_be_next (" . localtime($should_be_next) . @@ -249,10 +250,10 @@ MAIN: while($keepgoing) { if ($sock) { if ( $sock->connected ) { - print STDERR "[$$][$process_name][>] quit\n" if $verbose; + print STDERR "[$PID][$process_name][>] quit\n" if $verbose; print $sock "quit\n" ; } - print STDERR "[$$][$process_name] closing sock\n" if $verbose; + print STDERR "[$PID][$process_name] closing sock\n" if $verbose; $sock = undef; } @@ -266,14 +267,14 @@ MAIN: while($keepgoing) { my $sleep_sec = $when_next - time; if ($sleep_sec > 0) { - INFO("[$$][$process_name] Sleeping $sleep_sec sec"); + INFO("[$PID][$process_name] Sleeping $sleep_sec sec"); sleep $sleep_sec; } else { - INFO("[$$][$process_name] Already late : should sleep $sleep_sec sec\n"); + INFO("[$PID][$process_name] Already late : should sleep $sleep_sec sec\n"); } } -print STDERR "[$$][$process_name] Exiting\n" if $verbose; +print STDERR "[$PID][$process_name] Exiting\n" if $verbose; sub fetch_data { @@ -283,9 +284,9 @@ sub fetch_data my $sock = shift; - print STDERR "[$$][$process_name][>][$plugin] asking for config\n" if $verbose; + print STDERR "[$PID][$process_name][>][$plugin] asking for config\n" if $verbose; - print STDERR "[$$][$process_name][>][$plugin][sock] config $plugin\n" if $debug; + print STDERR "[$PID][$process_name][>][$plugin][sock] config $plugin\n" if $debug; print $sock "config $plugin\n"; my $is_dirtyconfig; @@ -294,7 +295,7 @@ sub fetch_data while(my $line = <$sock>) { chomp($line); - print STDERR "[$$][$process_name][<][$plugin][sock] $line\n" if $debug; + print STDERR "[$PID][$process_name][<][$plugin][sock] $line\n" if $debug; if ($line =~ m/^\./) { # Starting with . => end @@ -321,7 +322,7 @@ sub fetch_data # if dirty config, bypass the "fetch" part goto WRITE_SPOOL if $is_dirtyconfig; - INFO("[$$][$process_name][>][$plugin] asking for data\n"); + INFO("[$PID][$process_name][>][$plugin] asking for data\n"); DEBUG("[sock][>][$plugin] fetch $plugin\n"); print $sock "fetch $plugin\n"; diff --git a/script/munin-httpd b/script/munin-httpd index bd96bfa34c..401d6b1588 100755 --- a/script/munin-httpd +++ b/script/munin-httpd @@ -24,14 +24,14 @@ along with this program. If not, see . =cut +use strict; +use warnings; + # Trust PERL5LIB from environment use lib map { /(.*)/ } split(/:/, ($ENV{PERL5LIB} || '')); package Munin::Master::Http; -use strict; -use warnings; - use HTTP::Server::Simple::CGI::PreFork; use base qw(HTTP::Server::Simple::CGI::PreFork); @@ -56,7 +56,7 @@ sub handle_request Munin::Master::Graph::handle_request($cgi); } else { Munin::Master::HTML::handle_request($cgi); - } + } } package main; diff --git a/script/munin-node b/script/munin-node index d96f84d588..81aab6e03f 100755 --- a/script/munin-node +++ b/script/munin-node @@ -37,6 +37,8 @@ use Munin::Node::OS; use Munin::Node::Service; use Munin::Node::Server; +use English qw(-no_match_vars); + my $servicedir = "$Munin::Common::Defaults::MUNIN_CONFDIR/plugins"; my $sconfdir = "$Munin::Common::Defaults::MUNIN_CONFDIR/plugin-conf.d"; my $conffile = "$Munin::Common::Defaults::MUNIN_CONFDIR/munin-node.conf"; diff --git a/script/munin-node-configure b/script/munin-node-configure index 9666c897ae..c981564ad5 100755 --- a/script/munin-node-configure +++ b/script/munin-node-configure @@ -24,6 +24,8 @@ use Munin::Common::Defaults; use Munin::Node::Configure::PluginList; use Munin::Node::Configure::Debug; +use English qw(-no_match_vars); + use Munin::Node::Config; my $config = Munin::Node::Config->instance(); @@ -136,7 +138,8 @@ sub parse_args # comma-delimited form @snmp_hosts = map { split /,/ } @snmp_hosts; - my $snmp = init_snmp( + my $snmp; + $snmp = init_snmp( hosts => \@snmp_hosts, version => $snmpver, port => $snmpport, @@ -314,7 +317,7 @@ sub init_snmp { unless (eval { require Munin::Node::SNMPConfig; }) { die "# ERROR: Cannot perform SNMP probing as Munin::Node::SNMPConfig module is not available.\n", - $@; + $EVAL_ERROR; } return Munin::Node::SNMPConfig->new(@_); } diff --git a/script/munin-run b/script/munin-run index 3dc37f45fb..d3fc4dbcb2 100755 --- a/script/munin-run +++ b/script/munin-run @@ -35,6 +35,8 @@ use Munin::Node::Config; use Munin::Node::OS; use Munin::Node::Service; +use English qw(-no_match_vars); + my $services; my $servicedir; my $conffile = "$Munin::Common::Defaults::MUNIN_CONFDIR/munin-node.conf"; diff --git a/script/munin-update b/script/munin-update index eedd93b4c9..f4b1613182 100755 --- a/script/munin-update +++ b/script/munin-update @@ -61,6 +61,7 @@ sub configure { my @files = grep { ! /^\.|~$/ } readdir($DIR); closedir($DIR); + ## no critic ControlStructures::ProhibitMutatingListFunctions @files = map { $_ = $dirname.'/'.$_; } (sort @files); foreach my $f (@files) { @@ -84,7 +85,7 @@ sub parse_args { ); GetOptions ( - \%args, + \%args, "config|config_file=s", "debug", "verbose", From 584db4ae956ff21572d0f89fdef990d727613c46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 20 Aug 2018 12:30:51 +0200 Subject: [PATCH 05/10] [perlcritic] fix warnings in generated file --- lib/Munin/Common/Defaults.pm.PL | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Munin/Common/Defaults.pm.PL b/lib/Munin/Common/Defaults.pm.PL index a79e8c9a39..c1101ba224 100644 --- a/lib/Munin/Common/Defaults.pm.PL +++ b/lib/Munin/Common/Defaults.pm.PL @@ -54,9 +54,9 @@ our \$MUNIN_SPOOLDIR = '$MUNIN_SPOOLDIR'; # our \$MUNIN_MANDIR = ''; our \$MUNIN_LOGDIR = '$MUNIN_LOGDIR'; our \$MUNIN_STATEDIR = '$MUNIN_STATEDIR'; -our \$MUNIN_USER = \$^O eq 'MSWin32' ? '' : getpwuid \$EUID; -our \$MUNIN_GROUP = \$^O eq 'MSWin32' ? '' : getgrgid \$EGID; -our \$MUNIN_PLUGINUSER = \$^O eq 'MSWin32' ? '' : getpwuid \$EUID; +our \$MUNIN_USER = \$OSNAME eq 'MSWin32' ? '' : getpwuid \$EUID; +our \$MUNIN_GROUP = \$OSNAME eq 'MSWin32' ? '' : getgrgid \$EGID; +our \$MUNIN_PLUGINUSER = \$OSNAME eq 'MSWin32' ? '' : getpwuid \$EUID; our \$MUNIN_VERSION = '$MUNIN_VERSION'; our \$MUNIN_PERL = '/usr/bin/perl'; # our \$MUNIN_PERLLIB = ''; From 6dfc047b2c4b8bf1be554b917abd9a275f26e037 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 20 Aug 2018 14:06:13 +0200 Subject: [PATCH 06/10] [perlcritic] fix some more warnings --- .perlcriticrc | 20 +++++++++++++ lib/Munin/Common/TLS.pm | 2 +- lib/Munin/Common/TLSClient.pm | 2 +- lib/Munin/Common/TLSServer.pm | 2 +- lib/Munin/Master/Graph.pm | 28 ++---------------- lib/Munin/Master/HTML.pm | 2 +- lib/Munin/Master/LimitsOld.pm | 5 ++-- lib/Munin/Master/UpdateWorker.pm | 1 - lib/Munin/Master/Utils.pm | 49 ++++++++++++++++---------------- lib/Munin/Node/Config.pm | 2 +- lib/Munin/Plugin.pm | 20 +++++++------ lib/Munin/Plugin/Pgsql.pm | 2 +- script/munin-update | 2 +- 13 files changed, 67 insertions(+), 70 deletions(-) diff --git a/.perlcriticrc b/.perlcriticrc index 1294b4476b..b37f68e29f 100644 --- a/.perlcriticrc +++ b/.perlcriticrc @@ -24,3 +24,23 @@ perltidyrc = perltidyrc [CodeLayout::ProhibitTrailingWhitespace] severity = 5 +[CodeLayout::ProhibitQuotedWordLists] +severity = 5 + +[CodeLayout::RequireTrailingCommas] +severity = 5 + +[ControlStructures::ProhibitUnreachableCode] +severity = 5 + +[Documentation::RequirePackageMatchesPodName] +severity = 5 + +[Miscellanea::ProhibitUnrestrictedNoCritic] +severity = 5 + +[TestingAndDebugging::ProhibitNoWarnings] +severity = 5 + +[Variables::ProhibitUnusedVariables] +severity = 5 diff --git a/lib/Munin/Common/TLS.pm b/lib/Munin/Common/TLS.pm index 54d8d7532a..fa5a083ddd 100644 --- a/lib/Munin/Common/TLS.pm +++ b/lib/Munin/Common/TLS.pm @@ -413,7 +413,7 @@ __END__ =head1 NAME -Munin::Node::TLS - Abstract base class implementing the STARTTLS protocol +Munin::Common::TLS - Abstract base class implementing the STARTTLS protocol =head1 SYNOPSIS diff --git a/lib/Munin/Common/TLSClient.pm b/lib/Munin/Common/TLSClient.pm index 53b8d83506..432b8e62ff 100644 --- a/lib/Munin/Common/TLSClient.pm +++ b/lib/Munin/Common/TLSClient.pm @@ -67,7 +67,7 @@ __END__ =head1 NAME -Munin::Node::TLSClient - Implements the client side of the STARTTLS protocol +Munin::Common::TLSClient - Implements the client side of the STARTTLS protocol =head1 SYNOPSIS diff --git a/lib/Munin/Common/TLSServer.pm b/lib/Munin/Common/TLSServer.pm index daaeb411f5..0b508dcf22 100644 --- a/lib/Munin/Common/TLSServer.pm +++ b/lib/Munin/Common/TLSServer.pm @@ -50,7 +50,7 @@ __END__ =head1 NAME -Munin::Node::TLSServer - Implements the server side of the STARTTLS protocol +Munin::Common::TLSServer - Implements the server side of the STARTTLS protocol =head1 SYNOPSIS diff --git a/lib/Munin/Master/Graph.pm b/lib/Munin/Master/Graph.pm index 5f9d9c7844..53ace56cba 100644 --- a/lib/Munin/Master/Graph.pm +++ b/lib/Munin/Master/Graph.pm @@ -45,7 +45,6 @@ my %PALETTE; my @COLOUR; { - no warnings; # This is the old munin palette. Note that it lacks contrast. $PALETTE{'old'} = [ qw(22ff22 0022ff ff0000 00aaaa ff00ff @@ -87,7 +86,7 @@ my %resolutions = ( "day" => "300", "week" => "1500", "month" => "7200", - "year" => "86400" + "year" => "86400", ); my %CONTENT_TYPES = ( @@ -273,8 +272,6 @@ sub handle_request my @rrd_legend; my @rrd_sum; - my %negatives; - push @rrd_gfx, "COMMENT:\\t"; push @rrd_gfx, "COMMENT:Cur\\t"; push @rrd_gfx, "COMMENT:Min\\t"; @@ -666,27 +663,6 @@ sub RRDs_graph { # when called the second time. # return RRDs::graph(@_); - - use IPC::Open3; - use IO::String; - - # We just revert to spawning a full featured rrdtool cmd for now. - my $chld_out = new IO::String(); - my $chld_in = new IO::String(); - my $chld_err = new IO::String(); - - local $ENV{PATH} = $1 if $ENV{PATH} =~ /(.*)/; - - my $chld_pid = open3($chld_out, $chld_in, $chld_err, "rrdtool", "graphv", @_); - - DEBUG "[DEBUG] RRDs_graph(chld_out=".${$chld_out->string_ref}.")"; - DEBUG "[DEBUG] RRDs_graph(chld_err=".${$chld_err->string_ref}.")"; - - waitpid( $chld_pid, 0 ); - - my $child_exit_status = ($CHILD_ERROR >> 8); - - return $child_exit_status; } sub RRDs_graph_or_dump { @@ -778,7 +754,7 @@ sub RRDs_graph_or_dump { print $out_fh " \"columns\": " . (scalar @$columns) . ",\n"; print $out_fh " \"legend\": [\n"; my $index = 0; - ## no critic ControlStructures::ProhibitMutatingListFunctions + ## no critic qw(ControlStructures::ProhibitMutatingListFunctions) my @json_columns = map { s/\\l$//; $_; } @{ $columns }; # Remove trailing "\l" for my $column ( @json_columns ) { print $out_fh " \"$column\""; diff --git a/lib/Munin/Master/HTML.pm b/lib/Munin/Master/HTML.pm index 9ad933d68d..e5b15ea581 100755 --- a/lib/Munin/Master/HTML.pm +++ b/lib/Munin/Master/HTML.pm @@ -115,7 +115,7 @@ sub handle_request MUNIN_VERSION => $Munin::Common::Defaults::MUNIN_VERSION, TIMESTAMP => strftime("%Y-%m-%d %T%z (%Z)", localtime), R_PATH => '', - GRAPH_EXT => $graph_ext + GRAPH_EXT => $graph_ext, ); diff --git a/lib/Munin/Master/LimitsOld.pm b/lib/Munin/Master/LimitsOld.pm index 26f3cb3bf6..1969983a9a 100644 --- a/lib/Munin/Master/LimitsOld.pm +++ b/lib/Munin/Master/LimitsOld.pm @@ -71,7 +71,7 @@ my %default_text = ( "nagios" => '${var:host}\t${var:graph_title}\t${var:worstid}\t${strtrunc:350 ${if:cfields CRITICALs:${loop<,>:cfields ${var:label} is ${var:value} (outside range [${var:crange}])${if:extinfo : ${var:extinfo}}}.}${if:wfields WARNINGs:${loop<,>:wfields ${var:label} is ${var:value} (outside range [${var:wrange}])${if:extinfo : ${var:extinfo}}}.}${if:ufields UNKNOWNs:${loop<,>:ufields ${var:label} is ${var:value}${if:extinfo : ${var:extinfo}}}.}${if:fofields OKs:${loop<,>:fofields ${var:label} is ${var:value}${if:extinfo : ${var:extinfo}}}.}}', "old-nagios" => - '${var:host}\t${var:plugin}\t${var:worstid}\t${strtrunc:350 ${var:graph_title}:${if:cfields CRITICALs:${loop<,>:cfields ${var:label} is ${var:value} (outside range [${var:crange}])${if:extinfo : ${var:extinfo}}}.}${if:wfields WARNINGs:${loop<,>:wfields ${var:label} is ${var:value} (outside range [${var:wrange}])${if:extinfo : ${var:extinfo}}}.}${if:ufields UNKNOWNs:${loop<,>:ufields ${var:label} is ${var:value}${if:extinfo : ${var:extinfo}}}.}${if:fofields OKs:${loop<,>:fofields ${var:label} is ${var:value}${if:extinfo : ${var:extinfo}}}.}}' + '${var:host}\t${var:plugin}\t${var:worstid}\t${strtrunc:350 ${var:graph_title}:${if:cfields CRITICALs:${loop<,>:cfields ${var:label} is ${var:value} (outside range [${var:crange}])${if:extinfo : ${var:extinfo}}}.}${if:wfields WARNINGs:${loop<,>:wfields ${var:label} is ${var:value} (outside range [${var:wrange}])${if:extinfo : ${var:extinfo}}}.}${if:ufields UNKNOWNs:${loop<,>:ufields ${var:label} is ${var:value}${if:extinfo : ${var:extinfo}}}.}${if:fofields OKs:${loop<,>:fofields ${var:label} is ${var:value}${if:extinfo : ${var:extinfo}}}.}}', ); sub limits_startup { @@ -642,7 +642,8 @@ sub generate_service_message { 'warning' => [], 'unknown' => [], 'foks' => [], - 'ok' => []); + 'ok' => [], + ); my $contacts = munin_get_children(munin_get_node($config, ["contact"])); diff --git a/lib/Munin/Master/UpdateWorker.pm b/lib/Munin/Master/UpdateWorker.pm index 5748735558..b3d9a57dfd 100644 --- a/lib/Munin/Master/UpdateWorker.pm +++ b/lib/Munin/Master/UpdateWorker.pm @@ -500,7 +500,6 @@ sub _db_state_update { $sth_state->finish(); { - no warnings; DEBUG "_db_state_update.last_epoch:$last_epoch"; DEBUG "_db_state_update.last_value:$last_value"; } diff --git a/lib/Munin/Master/Utils.pm b/lib/Munin/Master/Utils.pm index cff5eb2583..4712fe5bc1 100644 --- a/lib/Munin/Master/Utils.pm +++ b/lib/Munin/Master/Utils.pm @@ -25,24 +25,24 @@ use Scalar::Util qw(isweak weaken); our (@ISA, @EXPORT); @ISA = ('Exporter'); -@EXPORT = ( - 'munin_removelock', - 'munin_runlock', - 'munin_getlock', - 'munin_get_bool', - 'munin_get', - 'munin_get_rrd_filename', - 'munin_get_node_name', - 'munin_get_node_loc', - 'munin_get_node', - 'munin_set_var_loc', - 'munin_set', - 'munin_mkdir_p', - 'munin_find_field_for_limits', - 'munin_get_children', - 'munin_has_subservices', - 'print_version_and_exit', - 'exit_if_run_by_super_user', +@EXPORT = qw( + munin_removelock + munin_runlock + munin_getlock + munin_get_bool + munin_get + munin_get_rrd_filename + munin_get_node_name + munin_get_node_loc + munin_get_node + munin_set_var_loc + munin_set + munin_mkdir_p + munin_find_field_for_limits + munin_get_children + munin_has_subservices + print_version_and_exit + exit_if_run_by_super_user ); my $VERSION = $Munin::Common::Defaults::MUNIN_VERSION; @@ -99,7 +99,6 @@ sub munin_runlock { sub munin_getlock { my ($lockname) = @_; - my $LOCK; if (sysopen (LOCK, $lockname, O_RDWR | O_CREAT)) { DEBUG "[DEBUG] Create/open lock : $lockname succeeded\n"; @@ -242,7 +241,7 @@ Returns: Get all child hash nodes. -Parameters: +Parameters: - $hash: A hash ref to the parent node Returns: @@ -266,7 +265,7 @@ Returns: Get location array for hash node. -Parameters: +Parameters: - $hash: A ref to the node Returns: @@ -278,7 +277,7 @@ Returns: Return the name of the hash node supplied. -Parameters: +Parameters: - $hash: A ref to the hash node Returns: @@ -351,7 +350,7 @@ to it. Returns a loc array from a path string. -Parameters: +Parameters: - $path: A path string Returns: @@ -371,7 +370,7 @@ Returns: Sets a variable in a hash. -Parameters: +Parameters: - $hash: A ref to the hash to set the variable in - $var: The name of the variable - $val: The value to set the variable to @@ -385,7 +384,7 @@ Returns: Sets a variable in a hash. -Parameters: +Parameters: - $hash: A ref to the hash to set the variable in - $loc: A ref to an array with the full path of the variable - $val: The value to set the variable to diff --git a/lib/Munin/Node/Config.pm b/lib/Munin/Node/Config.pm index 90eea326c8..ea203bffbc 100644 --- a/lib/Munin/Node/Config.pm +++ b/lib/Munin/Node/Config.pm @@ -268,7 +268,7 @@ sub _parse_plugin_line { elsif ($var_name eq 'command') { # Don't split on escaped whitespace. Also support escaping the escape character. # Better implementations welcome :). - ## no critic ControlStructures::ProhibitMutatingListFunctions + ## no critic qw(ControlStructures::ProhibitMutatingListFunctions) return (command => [reverse map {s/\\(.)/$1/g; scalar reverse} split /\s+(?=(?:\\\\)*(?!\\))/, reverse $var_value]); } elsif ($var_name eq 'host_name') { diff --git a/lib/Munin/Plugin.pm b/lib/Munin/Plugin.pm index 06bb1bd10c..7cc5d2fbff 100644 --- a/lib/Munin/Plugin.pm +++ b/lib/Munin/Plugin.pm @@ -28,7 +28,7 @@ use File::Temp; # File::Temp was first released with perl 5.006001 # This file uses subroutine prototypes. This is considered a bad # practice according to PBP (see page 194). -## no critic Prototypes +## no critic qw(Prototypes) =head1 NAME @@ -56,6 +56,7 @@ set_state_name, save_state, restore_state, tail_open, tail_close. =cut +use English qw(-no_match_vars); use Exporter; our @ISA = ('Exporter'); our @EXPORT = qw( @@ -303,7 +304,7 @@ sub restore_state { my @state; # Protects _restore_state_raw() with an eval() eval { @state = _restore_state_raw(); }; - if ($@) { @state = (); warn $@; } + if ($EVAL_ERROR) { @state = (); warn $EVAL_ERROR; } return _decode_state(@state); } @@ -317,7 +318,7 @@ sub _restore_state_raw { } # Read a state vector from a plugin appropriate state file - local $/; + local $INPUT_RECORD_SEPARATOR; my @state = split(/\n/, <$STATE>); my $filemagic = shift(@state); @@ -395,7 +396,7 @@ these percentages against $base. sub adjust_threshold { my ($threshold, $base) = @_; - return undef if(!defined $threshold or !defined $base); + return if(!defined $threshold or !defined $base); $threshold =~ s!(\d+\.?\d*)%!$1*$base/100!eg; @@ -462,8 +463,8 @@ the kernel exposes. sub readfile($) { my ($path) = @_; - open my $FH, "<", $path or return undef; - local $/; + open my $FH, "<", $path or return; + local $INPUT_RECORD_SEPARATOR; my $content = <$FH>; close $FH; @@ -485,7 +486,7 @@ Returns an empty array if the file is empty (or contains only whitespace). sub readarray($) { my ($path) = @_; - open my $FH, "<", $path or return undef; + open my $FH, "<", $path or return; my $line = <$FH>; # handle an empty file gracefully $line = "" if not defined($line); @@ -556,7 +557,7 @@ sub scaleNumber { 1E+9, 'G', # giga 1E+6, 'M', # mega 1E+3, 'k', # kilo - 1, ''); # nothing + 1, '',); # nothing my %small = (1, '', # nothing 1E-3, 'm', # milli @@ -566,7 +567,7 @@ sub scaleNumber { 1E-15, 'f', # femto 1E-18, 'a', # atto 1E-21, 'z', # zepto - 1E-24, 'y'); # yocto + 1E-24, 'y',);# yocto # Get the absolute and exaggerate it slightly since floating point # numbers don't compare very well. @@ -612,6 +613,7 @@ if it doesn't support multigraph plugins. sub need_multigraph { return if $ENV{MUNIN_CAP_MULTIGRAPH}; + ## no critic qw(InputOutput::ProhibitInteractiveTest) if (-t and (!$ARGV[0] or ($ARGV[0] eq 'config'))) { # Catch people running the plugin on the command line. Note diff --git a/lib/Munin/Plugin/Pgsql.pm b/lib/Munin/Plugin/Pgsql.pm index 21fc57695b..0eb62cfb27 100644 --- a/lib/Munin/Plugin/Pgsql.pm +++ b/lib/Munin/Plugin/Pgsql.pm @@ -223,7 +223,7 @@ sub new { base => 1000, category => 'PostgreSQL', graphdraw => 'LINE1', - graphtype => 'GAUGE' + graphtype => 'GAUGE', ); my $self = { diff --git a/script/munin-update b/script/munin-update index f4b1613182..d8c1fe8a0e 100755 --- a/script/munin-update +++ b/script/munin-update @@ -61,7 +61,7 @@ sub configure { my @files = grep { ! /^\.|~$/ } readdir($DIR); closedir($DIR); - ## no critic ControlStructures::ProhibitMutatingListFunctions + ## no critic qw(ControlStructures::ProhibitMutatingListFunctions) @files = map { $_ = $dirname.'/'.$_; } (sort @files); foreach my $f (@files) { From 5a1b8ba04b66d39174d64a4c2e6853c7cb047a4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 20 Aug 2018 14:21:16 +0200 Subject: [PATCH 07/10] [perlcritic] merge make target with lint --- Makefile | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 580230d124..9047fa7f8d 100644 --- a/Makefile +++ b/Makefile @@ -54,13 +54,11 @@ install: $(BUILD_SCRIPT) -e "$$(perl -I lib -M"Munin::Common::Defaults" \ -e "Munin::Common::Defaults->print_as_sed_substitutions();")" -#TODO: merge with lint target, when done -.PHONY: perlcritic -perlcritic: - perlcritic lib/ script/ - .PHONY: lint lint: + # Scanning munin code + perlcritic lib/ script/ + @# SC1008: ignore our weird shebang (substituted later) @# SC1090: ignore sourcing of files with variable in path @# SC2009: do not complain about "ps ... | grep" calls (may be platform specific) From 8d882187bdc01c434d7f5060e82f7f335c1368b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 20 Aug 2018 21:11:47 +0200 Subject: [PATCH 08/10] [perlcritic] allow usage of $0 --- .perlcriticrc | 2 +- lib/Munin/Node/Server.pm | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.perlcriticrc b/.perlcriticrc index b37f68e29f..479b3d3632 100644 --- a/.perlcriticrc +++ b/.perlcriticrc @@ -16,7 +16,7 @@ profile-strictness = quiet [Variables::ProhibitPunctuationVars] severity = 5 -allow = $_ $! +allow = $_ $! $0 [CodeLayout::RequireTidyCode] perltidyrc = perltidyrc diff --git a/lib/Munin/Node/Server.pm b/lib/Munin/Node/Server.pm index ca8b8b15de..053249f28a 100644 --- a/lib/Munin/Node/Server.pm +++ b/lib/Munin/Node/Server.pm @@ -120,7 +120,7 @@ sub process_request $session->{tls_mode} = $config->{tls} || 'auto'; $session->{peer_address} = $self->{server}->{peeraddr}; - $PROGRAM_NAME .= " [$session->{peer_address}]"; + $0 .= " [$session->{peer_address}]"; # Used to provide per-master state-files $ENV{MUNIN_MASTER_IP} = $session->{peer_address}; @@ -216,7 +216,7 @@ sub _process_command_line { sub _get_commandline { my $self = shift; - my $script = $PROGRAM_NAME; + my $script = $0; # make relative path absolute $script = $ENV{'PWD'} .'/'. $script if $script =~ m|^[^/]+/| && $ENV{'PWD'}; # untaint for later use in hup From 39b4ecb4d450de5356986eff419b591f549c3d7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 20 Aug 2018 21:18:43 +0200 Subject: [PATCH 09/10] [perlcritic] allow usage of $@ --- .perlcriticrc | 2 +- HACKING.pod | 2 +- lib/Munin/Common/Config.pm | 4 ++-- lib/Munin/Common/TLS.pm | 2 +- lib/Munin/Common/Timeout.pm | 2 +- lib/Munin/Master/Config.pm | 4 ++-- lib/Munin/Master/Update.pm | 4 ++-- lib/Munin/Master/UpdateWorker.pm | 6 +++--- lib/Munin/Master/Utils.pm | 2 +- lib/Munin/Node/Config.pm | 4 ++-- lib/Munin/Node/Server.pm | 6 +++--- lib/Munin/Node/Service.pm | 4 ++-- lib/Munin/Plugin.pm | 2 +- script/munin-node-configure | 2 +- 14 files changed, 23 insertions(+), 23 deletions(-) diff --git a/.perlcriticrc b/.perlcriticrc index 479b3d3632..969e74e975 100644 --- a/.perlcriticrc +++ b/.perlcriticrc @@ -16,7 +16,7 @@ profile-strictness = quiet [Variables::ProhibitPunctuationVars] severity = 5 -allow = $_ $! $0 +allow = $_ $! $0 $@ [CodeLayout::RequireTidyCode] perltidyrc = perltidyrc diff --git a/HACKING.pod b/HACKING.pod index e4abd805fb..db07673e50 100644 --- a/HACKING.pod +++ b/HACKING.pod @@ -145,7 +145,7 @@ Exceptions are caught with an eval: eval { # Exceptionally scary code }; - if ($EVAL_ERROR) { + if ($@) { # Handle exception } diff --git a/lib/Munin/Common/Config.pm b/lib/Munin/Common/Config.pm index 119bc30a2a..65e0118072 100644 --- a/lib/Munin/Common/Config.pm +++ b/lib/Munin/Common/Config.pm @@ -177,8 +177,8 @@ sub parse_config_from_file { eval { $self->parse_config($file); }; - if ($EVAL_ERROR) { - croak "ERROR: Failed to parse config file '$config_file': $EVAL_ERROR"; + if ($@) { + croak "ERROR: Failed to parse config file '$config_file': $@"; } close $file diff --git a/lib/Munin/Common/TLS.pm b/lib/Munin/Common/TLS.pm index fa5a083ddd..e9c35a71ee 100644 --- a/lib/Munin/Common/TLS.pm +++ b/lib/Munin/Common/TLS.pm @@ -103,7 +103,7 @@ sub _load_net_ssleay { eval { require Net::SSLeay; }; - if ($EVAL_ERROR) { + if ($@) { ERROR("TLS enabled but Net::SSLeay unavailable."); return 0; } diff --git a/lib/Munin/Common/Timeout.pm b/lib/Munin/Common/Timeout.pm index c1ce8534b7..6b0074a507 100644 --- a/lib/Munin/Common/Timeout.pm +++ b/lib/Munin/Common/Timeout.pm @@ -54,7 +54,7 @@ sub do_with_timeout { alarm ($new_timeout_epoch - time); $ret_value = $block->(); }; - my $err = $EVAL_ERROR; + my $err = $@; # Restore the old $current_timeout_epoch... $current_timeout_epoch = $old_current_timeout_epoch; diff --git a/lib/Munin/Master/Config.pm b/lib/Munin/Master/Config.pm index 240d407606..d0980dbb2e 100644 --- a/lib/Munin/Master/Config.pm +++ b/lib/Munin/Master/Config.pm @@ -377,9 +377,9 @@ sub _concat_config_line_ok { eval { $self->_split_config_line_ok($longkey); }; - if ($EVAL_ERROR) { + if ($@) { # _split_config_line_ok already logged the problem. - my $err_msg = "[ERROR] config error under [$prefix] for '$key $value' : $EVAL_ERROR"; + my $err_msg = "[ERROR] config error under [$prefix] for '$key $value' : $@"; ERROR $err_msg; die $err_msg; } diff --git a/lib/Munin/Master/Update.pm b/lib/Munin/Master/Update.pm index 81820d54a7..939952825b 100644 --- a/lib/Munin/Master/Update.pm +++ b/lib/Munin/Master/Update.pm @@ -193,11 +193,11 @@ sub _run_workers { $worker->{dbh_state}->disconnect(); my $worker_id = $worker->{ID}; - if (! defined($res) || $EVAL_ERROR) { + if (! defined($res) || $@) { # No res, something went wrong # Note that we handle connection failure same as other # failures. Since "do_connect()" fails only softly. - INFO "[INFO]: no connection or EVAL_ERROR:$EVAL_ERROR"; + INFO "[INFO]: no connection or EVAL_ERROR:$@"; $pm->finish(1, [ $worker_id ] ); } diff --git a/lib/Munin/Master/UpdateWorker.pm b/lib/Munin/Master/UpdateWorker.pm index b3d9a57dfd..18627323e9 100644 --- a/lib/Munin/Master/UpdateWorker.pm +++ b/lib/Munin/Master/UpdateWorker.pm @@ -204,12 +204,12 @@ NODE_END: kill 'KILL', $node_pid; # Using SIGKILL, since normal termination didn't happen } - if ($EVAL_ERROR =~ m/^NO_SPOOLFETCH_DATA /) { + if ($@ =~ m/^NO_SPOOLFETCH_DATA /) { INFO "[INFO] No spoofetch data for $nodedesignation"; return; - } elsif ($EVAL_ERROR) { + } elsif ($@) { ERROR "[ERROR] Error in node communication with $nodedesignation: " - .$EVAL_ERROR; + .$@; return; } diff --git a/lib/Munin/Master/Utils.pm b/lib/Munin/Master/Utils.pm index 4712fe5bc1..368b8c0b91 100644 --- a/lib/Munin/Master/Utils.pm +++ b/lib/Munin/Master/Utils.pm @@ -143,7 +143,7 @@ sub munin_mkdir_p { eval { mkpath($dirname, 0, $umask); }; - return if $EVAL_ERROR; + return if $@; return 1; } diff --git a/lib/Munin/Node/Config.pm b/lib/Munin/Node/Config.pm index ea203bffbc..717df639d6 100644 --- a/lib/Munin/Node/Config.pm +++ b/lib/Munin/Node/Config.pm @@ -198,10 +198,10 @@ sub parse_plugin_config_file { if $self->{DEBUG}; eval { $self->parse_plugin_config($CONF) }; - if ($EVAL_ERROR) { + if ($@) { carp sprintf( '%s at %s line %d. Skipping the rest of the file', - $EVAL_ERROR, + $@, $file, $INPUT_LINE_NUMBER, ); diff --git a/lib/Munin/Node/Server.pm b/lib/Munin/Node/Server.pm index 053249f28a..74c0812c9d 100644 --- a/lib/Munin/Node/Server.pm +++ b/lib/Munin/Node/Server.pm @@ -145,7 +145,7 @@ sub process_request }); }; - ERROR($EVAL_ERROR) if ($EVAL_ERROR); + ERROR($@) if ($@); ERROR("Node side timeout while processing: '$line'") if ($timed_out); return; @@ -196,8 +196,8 @@ sub _process_command_line { eval { $session->{tls_started} = _process_starttls_command($session); }; - if ($EVAL_ERROR) { - ERROR($EVAL_ERROR); + if ($@) { + ERROR($@); return 0; } DEBUG ('DEBUG: Returned from starttls.') if $config->{DEBUG}; diff --git a/lib/Munin/Node/Service.pm b/lib/Munin/Node/Service.pm index 5dbcc69cc5..5a71cc3a6f 100644 --- a/lib/Munin/Node/Service.pm +++ b/lib/Munin/Node/Service.pm @@ -223,8 +223,8 @@ sub change_real_and_effective_user_and_group Munin::Node::OS->set_effective_user_id($uid) unless $uid == $root_uid; }; - if ($EVAL_ERROR) { - CRITICAL("# FATAL: Plugin '$service' Can't drop privileges: $EVAL_ERROR."); + if ($@) { + CRITICAL("# FATAL: Plugin '$service' Can't drop privileges: $@."); exit 1; } } diff --git a/lib/Munin/Plugin.pm b/lib/Munin/Plugin.pm index 7cc5d2fbff..89e136d8b1 100644 --- a/lib/Munin/Plugin.pm +++ b/lib/Munin/Plugin.pm @@ -304,7 +304,7 @@ sub restore_state { my @state; # Protects _restore_state_raw() with an eval() eval { @state = _restore_state_raw(); }; - if ($EVAL_ERROR) { @state = (); warn $EVAL_ERROR; } + if ($@) { @state = (); warn $@; } return _decode_state(@state); } diff --git a/script/munin-node-configure b/script/munin-node-configure index c981564ad5..21b713c95b 100755 --- a/script/munin-node-configure +++ b/script/munin-node-configure @@ -317,7 +317,7 @@ sub init_snmp { unless (eval { require Munin::Node::SNMPConfig; }) { die "# ERROR: Cannot perform SNMP probing as Munin::Node::SNMPConfig module is not available.\n", - $EVAL_ERROR; + $@; } return Munin::Node::SNMPConfig->new(@_); } From c9d904c91397b197e8e15f3aa795a66ba3d1cbe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 20 Aug 2018 21:20:15 +0200 Subject: [PATCH 10/10] [perlcritic] allow usage of $$ --- .perlcriticrc | 2 +- lib/Munin/Common/Logger.pm | 4 +--- lib/Munin/Master/LimitsOld.pm | 2 +- lib/Munin/Master/UpdateWorker.pm | 2 +- lib/Munin/Master/Utils.pm | 4 ++-- script/munin-asyncd | 22 +++++++++++----------- 6 files changed, 17 insertions(+), 19 deletions(-) diff --git a/.perlcriticrc b/.perlcriticrc index 969e74e975..ea6efc689a 100644 --- a/.perlcriticrc +++ b/.perlcriticrc @@ -16,7 +16,7 @@ profile-strictness = quiet [Variables::ProhibitPunctuationVars] severity = 5 -allow = $_ $! $0 $@ +allow = $_ $! $0 $@ $$ [CodeLayout::RequireTidyCode] perltidyrc = perltidyrc diff --git a/lib/Munin/Common/Logger.pm b/lib/Munin/Common/Logger.pm index 2bb2d5132b..2ff0ce5e0f 100644 --- a/lib/Munin/Common/Logger.pm +++ b/lib/Munin/Common/Logger.pm @@ -20,8 +20,6 @@ our @EXPORT use Params::Validate qw(validate SCALAR); use POSIX; -use English qw(-no_match_vars); - sub _program_name { my @path = split( '/', $0 ); return $path[-1]; @@ -49,7 +47,7 @@ my $screen_format = sub { chomp $message; - return sprintf( "%s [%s][%06d]: %s\n", _timestamp, $level, $PID, $message ); + return sprintf( "%s [%s][%06d]: %s\n", _timestamp, $level, $$, $message ); }; my $file_format = $screen_format; diff --git a/lib/Munin/Master/LimitsOld.pm b/lib/Munin/Master/LimitsOld.pm index 1969983a9a..ccd9c46dd7 100644 --- a/lib/Munin/Master/LimitsOld.pm +++ b/lib/Munin/Master/LimitsOld.pm @@ -784,7 +784,7 @@ sub generate_service_message { # See https://github.com/munin-monitoring/munin/issues/382 # and https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=291168. close(STDOUT); - exec($cmd) or WARN "[WARNING] Failed to exec for contact $c in pid $PID"; + exec($cmd) or WARN "[WARNING] Failed to exec for contact $c in pid $$"; exit; } } diff --git a/lib/Munin/Master/UpdateWorker.pm b/lib/Munin/Master/UpdateWorker.pm index 18627323e9..2652a549b9 100644 --- a/lib/Munin/Master/UpdateWorker.pm +++ b/lib/Munin/Master/UpdateWorker.pm @@ -85,7 +85,7 @@ sub do_work { # Having a local handle looks easier my $node = $self->{node}; - INFO "[INFO] starting work in $PID for $nodedesignation.\n"; + INFO "[INFO] starting work in $$ for $nodedesignation.\n"; my $done = $node->do_in_session(sub { # A I/O timeout results in a violent exit. Catch and handle. diff --git a/lib/Munin/Master/Utils.pm b/lib/Munin/Master/Utils.pm index 368b8c0b91..48fd9324f4 100644 --- a/lib/Munin/Master/Utils.pm +++ b/lib/Munin/Master/Utils.pm @@ -128,8 +128,8 @@ sub munin_getlock { seek(LOCK, 0, 0); } DEBUG "[DEBUG] Writing out PID to lock file $lockname"; - print LOCK $PID; # we want the pid inside for later use - if (defined($pid) && length $PID < length $pid) { + print LOCK $$; # we want the pid inside for later use + if (defined($pid) && length $$ < length $pid) { # Since pid was defined we need to truncate in case len($) < len($pid) truncate(LOCK, tell(LOCK)) } diff --git a/script/munin-asyncd b/script/munin-asyncd index 72201a9a57..cf834340ed 100755 --- a/script/munin-asyncd +++ b/script/munin-asyncd @@ -130,7 +130,7 @@ my $process_name = "main"; my $plugins = {}; { - INFO("[$PID][$process_name] Reading config from $host"); + INFO("[$$][$process_name] Reading config from $host"); my $sock = new IO::Socket::INET( PeerAddr => "$host", Proto => 'tcp' @@ -207,7 +207,7 @@ MAIN: while($keepgoing) { $when_next = $should_be_next; } - DEBUG("[$PID][$process_name] $plugin: should_have_been $should_have_been (" . + DEBUG("[$$][$process_name] $plugin: should_have_been $should_have_been (" . localtime($should_have_been) . "), should_be_next: $should_be_next (" . localtime($should_be_next) . @@ -250,10 +250,10 @@ MAIN: while($keepgoing) { if ($sock) { if ( $sock->connected ) { - print STDERR "[$PID][$process_name][>] quit\n" if $verbose; + print STDERR "[$$][$process_name][>] quit\n" if $verbose; print $sock "quit\n" ; } - print STDERR "[$PID][$process_name] closing sock\n" if $verbose; + print STDERR "[$$][$process_name] closing sock\n" if $verbose; $sock = undef; } @@ -267,14 +267,14 @@ MAIN: while($keepgoing) { my $sleep_sec = $when_next - time; if ($sleep_sec > 0) { - INFO("[$PID][$process_name] Sleeping $sleep_sec sec"); + INFO("[$$][$process_name] Sleeping $sleep_sec sec"); sleep $sleep_sec; } else { - INFO("[$PID][$process_name] Already late : should sleep $sleep_sec sec\n"); + INFO("[$$][$process_name] Already late : should sleep $sleep_sec sec\n"); } } -print STDERR "[$PID][$process_name] Exiting\n" if $verbose; +print STDERR "[$$][$process_name] Exiting\n" if $verbose; sub fetch_data { @@ -284,9 +284,9 @@ sub fetch_data my $sock = shift; - print STDERR "[$PID][$process_name][>][$plugin] asking for config\n" if $verbose; + print STDERR "[$$][$process_name][>][$plugin] asking for config\n" if $verbose; - print STDERR "[$PID][$process_name][>][$plugin][sock] config $plugin\n" if $debug; + print STDERR "[$$][$process_name][>][$plugin][sock] config $plugin\n" if $debug; print $sock "config $plugin\n"; my $is_dirtyconfig; @@ -295,7 +295,7 @@ sub fetch_data while(my $line = <$sock>) { chomp($line); - print STDERR "[$PID][$process_name][<][$plugin][sock] $line\n" if $debug; + print STDERR "[$$][$process_name][<][$plugin][sock] $line\n" if $debug; if ($line =~ m/^\./) { # Starting with . => end @@ -322,7 +322,7 @@ sub fetch_data # if dirty config, bypass the "fetch" part goto WRITE_SPOOL if $is_dirtyconfig; - INFO("[$PID][$process_name][>][$plugin] asking for data\n"); + INFO("[$$][$process_name][>][$plugin] asking for data\n"); DEBUG("[sock][>][$plugin] fetch $plugin\n"); print $sock "fetch $plugin\n";