Compose foreground sandbox process lifetimes

This commit is contained in:
ms2k 2026-07-15 19:09:24 +09:00
commit fd78804fc7

View file

@ -13,9 +13,10 @@ use lazaret_core::records::{
HostProcessOwnershipSlot, ProcessOwnershipCommitAck, StagedProcessOwnership,
};
use lazaret_linux::process::{
ProcessOwnershipContext, TargetCommand, append_parent_identity, child_broker,
ChildStandardIo, ProcessOwnershipContext, TargetCommand, append_parent_identity, child_broker,
current_process_identity, dispatch_private_process_role, verify_direct_child_pidfd,
};
use rustix::pipe::{PipeFlags, pipe_with};
use rustix::process::{PidfdFlags, pidfd_open};
static SEQUENCE: AtomicU64 = AtomicU64::new(0);
@ -43,6 +44,7 @@ fn exit(result: std::io::Result<()>) -> ExitCode {
fn run_all() -> std::io::Result<()> {
successful_acquisition()?;
lifetime_pipe_acquisition()?;
failed_stages_and_acknowledgments()?;
production_wrapper_refuses_former_harness_path()?;
malformed_barriers_refuse()?;
@ -51,6 +53,32 @@ fn run_all() -> std::io::Result<()> {
concurrent_acquisitions_serialize()
}
#[allow(clippy::disallowed_methods, clippy::disallowed_types)]
fn lifetime_pipe_acquisition() -> std::io::Result<()> {
let marker = marker("lifetime-pipe");
let parent = current_process_identity()?;
let target = TargetCommand::new("/usr/bin/touch")
.argument(&marker)
.with_lifetime_pipe_parent_edge();
let (lifetime_reader, lifetime_writer) = pipe_with(PipeFlags::CLOEXEC)?;
let process = child_broker().acquire_with_stdio(
parent,
context(),
&target,
ChildStandardIo::redirected(Stdio::null(), Stdio::from(lifetime_reader)),
|_| Ok(()),
|staged| Ok(ProcessOwnershipCommitAck::v1(staged)),
)?;
child_broker().reap(process)?;
drop(lifetime_writer);
if !marker.is_file() {
return Err(std::io::Error::other(
"lifetime-pipe acquisition did not execute its target",
));
}
std::fs::remove_file(marker)
}
fn marker(name: &str) -> std::path::PathBuf {
std::env::temp_dir().join(format!(
"lazaret-acquisition-{name}-{}-{}",
@ -243,7 +271,9 @@ fn malformed_barriers_refuse() -> std::io::Result<()> {
.arg("--lazaret-private-process-role")
.arg("launch-wrapper");
append_parent_identity(&mut command, parent);
command.arg("--").arg("/usr/bin/touch").arg(&marker);
command
.args(["--parent-action", "kill", "--", "/usr/bin/touch"])
.arg(&marker);
command.stdin(Stdio::from(temporary_file(&bytes)?));
if command.status()?.success() || marker.exists() {
return Err(std::io::Error::other("malformed barrier released target"));