From 7a93955ce7b6414114b80fcaf804f6c0f61013d2 Mon Sep 17 00:00:00 2001 From: Ferenc Erki Date: Sat, 2 Nov 2024 23:42:34 +0100 Subject: [PATCH] Fix memory detection warnings on Solaris --- ChangeLog | 1 + lib/Rex/Hardware/Memory.pm | 38 ++++++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 64a7674da..b5c998723 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ Revision history for Rex [BUG FIXES] - Fix precedence warning after perl-5.41.4 - Fix missing argument warnings from Text::Wrap + - Fix memory detection warnings on Solaris [DOCUMENTATION] diff --git a/lib/Rex/Hardware/Memory.pm b/lib/Rex/Hardware/Memory.pm index a4f75b10d..6f6030773 100644 --- a/lib/Rex/Hardware/Memory.pm +++ b/lib/Rex/Hardware/Memory.pm @@ -9,6 +9,7 @@ use warnings; our $VERSION = '9999.99.99_99'; # VERSION +use English qw(-no_match_vars); use Rex::Hardware::Host; use Rex::Commands::Run; use Rex::Helper::Run; @@ -54,25 +55,34 @@ sub get { elsif ( $os eq "SunOS" ) { my @data = i_run "echo ::memstat | mdb -k", fail_ok => 1; - my ($free_cache) = map { /\D+\d+\s+(\d+)/ } grep { /^Free \(cache/ } @data; - my ($free_list) = map { /\D+\d+\s+(\d+)/ } grep { /^Free \(freel/ } @data; - my ($page_cache) = map { /\s+\d+\s+(\d+)/ } grep { /^Page cache/ } @data; + if ( $CHILD_ERROR == 0 ) { + my ($free_cache) = + map { /\D+\d+\s+(\d+)/ } grep { /^Free \(cache/ } @data; + my ($free_list) = map { /\D+\d+\s+(\d+)/ } grep { /^Free \(freel/ } @data; + my ($page_cache) = map { /\s+\d+\s+(\d+)/ } grep { /^Page cache/ } @data; - my $free = $free_cache + $free_list; + my $free = $free_cache + $free_list; #my ($total, $total_e) = grep { $_=$1 if /^Memory Size: (\d+) ([a-z])/i } i_run "prtconf"; - my ($total) = map { /\s+\d+\s+(\d+)/ } grep { /^Total/ } @data; + my ($total) = map { /\s+\d+\s+(\d+)/ } grep { /^Total/ } @data; - &$convert( $free, "M" ); - &$convert( $total, "M" ); - my $used = $total - $free; - - $data = { - used => $used, - total => $total, - free => $free, - }; + &$convert( $free, "M" ); + &$convert( $total, "M" ); + my $used = $total - $free; + $data = { + used => $used, + total => $total, + free => $free, + }; + } + else { + $data = { + used => 0, + total => 0, + free => 0, + }; + } } elsif ( $os eq "OpenBSD" ) { my $mem_str = i_run "top -d1 | grep Memory:", fail_ok => 1;