|
From: Lasse Kärkkäi. <tr...@us...> - 2010-03-19 13:36:32
|
Module: performous
Branch: master
Commit: 8596613a16216a294b99ce8e6513c1531d8a90f9
Author: Lasse Karkkainen <tro...@tr...>
Date: Fri Mar 19 15:36:19 2010 +0200
Better handling of Ctrl+C (allow killing the program even if something hangs).
---
game/main.cc | 14 ++++++++++++--
1 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/game/main.cc b/game/main.cc
index e62c9af..19b2f83 100644
--- a/game/main.cc
+++ b/game/main.cc
@@ -33,8 +33,19 @@ volatile bool g_quit = false;
bool g_take_screenshot = false;
+// Signal handling for Ctrl-C
+
+static void signalSetup();
+
extern "C" void quit(int) {
+ if (g_quit) std::exit(EXIT_SUCCESS); // Instant exit if Ctrl+C is pressed again
g_quit = true;
+ signalSetup();
+}
+
+static void signalSetup() {
+ std::signal(SIGINT, quit);
+ std::signal(SIGTERM, quit);
}
/// can be thrown as an exception to quit the game
@@ -287,8 +298,7 @@ int main(int argc, char** argv) try {
#endif
std::cout << PACKAGE " " VERSION << std::endl;
- std::signal(SIGINT, quit);
- std::signal(SIGTERM, quit);
+ signalSetup();
std::ios::sync_with_stdio(false); // We do not use C stdio
std::srand(std::time(NULL));
// Parse commandline options
|