diff options
author | Robert Rothenberg <rrwo@cpan.org> | 2020-03-30 11:47:35 +0100 |
---|---|---|
committer | Robert Rothenberg <rrwo@cpan.org> | 2020-03-30 11:47:35 +0100 |
commit | 4d97d5d12f2072ea786b83cdbf9cd0d1bb86dd46 (patch) | |
tree | a4c31df7e5b94556641578ef83c17843c7e37ffe | |
parent | 0b0c12c6886478108f56f245882e8f2b5aeee28f (diff) |
Improve error checking for uptime
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | lib/Sys/CpuLoad.pm | 1 |
2 files changed, 3 insertions, 0 deletions
@@ -71,6 +71,8 @@ As of v0.24, you can override the executable path by setting ```perl use Sys::CpuLoad 'uptime'; +no warnings 'once'; + $Sys::CpuLoad::UPTIME = '/usr/bin/w'; @load = uptime(); diff --git a/lib/Sys/CpuLoad.pm b/lib/Sys/CpuLoad.pm index c964b67..2953d8d 100644 --- a/lib/Sys/CpuLoad.pm +++ b/lib/Sys/CpuLoad.pm @@ -120,6 +120,7 @@ sub uptime { return undef; ## no critic (ProhibitExplicitReturnUndef) run3($UPTIME, \undef, \my $line); + return undef if $? || !defined($line); ## no critic (ProhibitExplicitReturnUndef) if ( $line =~ /(\d+\.\d+)\s*,?\s+(\d+\.\d+)\s*,?\s+(\d+\.\d+)\s*$/m ) { return ( $1, $2, $3 ); |