Merge remote-tracking branch 'origin/master' into time

This commit is contained in:
James R 2019-12-24 11:02:31 -08:00
commit d1f12347cc
4 changed files with 124 additions and 19 deletions

View file

@ -562,9 +562,6 @@ void D_SRB2Loop(void)
// Pushing of + parameters is now done back in D_SRB2Main, not here. // Pushing of + parameters is now done back in D_SRB2Main, not here.
CONS_Printf("I_StartupKeyboard()...\n");
I_StartupKeyboard();
#ifdef _WINDOWS #ifdef _WINDOWS
CONS_Printf("I_StartupMouse()...\n"); CONS_Printf("I_StartupMouse()...\n");
I_DoStartupMouse(); I_DoStartupMouse();

View file

@ -184,10 +184,6 @@ void I_StartupMouse(void);
*/ */
void I_StartupMouse2(void); void I_StartupMouse2(void);
/** \brief keyboard startup, shutdown, handler
*/
void I_StartupKeyboard(void);
/** \brief setup timer irq and user timer routine. /** \brief setup timer irq and user timer routine.
*/ */
void I_StartupTimer(void); void I_StartupTimer(void);

View file

@ -238,6 +238,7 @@ int main(int argc, char **argv)
#endif #endif
MakeCodeWritable(); MakeCodeWritable();
#endif #endif
// startup SRB2 // startup SRB2
CONS_Printf("Setting up SRB2...\n"); CONS_Printf("Setting up SRB2...\n");
D_SRB2Main(); D_SRB2Main();

View file

@ -102,6 +102,12 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T);
#endif #endif
#endif #endif
#if (defined (__unix__) && !defined (_MSDOS)) || defined (UNIXCOMMON)
#include <errno.h>
#include <sys/wait.h>
#define NEWSIGNALHANDLER
#endif
#ifndef NOMUMBLE #ifndef NOMUMBLE
#ifdef __linux__ // need -lrt #ifdef __linux__ // need -lrt
#include <sys/mman.h> #include <sys/mman.h>
@ -229,13 +235,11 @@ SDL_bool framebuffer = SDL_FALSE;
UINT8 keyboard_started = false; UINT8 keyboard_started = false;
FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) static void I_ReportSignal(int num, int coredumped)
{ {
//static char msg[] = "oh no! back to reality!\r\n"; //static char msg[] = "oh no! back to reality!\r\n";
const char * sigmsg; const char * sigmsg;
char sigdef[32]; char msg[128];
D_QuitNetGame(); // Fix server freezes
switch (num) switch (num)
{ {
@ -261,20 +265,41 @@ FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num)
sigmsg = "SIGABRT - abnormal termination triggered by abort call"; sigmsg = "SIGABRT - abnormal termination triggered by abort call";
break; break;
default: default:
sprintf(sigdef,"signal number %d", num); sprintf(msg,"signal number %d", num);
sigmsg = sigdef; if (coredumped)
sigmsg = 0;
else
sigmsg = msg;
} }
I_OutputMsg("\nsignal_handler() error: %s\n", sigmsg); if (coredumped)
{
if (sigmsg)
sprintf(msg, "%s (core dumped)", sigmsg);
else
strcat(msg, " (core dumped)");
sigmsg = msg;
}
I_OutputMsg("\nProcess killed by signal: %s\n\n", sigmsg);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Signal caught", "Process killed by signal",
sigmsg, NULL); sigmsg, NULL);
}
#ifndef NEWSIGNALHANDLER
FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num)
{
D_QuitNetGame(); // Fix server freezes
I_ReportSignal(num, 0);
I_ShutdownSystem(); I_ShutdownSystem();
signal(num, SIG_DFL); //default signal action signal(num, SIG_DFL); //default signal action
raise(num); raise(num);
I_Quit(); I_Quit();
} }
#endif
FUNCNORETURN static ATTRNORETURN void quit_handler(int num) FUNCNORETURN static ATTRNORETURN void quit_handler(int num)
{ {
@ -650,7 +675,7 @@ static inline void I_ShutdownConsole(void){}
// //
// StartupKeyboard // StartupKeyboard
// //
void I_StartupKeyboard (void) void I_RegisterSignals (void)
{ {
#ifdef SIGINT #ifdef SIGINT
signal(SIGINT , quit_handler); signal(SIGINT , quit_handler);
@ -664,10 +689,12 @@ void I_StartupKeyboard (void)
// If these defines don't exist, // If these defines don't exist,
// then compilation would have failed above us... // then compilation would have failed above us...
#ifndef NEWSIGNALHANDLER
signal(SIGILL , signal_handler); signal(SIGILL , signal_handler);
signal(SIGSEGV , signal_handler); signal(SIGSEGV , signal_handler);
signal(SIGABRT , signal_handler); signal(SIGABRT , signal_handler);
signal(SIGFPE , signal_handler); signal(SIGFPE , signal_handler);
#endif
} }
// //
@ -2139,6 +2166,85 @@ void I_Sleep(void)
SDL_Delay(cv_sleep.value); SDL_Delay(cv_sleep.value);
} }
#ifdef NEWSIGNALHANDLER
static void newsignalhandler_Warn(const char *pr)
{
char text[128];
snprintf(text, sizeof text,
"Error while setting up signal reporting: %s: %s",
pr,
strerror(errno)
);
I_OutputMsg("%s\n", text);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Startup error",
text, NULL);
I_ShutdownConsole();
exit(-1);
}
static void I_Fork(void)
{
int child;
int status;
int signum;
int c;
child = fork();
switch (child)
{
case -1:
newsignalhandler_Warn("fork()");
break;
case 0:
break;
default:
if (logstream)
fclose(logstream);/* the child has this */
c = wait(&status);
#ifdef LOGMESSAGES
/* By the way, exit closes files. */
logstream = fopen(logfilename, "at");
#else
logstream = 0;
#endif
if (c == -1)
{
kill(child, SIGKILL);
newsignalhandler_Warn("wait()");
}
else
{
if (WIFSIGNALED (status))
{
signum = WTERMSIG (status);
#ifdef WCOREDUMP
I_ReportSignal(signum, WCOREDUMP (status));
#else
I_ReportSignal(signum, 0);
#endif
status = 128 + signum;
}
else if (WIFEXITED (status))
{
status = WEXITSTATUS (status);
}
I_ShutdownConsole();
exit(status);
}
}
}
#endif/*NEWSIGNALHANDLER*/
INT32 I_StartupSystem(void) INT32 I_StartupSystem(void)
{ {
SDL_version SDLcompiled; SDL_version SDLcompiled;
@ -2146,6 +2252,10 @@ INT32 I_StartupSystem(void)
SDL_VERSION(&SDLcompiled) SDL_VERSION(&SDLcompiled)
SDL_GetVersion(&SDLlinked); SDL_GetVersion(&SDLlinked);
I_StartupConsole(); I_StartupConsole();
#ifdef NEWSIGNALHANDLER
I_Fork();
#endif
I_RegisterSignals();
I_OutputMsg("Compiled for SDL version: %d.%d.%d\n", I_OutputMsg("Compiled for SDL version: %d.%d.%d\n",
SDLcompiled.major, SDLcompiled.minor, SDLcompiled.patch); SDLcompiled.major, SDLcompiled.minor, SDLcompiled.patch);
I_OutputMsg("Linked with SDL version: %d.%d.%d\n", I_OutputMsg("Linked with SDL version: %d.%d.%d\n",
@ -2169,7 +2279,6 @@ void I_Quit(void)
if (quiting) goto death; if (quiting) goto death;
SDLforceUngrabMouse(); SDLforceUngrabMouse();
quiting = SDL_FALSE; quiting = SDL_FALSE;
I_ShutdownConsole();
M_SaveConfig(NULL); //save game config, cvars.. M_SaveConfig(NULL); //save game config, cvars..
#ifndef NONET #ifndef NONET
D_SaveBan(); // save the ban list D_SaveBan(); // save the ban list
@ -2287,8 +2396,6 @@ void I_Error(const char *error, ...)
I_OutputMsg("\nI_Error(): %s\n", buffer); I_OutputMsg("\nI_Error(): %s\n", buffer);
// --- // ---
I_ShutdownConsole();
M_SaveConfig(NULL); // save game config, cvars.. M_SaveConfig(NULL); // save game config, cvars..
#ifndef NONET #ifndef NONET
D_SaveBan(); // save the ban list D_SaveBan(); // save the ban list
@ -2430,6 +2537,10 @@ void I_ShutdownSystem(void)
{ {
INT32 c; INT32 c;
#ifndef NEWSIGNALHANDLER
I_ShutdownConsole();
#endif
for (c = MAX_QUIT_FUNCS-1; c >= 0; c--) for (c = MAX_QUIT_FUNCS-1; c >= 0; c--)
if (quit_funcs[c]) if (quit_funcs[c])
(*quit_funcs[c])(); (*quit_funcs[c])();