Move piping stream lines to the log to common

This commit is contained in:
Robbert van der Helm
2021-02-12 18:35:07 +01:00
parent dd0eb02970
commit a1bb522ea0
7 changed files with 64 additions and 100 deletions
+4 -24
View File
@@ -19,7 +19,6 @@
#include "../boost-fix.h"
#include <unistd.h>
#include <boost/asio/read_until.hpp>
#include <boost/process/environment.hpp>
#include <regex>
@@ -101,8 +100,10 @@ GroupBridge::GroupBridge(boost::filesystem::path group_socket_path)
// Write this process's original STDOUT and STDERR streams to the logger
// TODO: This works for output generated by plugins, but not for debug
// messages generated by wineserver. Is it possible to catch those?
async_log_pipe_lines(stdout_redirect.pipe, stdout_buffer, "[STDOUT] ");
async_log_pipe_lines(stderr_redirect.pipe, stderr_buffer, "[STDERR] ");
logger.async_log_pipe_lines(stdout_redirect.pipe, stdout_buffer,
"[STDOUT] ");
logger.async_log_pipe_lines(stderr_redirect.pipe, stderr_buffer,
"[STDERR] ");
stdio_handler = Win32Thread([&]() {
// In case a plugin generates a lot of FIXMEs relaying this IO with
@@ -300,27 +301,6 @@ void GroupBridge::async_handle_events() {
[&]() { return !is_event_loop_inhibited(); });
}
void GroupBridge::async_log_pipe_lines(
boost::asio::posix::stream_descriptor& pipe,
boost::asio::streambuf& buffer,
std::string prefix) {
boost::asio::async_read_until(
pipe, buffer, '\n',
[&, prefix](const boost::system::error_code& error, size_t) {
// When we get an error code then that likely means that the pipe
// has been clsoed and we have reached the end of the file
if (error.failed()) {
return;
}
std::string line;
std::getline(std::istream(&buffer), line);
logger.log(prefix + line);
async_log_pipe_lines(pipe, buffer, prefix);
});
}
boost::asio::local::stream_protocol::acceptor create_acceptor_if_inactive(
boost::asio::io_context& io_context,
boost::asio::local::stream_protocol::endpoint& endpoint) {
+3 -20
View File
@@ -16,15 +16,12 @@
#pragma once
#include <atomic>
#include <thread>
#include "../boost-fix.h"
#include <boost/asio/local/stream_protocol.hpp>
#include <boost/asio/posix/stream_descriptor.hpp>
#include <boost/asio/streambuf.hpp>
#include <boost/filesystem.hpp>
#include <atomic>
#include <thread>
#include "../common/logging/common.h"
#include "../utils.h"
@@ -190,20 +187,6 @@ class GroupBridge {
*/
void async_handle_events();
/**
* Continuously read from a pipe and write the output to the log file. Used
* with the IO streams captured by `stdout_redirect` and `stderr_redirect`.
*
* TODO: Merge this with `HostProcess::async_log_pipe_lines`
*
* @param pipe The pipe to read from.
* @param buffer The stream buffer to write to.
* @param prefix Text to prepend to the line before writing to the log.
*/
void async_log_pipe_lines(boost::asio::posix::stream_descriptor& pipe,
boost::asio::streambuf& buffer,
std::string prefix);
/**
* The logging facility used for this group host process. Since we can't
* identify which plugin is generating (debug) output, every line will only