ref: faa2a505ba7ee8c17679b208e4bfb6b30623a332
parent: 3bbed813e4ee72bd7fcf974e17835ab07c2b74b4
author: Simon Howard <[email protected]>
date: Wed Sep 7 17:40:28 EDT 2005
Catch signals and exit cleanly Subversion-branch: /trunk/chocolate-doom Subversion-revision: 86
--- a/src/i_main.c
+++ b/src/i_main.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: i_main.c 57 2005-08-30 22:11:10Z fraggle $
+// $Id: i_main.c 86 2005-09-07 21:40:28Z fraggle $
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005 Simon Howard
@@ -22,6 +22,9 @@
// 02111-1307, USA.
//
// $Log$
+// Revision 1.4 2005/09/07 21:40:28 fraggle
+// Catch signals and exit cleanly
+//
// Revision 1.3 2005/08/30 22:11:10 fraggle
// Windows fixes
//
@@ -38,19 +41,22 @@
//-----------------------------------------------------------------------------
static const char
-rcsid[] = "$Id: i_main.c 57 2005-08-30 22:11:10Z fraggle $";
+rcsid[] = "$Id: i_main.c 86 2005-09-07 21:40:28Z fraggle $";
+#include <signal.h>
#include "doomdef.h"
-
+#include "i_system.h"
#include "m_argv.h"
#include "d_main.h"
-int
-main
-( int argc,
- char** argv )
+void SignalHandler(int signum)
+{
+ I_Error("Aborting due to signal %i\n", signum);
+}
+
+int main(int argc, char **argv)
{
// save arguments
@@ -58,6 +64,17 @@
myargc = argc;
myargv = argv;
+ signal(SIGSEGV, SignalHandler);
+ signal(SIGTERM, SignalHandler);
+ signal(SIGILL, SignalHandler);
+ signal(SIGINT, SignalHandler);
+ signal(SIGFPE, SignalHandler);
+ signal(SIGABRT, SignalHandler);
+ signal(SIGHUP, SignalHandler);
+#ifdef SIGPIPE
+ signal(SIGHUP, SignalHandler);
+#endif
+
#ifdef _WIN32
// restore stdout/stderr
@@ -65,6 +82,7 @@
freopen("CON", "w", stderr);
#endif
+
// start doom
D_DoomMain ();