Fix the signal handler.

The signal handler was always fishy since it modified the global process
state but worked on all common platforms. libcurl turns the process into
a multithreaded environment, thus breaking that fragile construction.
After the signal handler was called the global state is inconsistent and
there's a high chance of things going wrong. For example at the net curl
download or when setjmp() is called in Qcommon_Frame().
This commit is contained in:
Yamagi Burmeister 2018-12-18 19:53:23 +01:00
parent 95c1bb9972
commit 7b200208c5
2 changed files with 23 additions and 1 deletions

View file

@ -118,10 +118,12 @@ signalhandler(int sig)
raise(sig); raise(sig);
} }
extern qboolean quitnextframe;
void void
terminate(int sig) terminate(int sig)
{ {
Cbuf_AddText("quit"); quitnextframe = true;
} }
void void

View file

@ -76,6 +76,10 @@ qboolean is_portable;
// Game given by user // Game given by user
char userGivenGame[MAX_QPATH]; char userGivenGame[MAX_QPATH];
// Game should quit next frame.
// Hack for the signal handlers.
qboolean quitnextframe;
// ---- // ----
static void static void
@ -424,6 +428,14 @@ Qcommon_Frame(int msec)
static qboolean last_was_packetframe; static qboolean last_was_packetframe;
/* Tells the client to shutdown.
Used by the signal handlers. */
if (quitnextframe)
{
Cbuf_AddText("quit");
}
/* In case of ERR_DROP we're jumping here. Don't know /* In case of ERR_DROP we're jumping here. Don't know
if that' really save but it seems to work. So leave if that' really save but it seems to work. So leave
it alone. */ it alone. */
@ -731,6 +743,14 @@ Qcommon_Frame(int msec)
qboolean packetframe = true; qboolean packetframe = true;
/* Tells the client to shutdown.
Used by the signal handlers. */
if (quitnextframe)
{
Cbuf_AddText("quit");
}
/* In case of ERR_DROP we're jumping here. Don't know /* In case of ERR_DROP we're jumping here. Don't know
if that' really save but it seems to work. So leave if that' really save but it seems to work. So leave
it alone. */ it alone. */