diff --git a/src/cgroup.rs b/src/cgroup.rs index 3e92757..63f413a 100644 --- a/src/cgroup.rs +++ b/src/cgroup.rs @@ -260,6 +260,22 @@ impl Cgroup { .try_for_each(|sub| sub.to_controller().add_task_by_tgid(&pid)) } + /// Set notify_on_release to the control group. + pub fn set_notify_on_release(&self, enable: bool) -> Result<()> { + self.subsystems() + .iter() + .try_for_each(|sub| sub.to_controller().set_notify_on_release(enable)) + } + + /// Set release_agent + pub fn set_release_agent(&self, path: &str) -> Result<()> { + self.hier + .root_control_group() + .subsystems() + .iter() + .try_for_each(|sub| sub.to_controller().set_release_agent(path)) + } + /// Returns an Iterator that can be used to iterate over the tasks that are currently in the /// control group. pub fn tasks(&self) -> Vec { diff --git a/src/lib.rs b/src/lib.rs index 46551cb..f1205be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -246,6 +246,12 @@ pub trait Controller { /// Does this controller already exist? fn exists(&self) -> bool; + /// Set notify_on_release + fn set_notify_on_release(&self, enable: bool) -> Result<()>; + + /// Set release_agent + fn set_release_agent(&self, path: &str) -> Result<()>; + /// Delete the controller. fn delete(&self) -> Result<()>; @@ -290,6 +296,22 @@ where } } + /// Set notify_on_release + fn set_notify_on_release(&self, enable: bool) -> Result<()> { + self.open_path("notify_on_release", true) + .and_then(|mut file| { + write!(file, "{}", enable as i32) + .map_err(|e| Error::with_cause(ErrorKind::WriteFailed, e)) + }) + } + + /// Set release_agent + fn set_release_agent(&self, path: &str) -> Result<()> { + self.open_path("release_agent", true).and_then(|mut file| { + file.write_all(path.as_bytes()) + .map_err(|e| Error::with_cause(ErrorKind::WriteFailed, e)) + }) + } /// Does this controller already exist? fn exists(&self) -> bool { self.get_path().exists()