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
impl LaunchNonceHandoff
Sourcepub fn new(nonce: &str) -> Result<Self>
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.
Sourcepub fn fd_env_value(&self) -> String
pub fn fd_env_value(&self) -> String
The value to give the child as
LAUNCH_NONCE_FD_ENV:
3:<inode of this pipe>.
Sourcepub fn install_last(self, command: &mut Command)
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.