Skip to content

Commit

Permalink
Fix cgroup.events error when cgroup is gone before reading events
Browse files Browse the repository at this point in the history
If cgroup is gone before reading the cgroup.events file then it will return
an error. Treat errors as unpopulated to account for it.
  • Loading branch information
nbdd0121 committed May 13, 2024
1 parent f2cd92f commit 3e52a32
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/runc/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ impl CgroupEventNotifier {

fn populated(&mut self) -> Result<bool> {
let file = self.file.get_mut();
file.seek(std::io::SeekFrom::Start(0))
.context("Cannot seek to start")?;
let Ok(_) = file.seek(std::io::SeekFrom::Start(0)) else {
return Ok(false);
};
for line in BufReader::new(file).lines() {
let line = line.context("Cannot read line")?;
let Ok(line) = line else {
// IO errors on cgroup.events file indicate that the cgroup has been deleted, so
// it is no longer populated.
return Ok(false);
};
if line.starts_with("populated ") {
return Ok(line.ends_with('1'));
}
Expand Down

0 comments on commit 3e52a32

Please sign in to comment.