Skip to main content

getpipe

Function getpipe 

Source
pub fn getpipe(cmd: &str, nullexec: i32) -> i32
Expand description

Port of getpipe() from Src/exec.c:5119 — C decl getpipe(char *cmd, int nullexec).

C body executes <(cmd) / >(cmd) process substitution via a pipe pair: parent gets back the readable (<(...)) or writable (>(...)) end as an fd; child runs the substituted command with its stdio redirected into the other end.

Eprog prog;
int pipes[2], out = *cmd == Inang;
pid_t pid;
struct timespec bgtime;
char *ends;
if (!(prog = parsecmd(cmd, &ends))) return -1;
if (*ends) { zerr("invalid syntax..."); return -1; }
if (mpipe(pipes) < 0) return -1;
if ((pid = zfork(&bgtime))) {
    zclose(pipes[out]);
    if (pid == -1) { zclose(pipes[!out]); return -1; }
    if (!nullexec) addproc(pid, NULL, 1, &bgtime, -1, -1);
    procsubstpid = pid;
    return pipes[!out];
}
entersubsh(ESUB_ASYNC|ESUB_PGRP|ESUB_NOMONITOR, NULL);
redup(pipes[out], out);
closem(FDT_UNUSED, 0);
cmdpush(CS_CMDSUBST);
execode(prog, 0, 1, out ? "outsubst" : "insubst");
cmdpop();
_realexit();

(a) addproc is now 7-arg (jobs.rs:1516) — wired at the procsubst pid recording site (c:5141-5142) earlier this session; the child IS now recorded in JOBTAB[thisjob]. (b) entersubsh IS ported (exec.rs:4329) including the ESUB_PGRP pipeline group-leadership path, and is called from the real forked child below for getpipe’s entersubsh(ESUB_ASYNC|ESUB_PGRP|ESUB_NOMONITOR, NULL). (c) execode(prog, ...) IS now ported (exec.rs:6047) — getpipe can route through execode for the parsed eprog. Currently this caller still uses the fusevm pipeline for cache coherence with execstring; switch over when the wordcode walker becomes the primary path. (d) The child ends with _realexit() (c:5152) after flushing Rust’s in-process stdout buffer.