Skip to main content

LaunchNonceHandoff

Struct LaunchNonceHandoff 

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

The daemon half of the handoff, prepared before the spawn: a pipe that already holds the nonce, its write end closed, and its inode.

A module uses the same type to hand its own nonce to a helper process that must connect as the module: never in argv, the environment or a file, all of which another same-user process can read.

use subc_os::launch_nonce::{LaunchNonceHandoff, LAUNCH_NONCE_FD_ENV};

let mut command = std::process::Command::new("helper");
let handoff = LaunchNonceHandoff::new(nonce)?;
command.env(LAUNCH_NONCE_FD_ENV, handoff.fd_env_value());
// After every other pre-exec step the command has.
handoff.install_last(&mut command);
command.spawn()?;

Implementations§

Source§

impl LaunchNonceHandoff

Source

pub fn new(nonce: &str) -> Result<Self>

Make the pipe, write nonce into it and close the write end, so a reader gets exactly nonce and then end of file.

Both ends are created close-on-exec (std::io::pipe does that), so the read end reaches no child until Self::install_last puts it into one. The nonce must fit in the pipe buffer, or the write blocks with no reader: POSIX guarantees 512 bytes and macOS and Linux give 16 KiB or more, and a daemon nonce is 64 characters.

Source

pub fn fd_env_value(&self) -> String

The value to give the child as LAUNCH_NONCE_FD_ENV: 3:<inode of this pipe>.

Source

pub fn install_last(self, command: &mut Command)

Arrange for the read end to be descriptor 3 in the process command spawns, and in no other process. For a tokio Command, pass command.as_std_mut().

It must be the LAST pre-exec step registered. The standard library runs pre-exec steps in registration order, after its own stdio setup, and this one closes whatever the child had at descriptor 3. A step that runs later and writes through a descriptor it captured (the Linux cgroup placement writes to cgroup.procs) would find the pipe there instead if that descriptor had number 3.

Registering any pre-exec step makes the standard library fork and exec instead of using posix_spawn, on macOS as on Linux.

Trait Implementations§

Source§

impl Debug for LaunchNonceHandoff

Source§

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

Formats the value using the given formatter. 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.