Skip to content

Commit

Permalink
Graceful shutdown on sigterm (#776)
Browse files Browse the repository at this point in the history
* Add players kick on SIGINT \ SIGTERM
* Add SIGINT & SIGTERM handling linux console
* change shutdown method
  • Loading branch information
wopox1337 authored Aug 19, 2020
1 parent 98db467 commit 376bc15
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
16 changes: 14 additions & 2 deletions rehlds/dedicated/src/sys_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,21 @@ char* BuildCmdLine(int argc, char **argv)
return linuxCmdline;
}

static void ConsoleCtrlHandler(int signal)
{
if (signal == SIGINT || signal == SIGTERM)
{
g_bAppHasBeenTerminated = true;
}
}

bool Sys_SetupConsole()
{
struct sigaction action;
action.sa_handler = ConsoleCtrlHandler;
sigaction(SIGINT, &action, NULL);
sigaction(SIGTERM, &action, NULL);

return true;
}

Expand All @@ -327,7 +340,6 @@ int main(int argc, char *argv[])
{
Q_snprintf(g_szEXEName, sizeof(g_szEXEName), "%s", argv[0]);
char* cmdline = BuildCmdLine(argc, argv);
StartServer(cmdline);

return 0;
return StartServer(cmdline) == LAUNCHER_OK ? EXIT_SUCCESS : EXIT_FAILURE;
}
5 changes: 5 additions & 0 deletions rehlds/engine/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,12 @@ void Host_Shutdown(void)
if (host_initialized) // Client-side
Host_WriteConfiguration();

#ifdef REHLDS_FIXES
Host_ShutdownServer(FALSE);
#else
SV_ServerShutdown();
#endif

Voice_Deinit();
host_initialized = FALSE;

Expand Down

0 comments on commit 376bc15

Please sign in to comment.