Skip to content

Commit

Permalink
fix: always check subprocess return codes
Browse files Browse the repository at this point in the history
  • Loading branch information
desbma committed Jan 1, 2025
1 parent 8d287d1 commit 376291a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/device/drive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ impl Drive {
.stdout(Stdio::piped())
.stderr(Stdio::null())
.output()?;
if !output.status.success() {
log::trace!("{}", output.status);
continue;
}
// log::trace!("{}", std::str::from_utf8(&output.stdout).unwrap());
if let Some(line) = output.stdout.lines().map_while(Result::ok).find(|l| {
let l = l.trim_start();
Expand All @@ -104,6 +108,11 @@ impl Drive {
.stdout(Stdio::piped())
.stderr(Stdio::null())
.output()?;
anyhow::ensure!(
output.status.success(),
"hdparm failed with code {}",
output.status
);
let state = output
.stdout
.lines()
Expand Down
5 changes: 5 additions & 0 deletions src/probe/hddtemp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ impl DeviceTempProber for InvocationProber {
.stderr(Stdio::null())
.env("LANG", "C")
.output()?;
anyhow::ensure!(
output.status.success(),
"hddtemp failed with code {}",
output.status
);
// TODO handle "drive is sleeping" case
let temp = str::from_utf8(&output.stdout)?.trim_end().parse()?;
Ok(temp)
Expand Down
10 changes: 10 additions & 0 deletions src/probe/smartctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ impl DeviceTempProber for SctProber {
.stderr(Stdio::null())
.env("LANG", "C")
.output()?;
anyhow::ensure!(
output.status.success(),
"smartctl failed with code {}",
output.status
);
let temp = output
.stdout
.lines()
Expand Down Expand Up @@ -162,6 +167,11 @@ impl DeviceTempProber for AttribProber {
.stderr(Stdio::null())
.env("LANG", "C")
.output()?;
anyhow::ensure!(
output.status.success(),
"smartctl failed with code {}",
output.status
);
let temp = output
.stdout
.lines()
Expand Down

0 comments on commit 376291a

Please sign in to comment.