From 7bb7b9719acbdb7eeb8a2d9e1a22d5a06460255a Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Sun, 7 Dec 2014 10:57:35 -0800 Subject: [PATCH] Strict and warnings compliance --- system-status/enable-collection.pl | 8 +++-- system-status/postinstall.pl | 3 ++ system-status/system-status-lib.pl | 49 ++++++++++++++++++------------ system-status/systeminfo.pl | 2 ++ 4 files changed, 41 insertions(+), 21 deletions(-) diff --git a/system-status/enable-collection.pl b/system-status/enable-collection.pl index 01b2b1b1c..203f4f5ca 100755 --- a/system-status/enable-collection.pl +++ b/system-status/enable-collection.pl @@ -1,9 +1,13 @@ #!/usr/local/bin/perl # Command-line script to enable status collection -$no_acl_check++; +use strict; +use warnings; +$main::no_acl_check++; +our (%config); require 'system-status-lib.pl'; -$ARGV[0] eq 'none' || $ARGV[0] =~ /^[1-9][0-9]*$/ && $ARGV[0] <= 60 || +my $zero = @ARGV ? $ARGV[0] : ''; +$zero eq 'none' || $zero =~ /^[1-9][0-9]*$/ && $zero <= 60 || die "usage: enable-collection.pl none|"; $config{'collect_interval'} = $ARGV[0]; diff --git a/system-status/postinstall.pl b/system-status/postinstall.pl index 58dde8429..e2fab1b1f 100755 --- a/system-status/postinstall.pl +++ b/system-status/postinstall.pl @@ -1,5 +1,8 @@ +use strict; +use warnings; require 'system-status-lib.pl'; +our ($module_config_directory, $module_name); sub module_install { diff --git a/system-status/system-status-lib.pl b/system-status/system-status-lib.pl index 5ea6340f6..c65c8569e 100755 --- a/system-status/system-status-lib.pl +++ b/system-status/system-status-lib.pl @@ -1,11 +1,15 @@ # Functions for collecting general system info +use strict; +use warnings; BEGIN { push(@INC, ".."); }; eval "use WebminCore;"; &init_config(); -$systeminfo_cron_cmd = "$module_config_directory/systeminfo.pl"; -$collected_info_file = "$module_config_directory/info"; -$historic_info_dir = "$module_config_directory/history"; +our ($module_config_directory, %config, %gconfig, $module_name, + $no_log_file_changes); +our $systeminfo_cron_cmd = "$module_config_directory/systeminfo.pl"; +our $collected_info_file = "$module_config_directory/info"; +our $historic_info_dir = "$module_config_directory/history"; # collect_system_info() # Returns a hash reference containing system information @@ -63,10 +67,10 @@ $info->{'drivetemps'} = \@drive if (@drive); # IO input and output if ($gconfig{'os_type'} =~ /-linux$/) { - local $out = &backquote_command("vmstat 1 2 2>/dev/null"); + my $out = &backquote_command("vmstat 1 2 2>/dev/null"); if (!$?) { - local @lines = split(/\r?\n/, $out); - local @w = split(/\s+/, $lines[$#lines]); + my @lines = split(/\r?\n/, $out); + my @w = split(/\s+/, $lines[$#lines]); shift(@w) if ($w[0] eq ''); if ($w[8] =~ /^\d+$/ && $w[9] =~ /^\d+$/) { # Blocks in and out @@ -101,9 +105,10 @@ return &collect_system_info(); sub save_collected_info { my ($info) = @_; -&open_tempfile(INFO, ">$collected_info_file"); -&print_tempfile(INFO, &serialise_variable($info)); -&close_tempfile(INFO); +my $fh = "INFO"; +&open_tempfile($fh, ">$collected_info_file"); +&print_tempfile($fh, &serialise_variable($info)); +&close_tempfile($fh); } # refresh_possible_packages(&newpackages) @@ -156,6 +161,7 @@ if (&foreign_check("net") && $gconfig{'os_type'} =~ /-linux$/) { # Get the current byte count my $rxtotal = 0; my $txtotal = 0; + my @ifaces; if ($config{'collect_ifaces'}) { # From module config @ifaces = split(/\s+/, $config{'collect_ifaces'}); @@ -164,7 +170,8 @@ if (&foreign_check("net") && $gconfig{'os_type'} =~ /-linux$/) { # Get list from net module &foreign_require("net"); foreach my $i (&net::active_interfaces()) { - if ($i->{'virtual'} eq '' && + my $v = defined($i->{'virtual'}) ? $i->{'virtual'} : ''; + if ($v eq '' && $i->{'name'} =~ /^(eth|ppp|wlan|ath|wlan)/) { push(@ifaces, $i->{'name'}); } @@ -184,6 +191,7 @@ if (&foreign_check("net") && $gconfig{'os_type'} =~ /-linux$/) { # Work out the diff since the last run, if we have it my %netcounts; + my $now = time(); if (&read_file("$historic_info_dir/netcounts", \%netcounts) && $netcounts{'rx'} && $netcounts{'tx'} && $netcounts{'ifaces'} eq $ifaces && @@ -222,13 +230,13 @@ if ($temptotal) { } # Get CPU temperature -my ($temptotal, $tempcount); +my ($ctemptotal, $ctempcount); foreach my $t (@{$info->{'cputemps'}}) { - $temptotal += $t->{'temp'}; - $tempcount++; + $ctemptotal += $t->{'temp'}; + $ctempcount++; } -if ($temptotal) { - push(@stats, [ "cputemp", $temptotal / $tempcount ]); +if ($ctemptotal) { + push(@stats, [ "cputemp", $ctemptotal / $ctempcount ]); } # Get IO blocks @@ -296,6 +304,7 @@ return @rv; sub list_all_historic_collected_info { my ($start, $end) = @_; +my %all; foreach my $f (&list_historic_stats()) { my @rv = &list_historic_collected_info($f, $start, $end); $all{$f} = \@rv; @@ -323,6 +332,7 @@ my $first = ; $first || return (undef, undef); chop($first); my ($firsttime, $firstvalue) = split(" ", $first); +my $last; seek(HISTORY, 2, -256) || seek(HISTORY, 0, 0); while() { $last = $_; @@ -408,8 +418,9 @@ sub get_current_cpu_temps my @rv; if (!$config{'collect_notemp'} && $gconfig{'os_type'} =~ /-linux$/ && &has_command("sensors")) { - &open_execute_command(SENSORS, "sensors /dev/null", 1); - while() { + my $fh = "SENSORS"; + &open_execute_command($fh, "sensors /dev/null", 1); + while(<$fh>) { if (/Core\s+(\d+):\s+([\+\-][0-9\.]+)/) { push(@rv, { 'core' => $1, 'temp' => $2 }); @@ -419,7 +430,7 @@ if (!$config{'collect_notemp'} && 'temp' => $1 }); } } - close(SENSORS); + close($fh); } return @rv; } @@ -444,7 +455,7 @@ $WebminCore::gconfig{'logfullfiles'} = 0; $no_log_file_changes = 1; &lock_file($collected_info_file); -$info = &collect_system_info(); +my $info = &collect_system_info(); if ($info) { &save_collected_info($info); &add_historic_collected_info($info, $start); diff --git a/system-status/systeminfo.pl b/system-status/systeminfo.pl index 61f704c92..b100003ac 100755 --- a/system-status/systeminfo.pl +++ b/system-status/systeminfo.pl @@ -2,6 +2,8 @@ # Collect various pieces of general system information, for display by themes # on their status pages. Run every 5 mins from Cron. +use strict; +use warnings; package system_status; $main::no_acl_check++; require './system-status-lib.pl';