From f2e8f390b9e2da1258a4ec8cf08a576173232fc1 Mon Sep 17 00:00:00 2001
From: chrfranke <chrfranke@4ea69e1a-61f1-4043-bf83-b5c94c648137>
Date: Mon, 18 Jan 2010 20:57:39 +0000
Subject: [PATCH] smartd: Fix directive '-l selftest' (ticket #36).

git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@3040 4ea69e1a-61f1-4043-bf83-b5c94c648137
---
 smartmontools/CHANGELOG   |  3 +++
 smartmontools/NEWS        |  1 +
 smartmontools/atacmds.cpp | 16 ++++++++++------
 3 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/smartmontools/CHANGELOG b/smartmontools/CHANGELOG
index 7e01ffac4..9fa0bae84 100644
--- a/smartmontools/CHANGELOG
+++ b/smartmontools/CHANGELOG
@@ -43,6 +43,9 @@ NOTES FOR FUTURE RELEASES: see TODO file.
 
 <DEVELOPERS: ADDITIONS TO THE CHANGE LOG GO JUST BELOW HERE, PLEASE>
 
+  [CF] smartd: Fix directive '-l selftest' (ticket #36)
+       Regression was introduced with r2773.
+
   [CF] smartd: Don't disable attribute tracking if read thresholds fails.
        Windows: Don't return dummy thresholds if IOCTL_STORAGE_QUERY_PROPERTY
        or 3ware CLI is used to read SMART data.
diff --git a/smartmontools/NEWS b/smartmontools/NEWS
index ea4601fa3..baff25624 100644
--- a/smartmontools/NEWS
+++ b/smartmontools/NEWS
@@ -13,6 +13,7 @@ Summary: smartmontools release 5.40
 - Drive database is in a separate source file 'drivedb.h'
   which can be downloaded from SVN.
 - Fix regression in smartctl option '-q, --quietmode'.
+- Fix regression in smartd directive '-l selftest'.
 
 Date 2009-12-09
 Summary: smartmontools release 5.39 (UNSTABLE/EXPERIMENTAL)
diff --git a/smartmontools/atacmds.cpp b/smartmontools/atacmds.cpp
index 745a4d55d..1abc9f9e8 100644
--- a/smartmontools/atacmds.cpp
+++ b/smartmontools/atacmds.cpp
@@ -2404,13 +2404,17 @@ int ataPrintSmartSelfTestlog(const ata_smart_selftestlog * data, bool allentries
       uint64_t lba48 = (log->lbafirstfailure < 0xffffffff ? log->lbafirstfailure : 0xffffffffffffULL);
 
       // Print entry
-      bool errorfound = ataPrintSmartSelfTestEntry(testno,
-        log->selftestnumber, log->selfteststatus, log->timestamp,
-        lba48, !allentries, noheaderprinted);
+      if (ataPrintSmartSelfTestEntry(testno,
+            log->selftestnumber, log->selfteststatus,
+            log->timestamp, lba48, !allentries, noheaderprinted)) {
 
-      // keep track of time of most recent error
-      if (errorfound && !hours)
-        hours=log->timestamp;
+        // Self-test showed an error
+        retval++;
+
+        // keep track of time of most recent error
+        if (!hours)
+          hours = log->timestamp;
+      }
     }
   }
   if (!allentries && retval)
-- 
GitLab