Struct Cgroup

Source
pub struct Cgroup { /* private fields */ }
Expand description

A controller of a specific cgroups namespace.

This type supports a number of operations for manipulating with a cgroups namespace.

Implementations§

Source§

impl Cgroup

Source

pub fn new(cgroup_name: &CgroupName, subsystem: &str) -> Self

Defines a cgroup relation.

Notes:

Source

pub fn create(&self) -> Result<()>

Creates a cgroups namespace.

Notes:

  • Keep in mind the usual filesystem permissions (owner, group, and mode bits).
Source

pub fn remove(&self) -> Result<()>

Removes a cgroups namespace.

Notes:

  • This method will fail if there are nested cgroups.
  • Keep in mind the usual filesystem permissions (owner, group, and mode bits).
Source

pub fn set_raw_value<V>(&self, key: &str, value: V) -> Result<()>
where V: AsRef<[u8]>,

Sets a binary or string value to the cgroup control file.

Source

pub fn set_value<V>(&self, key: &str, value: V) -> Result<()>
where V: Copy + ToString,

Sets a value to the cgroup control file.

Source

pub fn get_raw_value(&self, key: &str) -> Result<String>

Gets a string value from cgroup control file.

Source

pub fn get_value<T>(&self, key: &str) -> Result<T>
where T: FromStr,

Gets a value from cgroup control file.

Source

pub fn add_task(&self, pid: Pid) -> Result<()>

Attaches a task (thread) to the cgroup.

Source

pub fn get_tasks(&self) -> Result<Vec<Pid>>

Lists tasks (threads) attached to the cgroup.

Source

pub fn send_signal_to_all_tasks(&self, signal: Signal) -> Result<usize>

Sends a specified Unix Signal to all the tasks in the Cgroup.

Source

pub fn kill_all_tasks(&self) -> Result<()>

👎Deprecated since 1.0.1: please, use freezer cgroup to implement kill_all_tasks reliably (https://gitlab.com/dots.org.ua/ddots-runner/blob/d967ee3ba9de364dfb5a2e1a4f468586efb504f8/src/extensions/process.rs#L132-166)

Kills (SIGKILL) all the attached to the cgroup tasks.

WARNING: The naive implementation turned out to be not reliable enough for the fork-bomb use-case. To implement a reliable kill_all method, use freezer Cgroup. It is decided to move such extensions into a separate crate (to be announced).

Trait Implementations§

Source§

impl AsRef<Cgroup> for AutomanagedCgroup

Source§

fn as_ref(&self) -> &Cgroup

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Debug for Cgroup

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Cgroup

§

impl RefUnwindSafe for Cgroup

§

impl Send for Cgroup

§

impl Sync for Cgroup

§

impl Unpin for Cgroup

§

impl UnwindSafe for Cgroup

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.