Implement the Wine host process watchdog

This will shut down a bridge's sockets when the connected native host
process exits, to prevent dangling Wine processes.
This commit is contained in:
Robbert van der Helm
2021-05-01 17:54:22 +02:00
parent e912bdd302
commit 832089d4d1
8 changed files with 52 additions and 13 deletions
+18 -2
View File
@@ -16,13 +16,17 @@
#include "common.h"
#include <iostream>
#include "../editor.h"
HostBridge::HostBridge(MainContext& main_context,
boost::filesystem::path plugin_path)
boost::filesystem::path plugin_path,
pid_t parent_pid)
: plugin_path(plugin_path),
main_context(main_context),
generic_logger(Logger::create_wine_stderr()),
parent_pid(parent_pid),
watchdog_guard(main_context.register_watchdog(*this)) {}
void HostBridge::handle_win32_events() {
@@ -37,5 +41,17 @@ void HostBridge::handle_win32_events() {
}
void HostBridge::shutdown_if_dangling() {
// TODO: Implement
// If the parent process has exited and this plugin bridge instance is
// outliving the process it's supposed to be connected to (because in some
// situations sockets won't get closed when this happens so we'd hang on
// `recv()`), then we'll close the sockets here so that the plugin bridge
// exits gracefully. This will be periodically called from `MainContext`'s
// watchdog thread.
if (!pid_running(parent_pid)) {
std::cerr << "WARNING: The native plugin host seems to have died."
<< std::endl;
std::cerr << " This bridge will shut down now." << std::endl;
close_sockets();
}
}