Skip to content

Commit

Permalink
engine: implemented handling SIGTERM signal for proper stopping dedic…
Browse files Browse the repository at this point in the history
…ated server
  • Loading branch information
SNMetamorph authored and a1batross committed Oct 7, 2024
1 parent 35ae9f4 commit 50c8058
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions engine/common/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,9 @@ static void Host_InitCommon( int argc, char **argv, const char *progname, qboole
Host_RunTests( 0 );
#endif

#if XASH_DEDICATED
Platform_SetupSigtermHandling();
#endif
Platform_Init( Host_IsDedicated( ) || developer >= DEV_EXTENDED );
FS_Init( basedir );

Expand Down
8 changes: 8 additions & 0 deletions engine/platform/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void IOS_LaunchDialog( void );

#if XASH_POSIX
void Posix_Daemonize( void );
void Posix_SetupSigtermHandling( void );
#endif

#if XASH_SDL
Expand Down Expand Up @@ -156,6 +157,13 @@ static inline qboolean Sys_DebuggerPresent( void )
#endif
}

static inline void Platform_SetupSigtermHandling( void )
{
#if XASH_POSIX
Posix_SetupSigtermHandling( );
#endif
}

/*
==============================================================================
Expand Down
16 changes: 16 additions & 0 deletions engine/platform/posix/sys_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ GNU General Public License for more details.
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <signal.h>
#include "platform/platform.h"
#include "menu_int.h"

Expand Down Expand Up @@ -145,6 +146,21 @@ void Posix_Daemonize( void )

}

static void Posix_SigtermCallback( int signal )
{
Sys_Quit();
}

void Posix_SetupSigtermHandling( void )
{
#if !XASH_PSVITA
struct sigaction act = { 0 };
act.sa_handler = Posix_SigtermCallback;
act.sa_flags = 0;
sigaction( SIGTERM, &act, NULL );
#endif
}

#if XASH_TIMER == TIMER_POSIX
double Platform_DoubleTime( void )
{
Expand Down

0 comments on commit 50c8058

Please sign in to comment.