Skip to content

Commit

Permalink
cleanup errno check
Browse files Browse the repository at this point in the history
  • Loading branch information
tsturzl committed May 24, 2021
1 parent 54978c2 commit b808f30
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/cgroups/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,24 +156,21 @@ impl Memory {
Ok(_) => Ok(()),
Err(e) => {
// we need to look into the raw OS error for an EBUSY status
if let Some(code) = e.raw_os_error() {
// the nix crate has a handy enum for these, lets use that
let errno = Errno::from_i32(code);
// if the error is EBUSY
if let Errno::EBUSY = errno {
let usage = Self::get_memory_usage(cgroup_root)?;
let max_usage = Self::get_memory_max_usage(cgroup_root)?;
Err(anyhow!(
"unable to set memory limit to {} (current usage: {}, peak usage: {})",
val,
usage,
max_usage,
))
} else {
Err(anyhow!(e))
}
} else {
Err(anyhow!(e))
match e.raw_os_error() {
Some(code) => match Errno::from_i32(code) {
Errno::EBUSY => {
let usage = Self::get_memory_usage(cgroup_root)?;
let max_usage = Self::get_memory_max_usage(cgroup_root)?;
Err(anyhow!(
"unable to set memory limit to {} (current usage: {}, peak usage: {})",
val,
usage,
max_usage,
))
}
_ => Err(anyhow!(e)),
},
None => Err(anyhow!(e)),
}
}
}
Expand Down

0 comments on commit b808f30

Please sign in to comment.