Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added handling SIGTERM signal for proper stopping dedicated server #1830

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading