CgroupSysctl

Struct CgroupSysctl 

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

A program used to watch for sysctl changes.

CgroupSysctl programs can be attached to a cgroup and will be called every time a process inside that cgroup tries to read from or write to a sysctl knob in proc.

§Minimum kernel version

The minimum kernel version required to use this feature is 5.2.

§Examples

use std::fs::File;
use aya::programs::{CgroupAttachMode, CgroupSysctl};

let file = File::open("/sys/fs/cgroup/unified")?;
let program: &mut CgroupSysctl = bpf.program_mut("cgroup_sysctl").unwrap().try_into()?;
program.load()?;
program.attach(file, CgroupAttachMode::Single)?;

Implementations§

Source§

impl CgroupSysctl

Source

pub fn load(&mut self) -> Result<(), ProgramError>

Loads the program inside the kernel.

Source

pub fn attach<T: AsFd>( &mut self, cgroup: T, mode: CgroupAttachMode, ) -> Result<CgroupSysctlLinkId, ProgramError>

Attaches the program to the given cgroup.

The returned value can be used to detach, see CgroupSysctl::detach.

Takes ownership of the link referenced by the provided link_id.

The link will be detached on Drop and the caller is now responsible for managing its lifetime.

Source

pub fn detach( &mut self, link_id: CgroupSysctlLinkId, ) -> Result<(), ProgramError>

Detaches the program.

See CgroupSysctl::attach.

Source§

impl CgroupSysctl

Source

pub fn unload(&mut self) -> Result<(), ProgramError>

Unloads the program from the kernel.

Links will be detached before unloading the program. Note that owned links obtained using take_link() will not be detached.

Source§

impl CgroupSysctl

Source

pub fn fd(&self) -> Result<&ProgramFd, ProgramError>

Returns the file descriptor of this Program.

Source§

impl CgroupSysctl

Source

pub fn pin<P: AsRef<Path>>(&mut self, path: P) -> Result<(), PinError>

Pins the program to a BPF filesystem.

When a BPF object is pinned to a BPF filesystem it will remain loaded after Aya has unloaded the program. To remove the program, the file on the BPF filesystem must be removed. Any directories in the the path provided should have been created by the caller.

Source

pub fn unpin(self) -> Result<(), Error>

Removes the pinned link from the filesystem.

Source§

impl CgroupSysctl

Source

pub fn from_pin<P: AsRef<Path>>(path: P) -> Result<Self, ProgramError>

Creates a program from a pinned entry on a bpffs.

Existing links will not be populated. To work with existing links you should use crate::programs::links::PinnedLink.

On drop, any managed links are detached and the program is unloaded. This will not result in the program being unloaded from the kernel if it is still pinned.

Source§

impl CgroupSysctl

Source

pub fn info(&self) -> Result<ProgramInfo, ProgramError>

Returns metadata information of this program.

Uses kernel v4.13 features.

Trait Implementations§

Source§

impl Debug for CgroupSysctl

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for CgroupSysctl

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a> TryFrom<&'a Program> for &'a CgroupSysctl

Source§

type Error = ProgramError

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

fn try_from(program: &'a Program) -> Result<&'a CgroupSysctl, ProgramError>

Performs the conversion.
Source§

impl<'a> TryFrom<&'a mut Program> for &'a mut CgroupSysctl

Source§

type Error = ProgramError

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

fn try_from( program: &'a mut Program, ) -> Result<&'a mut CgroupSysctl, ProgramError>

Performs the conversion.

Auto Trait Implementations§

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.