Skip to content

Commit 3f62756

Browse files
committed
fix(supervisor): keep detached entrypoint stdin open
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent dc036ca commit 3f62756

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

‎crates/openshell-supervisor-process/src/process.rs‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,12 @@ fn mount_empty_tmpfs(target: &CString) -> std::io::Result<()> {
515515
/// Handle to a running process.
516516
pub struct ProcessHandle {
517517
child: Child,
518+
// Keep the canonical entrypoint's stdin open even when the supervisor
519+
// itself has no stdin (for example, a detached Docker supervisor). The
520+
// backend-neutral access plane does not attach this pipe yet, but closing
521+
// it here would make the canonical scratch shell exit before exec/connect
522+
// can reach the sandbox.
523+
_stdin_guard: Option<tokio::process::ChildStdin>,
518524
pid: u32,
519525
#[cfg(target_os = "linux")]
520526
managed_child: Option<managed_children::ManagedChild>,
@@ -608,7 +614,7 @@ impl ProcessHandle {
608614
) -> Result<Self> {
609615
let mut cmd = Command::new(program);
610616
cmd.args(args)
611-
.stdin(Stdio::inherit())
617+
.stdin(Stdio::piped())
612618
.stdout(Stdio::inherit())
613619
.stderr(Stdio::inherit())
614620
.kill_on_drop(true)
@@ -739,7 +745,8 @@ impl ProcessHandle {
739745

740746
#[cfg(target_os = "linux")]
741747
let mut child_registry = managed_children::lock();
742-
let child = cmd.spawn().into_diagnostic()?;
748+
let mut child = cmd.spawn().into_diagnostic()?;
749+
let stdin_guard = child.stdin.take();
743750
let pid = child.id().unwrap_or(0);
744751
let managed_child = child_registry.register(pid);
745752
drop(child_registry);
@@ -748,6 +755,7 @@ impl ProcessHandle {
748755

749756
Ok(Self {
750757
child,
758+
_stdin_guard: stdin_guard,
751759
pid,
752760
managed_child,
753761
terminal: Arc::new(AtomicBool::new(false)),
@@ -771,7 +779,7 @@ impl ProcessHandle {
771779
) -> Result<Self> {
772780
let mut cmd = Command::new(program);
773781
cmd.args(args)
774-
.stdin(Stdio::inherit())
782+
.stdin(Stdio::piped())
775783
.stdout(Stdio::inherit())
776784
.stderr(Stdio::inherit())
777785
.kill_on_drop(true)
@@ -845,7 +853,8 @@ impl ProcessHandle {
845853

846854
#[cfg(target_os = "linux")]
847855
let mut child_registry = managed_children::lock();
848-
let child = cmd.spawn().into_diagnostic()?;
856+
let mut child = cmd.spawn().into_diagnostic()?;
857+
let stdin_guard = child.stdin.take();
849858
let pid = child.id().unwrap_or(0);
850859
#[cfg(target_os = "linux")]
851860
let managed_child = child_registry.register(pid);
@@ -856,6 +865,7 @@ impl ProcessHandle {
856865

857866
Ok(Self {
858867
child,
868+
_stdin_guard: stdin_guard,
859869
pid,
860870
#[cfg(target_os = "linux")]
861871
managed_child,

0 commit comments

Comments
 (0)