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 committed Oct 7, 2024
1 parent 35ae9f4 commit 061c4a1
Show file tree
Hide file tree
Showing 3 changed files with 22 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
11 changes: 11 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,16 @@ void Posix_Daemonize( void )

}

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

void Posix_SetupSigtermHandling( void )
{
signal( SIGTERM, Posix_SigtermCallback );
}

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

0 comments on commit 061c4a1

Please sign in to comment.