diff --git a/src/runner.cpp b/src/runner.cpp index dbece25..28a55d2 100644 --- a/src/runner.cpp +++ b/src/runner.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -19,6 +20,10 @@ run_result runner::run_blocking(const program &program) { throw std::system_error{errno, std::generic_category()}; } + // Avoid blocking on stdin, and being interrupted if the pipe is closed prematurely + int flags = fcntl(in_pipe[1], F_GETFL, 0); + fcntl(in_pipe[1], F_SETFL, flags | O_NONBLOCK); + posix_spawn_file_actions_t actions; posix_spawn_file_actions_init(&actions); posix_spawn_file_actions_addclose(&actions, in_pipe[1]);