From: Yaroslav Sidlovsky Date: Wed, 17 Mar 2021 12:37:30 +0000 (+0300) Subject: [PATCH] Fix smartctl exit status success check According to the smartctl man page... X-Git-Tag: archive/raspbian/20.12.3-2+rpi1^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=7163150a87530c927aa4443793414f7f7be3015d;p=kpmcore.git [PATCH] Fix smartctl exit status success check According to the smartctl man page: ``` EXIT STATUS The exit statuses of smartctl are defined by a bitmask. If all is well with the disk, the exit status (return value) of smartctl is 0 (all bits turned off). If a problem occurs, or an error, potential error, or fault is detected, then a non-zero status is returned. In this case, the eight different bits in the exit status have the following meanings for ATA disks; some of these values may also be returned for SCSI disks. . Bit 0: Command line did not parse. . Bit 1: Device open failed, device did not return an IDENTIFY DEVICE structure, or device is in a low-power mode (see '-n' option above). . Bit 2: Some SMART or other ATA command to the disk failed, or there was a checksum error in a SMART data structure (see '-b' option above). . Bit 3: SMART status check returned "DISK FAILING". . Bit 4: We found prefail Attributes <= threshold. . Bit 5: SMART status check returned "DISK OK" but we found that some (usage or prefail) Attributes have been <= threshold at some time in the past. . Bit 6: The device error log contains records of errors. . Bit 7: The device self-test log contains records of errors. [ATA only] Failed self-tests outdated by a newer successful extended self-test are ignored. ``` . BUG: 429028 Gbp-Pq: Name upstream_2ea9ff49_fix_smartctl_exit_status_success_check.patch --- diff --git a/src/core/smartparser.cpp b/src/core/smartparser.cpp index 80c73f1..9170a0f 100644 --- a/src/core/smartparser.cpp +++ b/src/core/smartparser.cpp @@ -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);