diff --git a/src/io.cpp b/src/io.cpp index 54a8218da..8ca1da89f 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -301,7 +301,7 @@ fd_set_t io_chain_t::fd_set() const { return result; } -autoclose_fd_t move_fd_to_unused(autoclose_fd_t fd, const fd_set_t &fdset, bool cloexec) { +autoclose_fd_t move_fd_to_unused(autoclose_fd_t fd, const fd_set_t &fdset) { if (!fd.valid() || !fdset.contains(fd.fd())) { return fd; } @@ -319,8 +319,8 @@ autoclose_fd_t move_fd_to_unused(autoclose_fd_t fd, const fd_set_t &fdset, bool return autoclose_fd_t{}; } // Ok, we have a new candidate fd. Recurse. - if (cloexec) set_cloexec(tmp_fd); - return move_fd_to_unused(autoclose_fd_t{tmp_fd}, fdset, cloexec); + set_cloexec(tmp_fd); + return move_fd_to_unused(autoclose_fd_t{tmp_fd}, fdset); } maybe_t make_autoclose_pipes(const fd_set_t &fdset) { @@ -334,10 +334,10 @@ maybe_t make_autoclose_pipes(const fd_set_t &fdset) { set_cloexec(pipes[0]); set_cloexec(pipes[1]); - auto read = move_fd_to_unused(autoclose_fd_t{pipes[0]}, fdset, true); + auto read = move_fd_to_unused(autoclose_fd_t{pipes[0]}, fdset); if (!read.valid()) return none(); - auto write = move_fd_to_unused(autoclose_fd_t{pipes[1]}, fdset, true); + auto write = move_fd_to_unused(autoclose_fd_t{pipes[1]}, fdset); if (!write.valid()) return none(); return autoclose_pipes_t(std::move(read), std::move(write)); diff --git a/src/io.h b/src/io.h index b5dd366cb..3af5934d2 100644 --- a/src/io.h +++ b/src/io.h @@ -387,10 +387,9 @@ struct autoclose_pipes_t { maybe_t make_autoclose_pipes(const fd_set_t &fdset); /// If the given fd is present in \p fdset, duplicates it repeatedly until an fd not used in the set -/// is found or we run out. If we return a new fd or an error, closes the old one. If \p cloexec is -/// set, any fd created is marked close-on-exec. \returns -1 on failure (in which case the given fd -/// is still closed). -autoclose_fd_t move_fd_to_unused(autoclose_fd_t fd, const fd_set_t &fdset, bool cloexec = true); +/// is found or we run out. If we return a new fd or an error, closes the old one. Marks the fd as +/// cloexec. \returns invalid fd on failure (in which case the given fd is still closed). +autoclose_fd_t move_fd_to_unused(autoclose_fd_t fd, const fd_set_t &fdset); /// Class representing the output that a builtin can generate. class output_stream_t {