[PATCH] Fix smartctl exit status success check According to the smartctl man page...
authorYaroslav Sidlovsky <zawertun@gmail.com>
Wed, 17 Mar 2021 12:37:30 +0000 (15:37 +0300)
committerAurélien COUDERC <coucouf@debian.org>
Mon, 22 Mar 2021 10:36:09 +0000 (10:36 +0000)
Gbp-Pq: Name upstream_2ea9ff49_fix_smartctl_exit_status_success_check.patch

src/core/smartparser.cpp

index 80c73f19a8cedade7c6d1687945ae77771f26e4a..9170a0f6ed7cfb78643e8e39f8ab43d4e6098450 100644 (file)
@@ -117,7 +117,11 @@ void SmartParser::loadSmartOutput()
     if (m_SmartOutput.isEmpty()) {
         ExternalCommand smartctl(QStringLiteral("smartctl"), { QStringLiteral("--all"), QStringLiteral("--json"), devicePath() });
 
-        if (smartctl.run() && smartctl.exitCode() == 0) {
+        // Exit status of smartctl is a bitfield, check that bits 0 and 1 are not set:
+        //  - bit 0: command line did not parse;
+        //  - bit 1: device open failed.
+        // See `man 8 smartctl` for more details.
+        if (smartctl.run() && (smartctl.exitCode() & 1) == 0 && (smartctl.exitCode() & 2) == 0) {
             QByteArray output = smartctl.rawOutput();
 
             m_SmartOutput = QJsonDocument::fromJson(output);