Skip to content

Commit

Permalink
reactor: pass fd opened in blocking mode to spawned process
Browse files Browse the repository at this point in the history
* 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 scylladb#1320
Signed-off-by: Jianyong Chen <baluschch@gmail.com>
Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
  • Loading branch information
tchaikov committed Mar 13, 2023
1 parent 58a4e90 commit 486f38d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/core/reactor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1986,6 +1986,12 @@ reactor::spawn(std::string_view pathname,
std::get<pipefd_read_end>(cin_pipe).spawn_actions_add_close(&actions);
std::get<pipefd_write_end>(cout_pipe).spawn_actions_add_close(&actions);
std::get<pipefd_write_end>(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<pipefd_read_end>(cin_pipe).ioctl(FIONBIO, &nonblocking);
std::get<pipefd_write_end>(cout_pipe).ioctl(FIONBIO, &nonblocking);
std::get<pipefd_write_end>(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
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/spawn_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 486f38d

Please sign in to comment.