Skip to main content

make_pty

Function make_pty 

Source
pub fn make_pty() -> Result<(Fd, Fd), CoreError>
Expand description

Open a new pseudo-terminal and return (master, slave), both relocated above stdio with O_CLOEXEC.

The master is drained as the child’s single merged stdout+stderr stream; the slave is dup2’d to the child’s fd 0/1/2 in the child setup. Both are O_NOCTTY so neither side accidentally becomes a controlling terminal of the daemon (only the child claims it via TIOCSCTTY).

The pair is returned to the caller so a spawn can be configured before the child execs: apply the initial window with pty_window, derive the child’s LINES/COLUMNS env from that read-back, then hand ownership to SpawnOptionsBuilder::pty_with. Core re-takes ownership inside Pipes: from the moment the pair enters the spawn options, Core owns both descriptors and is responsible for their cleanup on every success and failure path — there is no ambiguous “does the caller still own this fd?” state.