From df19364adef814237b8afd156d3bd1a33d16b318 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 4 Sep 2024 13:38:49 +0300 Subject: Turn standard streams into blocking mode on start (GH issue 417) --- bdep/bdep.cxx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/bdep/bdep.cxx b/bdep/bdep.cxx index 02912d0..cc9ac17 100644 --- a/bdep/bdep.cxx +++ b/bdep/bdep.cxx @@ -12,6 +12,7 @@ #include // set_terminate(), terminate_handler #include // enable_if, is_base_of +#include // std*_fdmode() #include // backtrace() #include @@ -408,6 +409,24 @@ try default_terminate = set_terminate (custom_terminate); + // Note that the standard stream descriptors can potentially be in the + // non-blocking mode, which the C++ streams are not suited for and which are + // not fully supported by butl::iofdstreams. Using such descriptors may lead + // to various weird failures (see GH issue #417 for the reproducer). Thus, + // we just turn such descriptors into the blocking mode at the beginning of + // the program execution. + // + try + { + stdin_fdmode (fdstream_mode::blocking); + stdout_fdmode (fdstream_mode::blocking); + stderr_fdmode (fdstream_mode::blocking); + } + catch (const io_error& e) + { + fail << "unable to turn standard streams into blocking mode: " << e; + } + if (fdterm (stderr_fd ())) { stderr_term = std::getenv ("TERM"); -- cgit v1.1