diff --git a/src/common/serialization/common.h b/src/common/serialization/common.h index a427ac2c..bb6ea91f 100644 --- a/src/common/serialization/common.h +++ b/src/common/serialization/common.h @@ -50,12 +50,14 @@ struct HostRequest { PluginType plugin_type; std::string plugin_path; std::string endpoint_base_dir; + pid_t parent_pid; template void serialize(S& s) { s.object(plugin_type); s.text1b(plugin_path, 4096); s.text1b(endpoint_base_dir, 4096); + s.value4b(parent_pid); } }; diff --git a/src/plugin/bridges/common.h b/src/plugin/bridges/common.h index fadb2aa6..cdac9a80 100644 --- a/src/plugin/bridges/common.h +++ b/src/plugin/bridges/common.h @@ -76,7 +76,8 @@ class PluginBridge { HostRequest{ .plugin_type = plugin_type, .plugin_path = info.windows_plugin_path.string(), - .endpoint_base_dir = sockets.base_dir.string()}, + .endpoint_base_dir = sockets.base_dir.string(), + .parent_pid = getpid()}, sockets, *config.group)) : std::unique_ptr( @@ -88,7 +89,8 @@ class PluginBridge { .plugin_type = plugin_type, .plugin_path = info.windows_plugin_path.string(), - .endpoint_base_dir = sockets.base_dir.string()}, + .endpoint_base_dir = sockets.base_dir.string(), + .parent_pid = getpid()}, sockets))), has_realtime_priority(has_realtime_priority_promise.get_future()), wine_io_handler([&]() { diff --git a/src/plugin/host-process.cpp b/src/plugin/host-process.cpp index 7158cd32..ae0a14e0 100644 --- a/src/plugin/host-process.cpp +++ b/src/plugin/host-process.cpp @@ -83,6 +83,10 @@ IndividualHost::IndividualHost(boost::asio::io_context& io_context, host_request.plugin_path, #endif host_request.endpoint_base_dir, + // We pass this process' process ID as an argument so we can run a + // watchdog on the Wine plugin host process that shuts down the + // sockets after this process shuts down + std::to_string(getpid()), bp::env = plugin_info.create_host_env(), bp::std_out = stdout_pipe, bp::std_err = stderr_pipe diff --git a/src/wine-host/individual-host.cpp b/src/wine-host/individual-host.cpp index aadf0d01..059a942c 100644 --- a/src/wine-host/individual-host.cpp +++ b/src/wine-host/individual-host.cpp @@ -39,20 +39,20 @@ __cdecl main(int argc, char* argv[]) { set_realtime_priority(true); - // We pass plugin format, the name of the VST2 plugin .dll file or VST3 - // bundle to load, and the base directory for the Unix domain socket - // endpoints to connect to as the first two arguments of this process in - // `src/plugin/host-process.cpp` - if (argc < 4) { - std::cerr - << "Usage: " + // We pass the plugin format, the name of the VST2 plugin .dll file or VST3 + // bundle to load, the base directory for the Unix domain socket endpoints + // to connect to and the process ID of the process the native plugin is + // being hosted in as arguments for yabridge-host.exe + if (argc < 5) { + std::cerr << "Usage: " #ifdef __i386__ - << yabridge_individual_host_name_32bit + << yabridge_individual_host_name_32bit #else - << yabridge_individual_host_name + << yabridge_individual_host_name #endif - << " " - << std::endl; + << " " + " " + << std::endl; return 1; } @@ -61,6 +61,7 @@ __cdecl const PluginType plugin_type = plugin_type_from_string(plugin_type_str); const std::string plugin_location(argv[2]); const std::string socket_endpoint_path(argv[3]); + const pid_t parent_pid = std::stoi(argv[4]); std::cout << "Initializing yabridge host version " << yabridge_git_version #ifdef __i386__