Skip to main content

CmdFds

Struct CmdFds 

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

File descriptor allocator for child processes.

Collects fd assignments and optional systemd socket-activation configuration, then applies them all at once via CapStdExtCommandExt::take_fds.

  • new_systemd_fds creates an allocator with systemd socket-activation fds at 3, 4, … (SD_LISTEN_FDS_START).
  • take_fd auto-assigns the next fd above all previously assigned ones (minimum 3).
  • take_fd_n places an fd at an explicit number, panicking on overlap.
let mut cmd = std::process::Command::new("myservice");
let mut fds = CmdFds::new_systemd_fds([(varlink_fd, SystemdFdName::new("varlink"))]);
let extra_n = fds.take_fd(extra_fd);
cmd.take_fds(fds);

Implementations§

Source§

impl CmdFds

Source

pub fn new() -> Self

Create a new fd allocator.

Source

pub fn new_systemd_fds<'a>( fds: impl IntoIterator<Item = (Arc<OwnedFd>, SystemdFdName<'a>)>, ) -> Self

Create a new fd allocator with systemd socket-activation fds.

Each (fd, name) pair is assigned a consecutive fd number starting at SD_LISTEN_FDS_START (3). The LISTEN_PID, LISTEN_FDS, and LISTEN_FDNAMES environment variables will be set in the child when CapStdExtCommandExt::take_fds is called.

Additional (non-systemd) fds can be registered afterwards via take_fd or take_fd_n.

Source

pub fn take_fd(&mut self, fd: Arc<OwnedFd>) -> i32

Register a file descriptor at the next available fd number.

Returns the fd number that will be assigned in the child. Call CapStdExtCommandExt::take_fds to apply.

Source

pub fn take_fd_n(&mut self, fd: Arc<OwnedFd>, target: i32) -> &mut Self

Register a file descriptor at a specific fd number.

Call CapStdExtCommandExt::take_fds to apply.

§Panics

Panics if target has already been assigned.

Trait Implementations§

Source§

impl Debug for CmdFds

Source§

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

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

impl Default for CmdFds

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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.