From 6962da4fe4b9920ad5a1083a9c93310d86bc1ba7 Mon Sep 17 00:00:00 2001 From: Andreas Bachlechner <62039342+bachandi@users.noreply.github.com> Date: Mon, 11 Oct 2021 17:17:28 +0200 Subject: [PATCH] Fix nan handling of alternative temperature sources. --- lib/disk.pm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/disk.pm b/lib/disk.pm index a50e04d..56253b9 100644 --- a/lib/disk.pm +++ b/lib/disk.pm @@ -29,6 +29,8 @@ use File::Basename; use Exporter 'import'; our @EXPORT = qw(disk_init disk_update disk_cgi); +sub isnan { ! defined( $_[0] <=> (0+"inf")) } + sub disk_init { my $myself = (caller(0))[3]; my ($package, $config, $debug) = @_; @@ -229,7 +231,7 @@ sub disk_update { } if(/^190/ && /Airflow_Temperature_Cel/) { my @tmp = split(' ', $_); - $temp = $tmp[9] unless $temp; + $temp = $tmp[9] unless ($temp && !isnan($temp)); chomp($temp); } if(/^197/ && /Current_Pending_Sector/) { @@ -239,12 +241,12 @@ sub disk_update { } if(/^Current Drive Temperature: /) { my @tmp = split(' ', $_); - $temp = $tmp[3] unless $temp; + $temp = $tmp[3] unless ($temp && !isnan($temp)); chomp($temp); } if(/^Temperature: /) { my @tmp = split(' ', $_); - $temp = $tmp[1] unless $temp; + $temp = $tmp[1] unless ($temp && !isnan($temp)); chomp($temp); } }