Skip to content

Fix/status and exit code handling - #121

Open
arekm wants to merge 4 commits into
Napsty:masterfrom
arekm:fix/status-and-exit-code-handling
Open

Fix/status and exit code handling#121
arekm wants to merge 4 commits into
Napsty:masterfrom
arekm:fix/status-and-exit-code-handling

Conversation

@arekm

@arekm arekm commented Aug 13, 2026

Copy link
Copy Markdown
  • escalate_status() used a bitwise string OR as its downgrade guard
    ('CRITICAL'|'OK' is 'O[ITICAL'), so under -g a later disk's WARNING
    overwrote an earlier disk's CRITICAL. Statuses are now ranked.
  • $? is the wait status, so the exit code is $? >> 8; every
    $? & 0x01..0x80 test read the low byte and could never fire. Signal
    death now reports UNKNOWN instead of looking clean.
  • --skip-error-log now also covers exit status bit 6.
  • Bit 2 is "SMART/ATA command failed, or checksum error", usually the
    former — Checksum failure points at the wrong problem.

arekm added 4 commits August 13, 2026 09:42
escalate_status() guarded against downgrades with ($exit_status|$exit_status_local),
which is a bitwise string OR, not a logical one: 'CRITICAL'|'OK' is 'O[ITICAL', so
the guard only ever matched while both variables were already equal. Under -g the
per-device variable is reset for every disk, so a WARNING on a later disk silently
overwrote a CRITICAL from an earlier one and the plugin exited 1 instead of 2.

Rank the statuses and raise each variable only when the new one is worse. This also
keeps the per-device status correct when the global status is already higher.
…e bits

system() sets $? to the wait status, so the exit code is $? >> 8. Testing
$? & 0x01 .. 0x80 inspects the low byte, which is 0 for every normal exit, so
none of the exit status checks could ever fire.

Shifting alone would make a smartctl killed by a signal look like a clean run,
so handle abnormal termination explicitly and report it as UNKNOWN.
The flag suppressed the ATA Error Count check on the attribute output but not
bit 6 of smartctl's exit status, which reports the same condition.
Bit 2 is "Some SMART or other ATA command to the disk failed, or there was a
checksum error in a SMART data structure", and in practice it is usually the
former: an optional command the drive or controller does not support. Calling
it a checksum failure sends the operator after the wrong problem.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant