Launch server cmd in a new thread to prevent deadlock after sleep commands
This commit is contained in:
+14
-10
@@ -996,23 +996,27 @@ namespace stream {
|
|||||||
});
|
});
|
||||||
|
|
||||||
server->map(packetTypes[IDX_EXEC_SERVER_CMD], [server](session_t *session, const std::string_view &payload) {
|
server->map(packetTypes[IDX_EXEC_SERVER_CMD], [server](session_t *session, const std::string_view &payload) {
|
||||||
BOOST_LOG(debug) << "type [IDX_EXEC_SERVER_CMD]: "sv;
|
BOOST_LOG(debug) << "type [IDX_EXEC_SERVER_CMD]"sv;
|
||||||
uint8_t cmdIndex = *(uint8_t*)payload.data();
|
uint8_t cmdIndex = *(uint8_t*)payload.data();
|
||||||
|
|
||||||
if (cmdIndex < config::sunshine.server_cmds.size()) {
|
if (cmdIndex < config::sunshine.server_cmds.size()) {
|
||||||
const auto& cmd = config::sunshine.server_cmds[cmdIndex];
|
const auto& cmd = config::sunshine.server_cmds[cmdIndex];
|
||||||
BOOST_LOG(info) << "Executing server command: " << cmd.cmd_name;
|
BOOST_LOG(info) << "Executing server command: " << cmd.cmd_name;
|
||||||
|
|
||||||
std::error_code ec;
|
auto exec_thread = std::thread([&cmd]{
|
||||||
auto env = proc::proc.get_env();
|
std::error_code ec;
|
||||||
boost::filesystem::path working_dir = proc::find_working_directory(cmd.cmd_val, env);
|
auto env = proc::proc.get_env();
|
||||||
auto child = platf::run_command(cmd.elevated, true, cmd.cmd_val, working_dir, {}, nullptr, ec, nullptr);
|
boost::filesystem::path working_dir = proc::find_working_directory(cmd.cmd_val, env);
|
||||||
|
auto child = platf::run_command(cmd.elevated, true, cmd.cmd_val, working_dir, env, nullptr, ec, nullptr);
|
||||||
|
|
||||||
if (ec) {
|
if (ec) {
|
||||||
BOOST_LOG(error) << "Failed to execute server command: " << ec.message();
|
BOOST_LOG(error) << "Failed to execute server command: " << ec.message();
|
||||||
} else {
|
} else {
|
||||||
child.detach();
|
child.detach();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
exec_thread.detach();
|
||||||
} else {
|
} else {
|
||||||
BOOST_LOG(error) << "Invalid server command index: " << (int)cmdIndex;
|
BOOST_LOG(error) << "Invalid server command index: " << (int)cmdIndex;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user