From 0ad849a42fed3a810d05c577047faf762155ce8f Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sun, 17 May 2020 18:35:40 +0200 Subject: [PATCH] Fall back to /dev/stderr instead of std::cerr This allows us to remap STDIO internally in the group process. --- src/common/logging.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/common/logging.cpp b/src/common/logging.cpp index 6950dd26..d8e9b892 100644 --- a/src/common/logging.cpp +++ b/src/common/logging.cpp @@ -72,7 +72,12 @@ Logger Logger::create_from_environment(std::string prefix) { if (log_file->is_open()) { return Logger(log_file, verbosity_level, prefix); } else { - return Logger(std::shared_ptr(&std::cerr, [](auto) {}), + // For STDERR we sadly can't just use `std::cerr`. In the group process + // we need to capture all output generated by the process itself, and + // the only way to do this is by reopening the STDERR and STDOUT streams + // to a pipe. Luckily `/dev/stderr` stays unaffected, so we can still + // write there without causing infinite loops. + return Logger(std::make_shared("/dev/stderr"), verbosity_level, prefix); } }