pub fn getpipe(cmd: &str, nullexec: i32) -> i32Expand description
Port of static int getpipe(char *cmd, int nullexec) from
Src/exec.c:5119.
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 now ported (exec.rs:3934) including the
ESUB_PGRP pipeline group-leadership path — wired this
session for getpipe’s entersubsh(ESUB_ASYNC|ESUB_PGRP| ESUB_NOMONITOR, NULL) call.
(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) _realexit() flushes stdio + jobs + history. We use bare
std::process::exit(lastval) for now.