MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / install_pre_exec

Function install_pre_exec

crates/openshell-supervisor-process/src/ssh.rs:1104–1137  ·  view source on GitHub ↗
(
        cmd: &mut Command,
        policy: SandboxPolicy,
        _workdir: Option<String>,
        slave_fd: RawFd,
        netns_fd: Option<RawFd>,
        #[cfg(target_os = "linux")] prepared: cr

Source from the content-addressed store, hash-verified

1102 )
1103 )]
1104 pub fn install_pre_exec(
1105 cmd: &mut Command,
1106 policy: SandboxPolicy,
1107 _workdir: Option<String>,
1108 slave_fd: RawFd,
1109 netns_fd: Option<RawFd>,
1110 #[cfg(target_os = "linux")] prepared: crate::sandbox::linux::PreparedSandbox,
1111 ) -> anyhow::Result<()> {
1112 // Wrap in Option so we can .take() it out of the FnMut closure.
1113 // pre_exec is only called once (after fork, before exec).
1114 #[cfg(target_os = "linux")]
1115 let mut prepared = Some(prepared);
1116 #[cfg(target_os = "linux")]
1117 let supervisor_identity_mount = crate::process::supervisor_identity_mount_from_env()
1118 .map_err(|err| {
1119 anyhow::anyhow!("failed to prepare supervisor identity isolation: {err}")
1120 })?;
1121 unsafe {
1122 cmd.pre_exec(move || {
1123 setsid().map_err(|err| std::io::Error::other(err.to_string()))?;
1124 set_controlling_tty(slave_fd)?;
1125
1126 enter_netns_and_sandbox(
1127 netns_fd,
1128 &policy,
1129 #[cfg(target_os = "linux")]
1130 supervisor_identity_mount,
1131 #[cfg(target_os = "linux")]
1132 prepared.take(),
1133 )
1134 });
1135 }
1136 Ok(())
1137 }
1138
1139 /// Pre-exec hook for pipe-based (non-PTY) exec.
1140 ///

Callers 1

spawn_pty_shellFunction · 0.85

Calls 3

set_controlling_ttyFunction · 0.85
enter_netns_and_sandboxFunction · 0.85

Tested by

no test coverage detected