Fall back to /dev/stderr instead of std::cerr

This allows us to remap STDIO internally in the group process.
This commit is contained in:
Robbert van der Helm
2020-05-17 18:35:40 +02:00
parent df2c4c29a9
commit 0ad849a42f
+6 -1
View File
@@ -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::ostream>(&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<std::ofstream>("/dev/stderr"),
verbosity_level, prefix);
}
}