From 163fcffaace032cc511a85eb1dcf5947207fb809 Mon Sep 17 00:00:00 2001
From: chrfranke <chrfranke@4ea69e1a-61f1-4043-bf83-b5c94c648137>
Date: Fri, 16 Apr 2010 07:05:46 +0000
Subject: [PATCH] smartd '-l selftest' directive: Print info if error count
 decreased. Avoid misleading warning if error count decreased to zero (ticket
 #67).

git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@3082 4ea69e1a-61f1-4043-bf83-b5c94c648137
---
 smartmontools/CHANGELOG  |  4 ++++
 smartmontools/smartd.cpp | 10 ++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/smartmontools/CHANGELOG b/smartmontools/CHANGELOG
index 5cbad8d0c..d99985df9 100644
--- a/smartmontools/CHANGELOG
+++ b/smartmontools/CHANGELOG
@@ -43,6 +43,10 @@ NOTES FOR FUTURE RELEASES: see TODO file.
 
 <DEVELOPERS: ADDITIONS TO THE CHANGE LOG GO JUST BELOW HERE, PLEASE>
 
+  [CF] smartd '-l selftest' directive: Print info if error count
+       decreased.  Avoid misleading warning if error count decreased
+       to zero (ticket #67).
+
   [CF] smartctl: Rework ataPrintMain().  Issue ATA SMART commands only if
        necessary.  Improve handling of SMART STATUS command failure when
        ATA output registers are missing (ticket #27).
diff --git a/smartmontools/smartd.cpp b/smartmontools/smartd.cpp
index b8eaa09c4..cdd29b042 100644
--- a/smartmontools/smartd.cpp
+++ b/smartmontools/smartd.cpp
@@ -2058,7 +2058,8 @@ static void CheckSelfTestLogs(const dev_config & cfg, dev_state & state, int new
       MailWarning(cfg, state, 3, "Device: %s, Self-Test Log error count increased from %d to %d",
                    name, oldc, newc);
       state.must_write = true;
-    } else if (oldh!=newh) {
+    }
+    else if (newc > 0 && oldh != newh) {
       // more recent error
       // a 'more recent' error might actually be a smaller hour number,
       // if the hour number has wrapped.
@@ -2072,7 +2073,12 @@ static void CheckSelfTestLogs(const dev_config & cfg, dev_state & state, int new
                    name, newh);
       state.must_write = true;
     }
-    
+
+    // Print info if error entries have disappeared
+    if (oldc > newc)
+      PrintOut(LOG_INFO, "Device: %s, Self-Test Log error count decreased from %d to %d\n",
+               name, oldc, newc);
+
     // Needed since self-test error count may DECREASE.  Hour might
     // also have changed.
     state.selflogcount= newc;
-- 
GitLab