mirror of
https://github.com/kata-containers/cgroups-rs.git
synced 2026-08-05 02:13:23 +00:00
Support set notify_on_release & release_agent
Support set notify_on_release & release_agent Signed-off-by: Qingyuan Hou <qingyuan.hou@linux.alibaba.com>
This commit is contained in:
@@ -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<CgroupPid> {
|
||||
|
||||
22
src/lib.rs
22
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()
|
||||
|
||||
Reference in New Issue
Block a user