From c6c3dfe8e063171e89050a6cacb4299d300211a2 Mon Sep 17 00:00:00 2001 From: Ayla Date: Fri, 17 Sep 2010 22:32:41 +0200 Subject: [PATCH] Added some signal handlers, so that gmenu2x will exit correctly if a TERM signal occurs or after a segfault. --- src/gmenu2x.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index 03916ff..6b35880 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -86,6 +86,8 @@ const char *CARD_ROOT = "/card/"; //Note: Add a trailing /! #endif const int CARD_ROOT_LEN = 5; +static GMenu2X *app; + using namespace std; using namespace fastdelegate; @@ -114,14 +116,21 @@ static const char *colorToString(enum color c) return colorNames[c]; } +static void quit_all(int err) { + delete app; + exit(err); +} + int main(int /*argc*/, char * /*argv*/[]) { INFO("----\nGMenu2X starting: If you read this message in the logs, check http://gmenu2x.sourceforge.net/page/Troubleshooting for a solution\n----\n"); - signal(SIGINT,&exit); - GMenu2X app; + signal(SIGINT, &quit_all); + signal(SIGSEGV,&quit_all); + signal(SIGTERM,&quit_all); + app = new GMenu2X(); DEBUG("Starting main()\n"); - app.main(); + app->main(); return 0; }