Pipe fds to move to the "high range"

This concerns how fish prevents its own fds from interfering with
user-defined fd redirections, like `echo hi >&5`. fish has historically
done this by tracking all user defined redirections when running a job,
and ensuring that pipes are not assigned the same fds. However this is
annoying to pass around - it means that we have to thread user-defined
redirections into pipe creation.

Take a page from zsh and just ensure that all pipes we create have fds in
the "high range," which here means at least 10. The primary way to do this
is via the F_DUPFD_CLOEXEC syscall, which also sets CLOEXEC, so we aren't
invoking additional syscalls in the common case. This will free us from
having to track which fds are in user-defined redirections.
This commit is contained in:
ridiculousfish
2021-02-02 20:30:52 -08:00
parent 6c4f2622ef
commit 97f29b1f4d
8 changed files with 81 additions and 36 deletions

View File

@@ -968,7 +968,7 @@ bool exec_job(parser_t &parser, const shared_ptr<job_t> &j, const io_chain_t &bl
autoclose_pipes_t proc_pipes;
proc_pipes.read = std::move(pipe_next_read);
if (!p->is_last_in_job) {
auto pipes = make_autoclose_pipes(conflicts);
auto pipes = make_autoclose_pipes();
if (!pipes) {
FLOGF(warning, PIPE_ERROR);
wperror(L"pipe");