since smartctl uses the return value to encode
disk health status (such as failure in the past)
we cannot die there, but have to parse the returncode
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
my $smartdata = {};
my $datastarted = 0;
my $smartdata = {};
my $datastarted = 0;
- run_command([$SMARTCTL, '-a', '-f', 'brief', $disk], outfunc => sub{
+ $returncode = run_command([$SMARTCTL, '-a', '-f', 'brief', $disk], noerr => 1, outfunc => sub{
my ($line) = @_;
if ($datastarted && $line =~ m/^[ \d]{2}\d/) {
my ($line) = @_;
if ($datastarted && $line =~ m/^[ \d]{2}\d/) {
- die "Error getting S.M.A.R.T. data: $@\n" if $@;
+ my $err = $@;
+
+ # bit 0 and 1 mark an severe smartctl error
+ # all others are for disk status, so ignore them
+ # see smartctl(8)
+ if ((defined($returncode) && ($returncode & 0b00000011)) || $err) {
+ die "Error getting S.M.A.R.T. data: Exit code: $returncode\n";
+ }
$smartdata->{health} = 'UNKOWN' if !defined $smartdata->{health};
return $smartdata;
}
$smartdata->{health} = 'UNKOWN' if !defined $smartdata->{health};
return $smartdata;
}
my $message = "UNKOWN";
eval {
my $message = "UNKOWN";
eval {
- run_command([$SMARTCTL, '-H', $disk], outfunc => sub {
+ run_command([$SMARTCTL, '-H', $disk], noerr => 1, outfunc => sub {
my ($line) = @_;
if ($line =~ m/test result: (.*)$/) {
my ($line) = @_;
if ($line =~ m/test result: (.*)$/) {