From c6cf8e526961eac7ce52d803b14373bc4f469158 Mon Sep 17 00:00:00 2001 From: Marcus Minhorst Date: Tue, 19 Aug 2025 20:25:15 -0400 Subject: [PATCH] Added signal handler --- src/common/platform/posix/sdl/st_start.cpp | 28 ++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/common/platform/posix/sdl/st_start.cpp b/src/common/platform/posix/sdl/st_start.cpp index 4653f4ff9..65b1d2cf1 100644 --- a/src/common/platform/posix/sdl/st_start.cpp +++ b/src/common/platform/posix/sdl/st_start.cpp @@ -4,6 +4,7 @@ ** **--------------------------------------------------------------------------- ** Copyright 2006-2007 Randy Heit +** Copyright 2017-2025 GZDoom Maintainers and Contributors ** All rights reserved. ** ** Redistribution and use in source and binary forms, with or without @@ -34,14 +35,14 @@ // HEADER FILES ------------------------------------------------------------ -#include +#include +#include #include #include +#include +#include "basics.h" #include "st_start.h" -#include "i_system.h" -#include "c_cvars.h" -#include "engineerrors.h" // MACROS ------------------------------------------------------------------ @@ -268,6 +269,12 @@ int FTTYStartupScreen::GetNetBanClient() return -1; } +static volatile sig_atomic_t netloop_running; +void netloop_handler(int signal) +{ + netloop_running = false; +} + //=========================================================================== // // FTTYStartupScreen :: NetLoop @@ -290,7 +297,10 @@ bool FTTYStartupScreen::NetLoop(bool (*loopCallback)(void *), void *data) char k; bool stdin_eof = false; - for (;;) + netloop_running = true; + auto previous_handler = std::signal(SIGINT, netloop_handler); + + while (netloop_running) { // Don't flood the network with packets on startup. tv.tv_sec = 0; @@ -328,11 +338,15 @@ bool FTTYStartupScreen::NetLoop(bool (*loopCallback)(void *), void *data) { if (k == 'q' || k == 'Q') { - fprintf (stderr, "\nNetwork game synchronization aborted."); - return false; + netloop_running = false; } } } } + + std::signal(SIGINT, previous_handler); + + fprintf (stderr, "\nNetwork game synchronization aborted."); + return false; }