Clean up how pipe fd avoidance works

fish has to ensure that the pipes it creates do not conflict with any
explicit fds named in redirections. Switch this code to using
autoclose_fd_t to make the ownership logic more explicit, and also
introduce fd_set_t to reduce the dependence on io_chain_t.
This commit is contained in:
ridiculousfish
2019-12-12 14:42:03 -08:00
parent 4e52feb51a
commit be685faeb8
5 changed files with 104 additions and 94 deletions

View File

@@ -1031,7 +1031,7 @@ static void test_parser() {
}
static void test_1_cancellation(const wchar_t *src) {
auto filler = io_bufferfill_t::create(io_chain_t{});
auto filler = io_bufferfill_t::create(fd_set_t{});
pthread_t thread = pthread_self();
double delay = 0.25 /* seconds */;
iothread_perform([=]() {
@@ -3188,6 +3188,21 @@ static void test_input() {
}
}
static void test_fd_set() {
say(L"Testing fd_set");
fd_set_t fds;
do_test(!fds.contains(0));
do_test(!fds.contains(100));
fds.add(1);
do_test(!fds.contains(0));
do_test(!fds.contains(100));
do_test(fds.contains(1));
fds.add(1);
do_test(!fds.contains(0));
do_test(!fds.contains(100));
do_test(fds.contains(1));
}
static void test_line_iterator() {
say(L"Testing line iterator");
@@ -5518,6 +5533,7 @@ int main(int argc, char **argv) {
if (should_test_function("complete")) test_complete();
if (should_test_function("autoload")) test_autoload();
if (should_test_function("input")) test_input();
if (should_test_function("io")) test_fd_set();
if (should_test_function("line_iterator")) test_line_iterator();
if (should_test_function("universal")) test_universal();
if (should_test_function("universal")) test_universal_output();