diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/Makefile.am | 2 | ||||
-rw-r--r-- | src/core/applicationinterface.cc | 30 |
2 files changed, 30 insertions, 2 deletions
diff --git a/src/core/Makefile.am b/src/core/Makefile.am index b062f9e..8046b79 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -4,7 +4,7 @@ INCLUDES = -I$(top_srcdir)/src libcore_la_SOURCES = applicationinterface.cc gameinterface.cc libcore_la_LDFLAGS = -avoid-version libcore_la_LIBADD = $(top_builddir)/src/math/libmath.la \ - $(top_builddir)/src/common/libcommon.la \ + $(top_builddir)/src/common/libcommon.la $(top_builddir)/src/sys/libsys.la \ $(top_builddir)/src/filesystem/libfilesystem.la noinst_LTLIBRARIES = libcore.la diff --git a/src/core/applicationinterface.cc b/src/core/applicationinterface.cc index 9ef5c16..ba22d8c 100644 --- a/src/core/applicationinterface.cc +++ b/src/core/applicationinterface.cc @@ -6,14 +6,37 @@ #include "core/core.h" #include "filesystem/filesystem.h" +#include "sys/sys.h" #include "common/common.h" #include <iostream> #include <stdlib.h> +#include <errno.h> +#include <signal.h> + namespace core { +extern "C" void signal_handler(int signum) +{ + switch(signum){ + case SIGHUP: + case SIGINT: + case SIGQUIT: + case SIGTERM: + con_warn << "received signal " << signum << ", shutting down..." << std::endl; + if (ApplicationInterface::instance()); + ApplicationInterface::instance()->shutdown(); + exit(1); + break; + default: + con_warn << "received signal " << signum << ", terminated..." << std::endl; + exit(1); + break; + } +} + ApplicationInterface *ApplicationInterface::applicationinterface_instance = 0; ApplicationInterface::ApplicationInterface() { @@ -22,6 +45,11 @@ ApplicationInterface::ApplicationInterface() { exit(2); } applicationinterface_instance = this; + + sys::signal(SIGHUP, signal_handler); + sys::signal(SIGINT, signal_handler); + sys::signal(SIGQUIT, signal_handler); + sys::signal(SIGTERM, signal_handler); } ApplicationInterface::~ApplicationInterface() @@ -29,7 +57,7 @@ ApplicationInterface::~ApplicationInterface() applicationinterface_instance = 0; } -ApplicationInterface *ApplicationInterface::instance() +ApplicationInterface *ApplicationInterface::instance() { return applicationinterface_instance; } |