mirror of
https://github.com/LizardByte/Sunshine.git
synced 2025-08-10 00:52:16 +00:00
Implement graceful termination and group-based app tracking
This commit is contained in:
@@ -249,6 +249,33 @@ namespace platf {
|
||||
lifetime::exit_sunshine(0, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Attempt to gracefully terminate a process group.
|
||||
* @param native_handle The process group ID.
|
||||
* @return true if termination was successfully requested.
|
||||
*/
|
||||
bool
|
||||
request_process_group_exit(std::uintptr_t native_handle) {
|
||||
if (kill(-((pid_t) native_handle), SIGTERM) == 0 || errno == ESRCH) {
|
||||
BOOST_LOG(debug) << "Successfully sent SIGTERM to process group: "sv << native_handle;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
BOOST_LOG(warning) << "Unable to send SIGTERM to process group ["sv << native_handle << "]: "sv << errno;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks if a process group still has running children.
|
||||
* @param native_handle The process group ID.
|
||||
* @return true if processes are still running.
|
||||
*/
|
||||
bool
|
||||
process_group_running(std::uintptr_t native_handle) {
|
||||
return waitpid(-((pid_t) native_handle), nullptr, WNOHANG) >= 0;
|
||||
}
|
||||
|
||||
struct sockaddr_in
|
||||
to_sockaddr(boost::asio::ip::address_v4 address, uint16_t port) {
|
||||
struct sockaddr_in saddr_v4 = {};
|
||||
|
||||
Reference in New Issue
Block a user