From 454696e4a10c256a0a260ed3193a616497939122 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 27 Mar 2014 21:00:19 +0100 Subject: [PATCH] Fix #5389 --- apps/hddtemp/mode/listdrives.pm | 15 +++++++++++++-- apps/hddtemp/mode/temperature.pm | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/apps/hddtemp/mode/listdrives.pm b/apps/hddtemp/mode/listdrives.pm index d67e5ace7..9527d0928 100644 --- a/apps/hddtemp/mode/listdrives.pm +++ b/apps/hddtemp/mode/listdrives.pm @@ -89,10 +89,21 @@ sub manage_selection { #|/dev/sda|SD280813AS|35|C|#|/dev/sdb|ST2000CD005-1CH134|35|C| - my $_ = <$oSocketConn>; + my $line; + + eval { + local $SIG{ALRM} = sub { die "Timeout by signal ALARM\n"; }; + alarm(10); + $line = <$oSocketConn>; + alarm(0); + }; $oSocketConn->shutdown(2); + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot get informations."); + $self->{output}->option_exit(); + } - while (m/\|([^|]+)\|([^|]+)\|([^|]+)\|(C|F)\|/g) { + while ($line =~ /\|([^|]+)\|([^|]+)\|([^|]+)\|(C|F)\|/g) { my ($drive, $serial, $temperature, $unit) = ($1, $2, $3, $4); next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && diff --git a/apps/hddtemp/mode/temperature.pm b/apps/hddtemp/mode/temperature.pm index 9533a8bc2..dbaeace69 100644 --- a/apps/hddtemp/mode/temperature.pm +++ b/apps/hddtemp/mode/temperature.pm @@ -99,10 +99,21 @@ sub manage_selection { #|/dev/sda|SD280813AS|35|C|#|/dev/sdb|ST2000CD005-1CH134|35|C| - my $_ = <$oSocketConn>; + my $line; + + eval { + local $SIG{ALRM} = sub { die "Timeout by signal ALARM\n"; }; + alarm(10); + $line = <$oSocketConn>; + alarm(0); + }; $oSocketConn->shutdown(2); + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot get informations."); + $self->{output}->option_exit(); + } - while (m/\|([^|]+)\|([^|]+)\|([^|]+)\|(C|F)\|/g) { + while ($line =~ /\|([^|]+)\|([^|]+)\|([^|]+)\|(C|F)\|/g) { my ($drive, $serial, $temperature, $unit) = ($1, $2, $3, $4); next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi})