mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-03-15 23:22:53 +08:00
Always mark pipes as cloexec
There is never a reason to keep these open in exec.
This commit is contained in:
parent
b784a0caa3
commit
d0cefe8b65
10
src/io.cpp
10
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<autoclose_pipes_t> make_autoclose_pipes(const fd_set_t &fdset) {
|
||||
@ -334,10 +334,10 @@ maybe_t<autoclose_pipes_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));
|
||||
|
7
src/io.h
7
src/io.h
@ -387,10 +387,9 @@ struct autoclose_pipes_t {
|
||||
maybe_t<autoclose_pipes_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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user