From 486f38d99543c46db7ade80312d28de72605132b Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 13 Mar 2023 22:14:24 +0800 Subject: [PATCH] reactor: pass fd opened in blocking mode to spawned process * pass fds opened in blocking mode to spawned process * do not tolerate test failures in test_spawn_input it turns out tools like "cat" expect fd opened blocking mode. while the pipe fds are always created in non-blocking mode. so in order to appease these tools, let's set the fds passed to the spawned process to blocking mode. Fixes #1320 Signed-off-by: Jianyong Chen Signed-off-by: Kefu Chai --- src/core/reactor.cc | 6 ++++++ tests/unit/spawn_test.cc | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/reactor.cc b/src/core/reactor.cc index 8c753b4f13e..c1c9582c335 100644 --- a/src/core/reactor.cc +++ b/src/core/reactor.cc @@ -1986,6 +1986,12 @@ reactor::spawn(std::string_view pathname, std::get(cin_pipe).spawn_actions_add_close(&actions); std::get(cout_pipe).spawn_actions_add_close(&actions); std::get(cerr_pipe).spawn_actions_add_close(&actions); + // tools like "cat" expect a fd opened in blocking mode when performing I/O + int nonblocking = 0; + std::get(cin_pipe).ioctl(FIONBIO, &nonblocking); + std::get(cout_pipe).ioctl(FIONBIO, &nonblocking); + std::get(cerr_pipe).ioctl(FIONBIO, &nonblocking); + r = ::posix_spawnattr_init(&attr); throw_pthread_error(r); // make sure the following signals are not ignored by the child process diff --git a/tests/unit/spawn_test.cc b/tests/unit/spawn_test.cc index 5a41f7412ab..44141b38b3e 100644 --- a/tests/unit/spawn_test.cc +++ b/tests/unit/spawn_test.cc @@ -92,7 +92,7 @@ SEASTAR_TEST_CASE(test_spawn_echo) { }); } -SEASTAR_TEST_CASE(test_spawn_input, *boost::unit_test::expected_failures(3)) { +SEASTAR_TEST_CASE(test_spawn_input) { static const sstring text = "hello world\n"; return spawn_process("/bin/cat").then([] (auto process) { auto stdin = process.stdin();