summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Rothenberg <rrwo@cpan.org>2020-03-30 11:47:35 +0100
committerRobert Rothenberg <rrwo@cpan.org>2020-03-30 11:47:35 +0100
commit4d97d5d12f2072ea786b83cdbf9cd0d1bb86dd46 (patch)
treea4c31df7e5b94556641578ef83c17843c7e37ffe
parent0b0c12c6886478108f56f245882e8f2b5aeee28f (diff)
Improve error checking for uptime
-rw-r--r--README.md2
-rw-r--r--lib/Sys/CpuLoad.pm1
2 files changed, 3 insertions, 0 deletions
diff --git a/README.md b/README.md
index a940d59..cb8a9ef 100644
--- a/README.md
+++ b/README.md
@@ -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 );