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

Function spawn_pty_shell

crates/openshell-supervisor-process/src/ssh.rs:739–897  ·  view source on GitHub ↗
(
    policy: &SandboxPolicy,
    workdir: Option<String>,
    command: Option<String>,
    pty: &PtyRequest,
    handle: Handle,
    channel: ChannelId,
    netns_fd: Option<RawFd>,
    proxy_url: Op

Source from the content-addressed store, hash-verified

737
738#[allow(clippy::too_many_arguments)]
739fn spawn_pty_shell(
740 policy: &SandboxPolicy,
741 workdir: Option<String>,
742 command: Option<String>,
743 pty: &PtyRequest,
744 handle: Handle,
745 channel: ChannelId,
746 netns_fd: Option<RawFd>,
747 proxy_url: Option<String>,
748 ca_file_paths: Option<Arc<(PathBuf, PathBuf)>>,
749 provider_env: &HashMap<String, String>,
750 user_environment: &HashMap<String, String>,
751) -> anyhow::Result<(std::fs::File, mpsc::Sender<Vec<u8>>)> {
752 let winsize = Winsize {
753 ws_row: to_u16(pty.row_height.max(1)),
754 ws_col: to_u16(pty.col_width.max(1)),
755 ws_xpixel: to_u16(pty.pixel_width),
756 ws_ypixel: to_u16(pty.pixel_height),
757 };
758 let openpty = openpty(Some(&winsize), None)?;
759 let master = std::fs::File::from(openpty.master);
760 let slave = std::fs::File::from(openpty.slave);
761 let slave_fd = slave.as_raw_fd();
762
763 let stdin = slave.try_clone()?;
764 let stdout = slave.try_clone()?;
765 let stderr = slave;
766 let mut reader = master.try_clone()?;
767 let mut writer = master.try_clone()?;
768
769 let mut cmd = command.map_or_else(
770 || {
771 let mut c = Command::new("/bin/bash");
772 c.arg("-i");
773 c
774 },
775 |command| {
776 let mut c = Command::new("/bin/bash");
777 c.arg("-lc").arg(command);
778 c
779 },
780 );
781
782 let term = if pty.term.is_empty() {
783 "xterm-256color"
784 } else {
785 pty.term.as_str()
786 };
787
788 // Derive USER and HOME from the policy's run_as_user when available,
789 // falling back to "sandbox" / "/sandbox" for backward compatibility.
790 let (session_user, session_home) = session_user_and_home(policy);
791 apply_child_env(
792 &mut cmd,
793 &session_home,
794 &session_user,
795 term,
796 proxy_url.as_deref(),

Callers 1

start_shellMethod · 0.85

Calls 15

to_u16Function · 0.85
session_user_and_homeFunction · 0.85
apply_child_envFunction · 0.85
log_sandbox_readinessFunction · 0.85
install_pre_execFunction · 0.85
registerFunction · 0.85
unregisterFunction · 0.85
dataMethod · 0.80
waitMethod · 0.80
codeMethod · 0.80
spawnFunction · 0.70
prepareFunction · 0.50

Tested by

no test coverage detected