Index: branches/signals/src/util/Makefile.am
===================================================================
--- branches/signals/src/util/Makefile.am	(revision 7360)
+++ branches/signals/src/util/Makefile.am	(revision 7361)
@@ -10,4 +10,5 @@
 			game_rules.cc \
 			multiplayer_team_deathmatch.cc \
+			signal_handler.cc \
 			\
 			animation/animation3d.cc \
@@ -26,4 +27,5 @@
 			game_rules.h \
 			multiplayer_team_deathmatch.h \
+			signal_handler.h \
 			\
 			animation/animation3d.h \
Index: branches/signals/src/util/signal_handler.cc
===================================================================
--- branches/signals/src/util/signal_handler.cc	(revision 7361)
+++ branches/signals/src/util/signal_handler.cc	(revision 7361)
@@ -0,0 +1,107 @@
+/*
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2004 orx
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+### File Specific:
+   main-programmer: Christoph Renner
+   co-programmer: ...
+*/
+
+#include "signal_handler.h"
+
+SignalHandler * SignalHandler::singletonRef = NULL;
+
+SignalHandler::SignalHandler()
+{
+}
+
+void SignalHandler::doCatch( std::string appName, GdbRunType type )
+{
+  this->type = type;
+  this->appName = appName;
+  
+  catchSignal( SIGSEGV );
+  catchSignal( SIGABRT );
+}
+
+void SignalHandler::dontCatch()
+{
+  for ( SignalRecList::iterator it = sigRecList.begin(); it != sigRecList.end(); it++ )
+  {
+    signal( it->signal, it->handler );
+  }
+
+  sigRecList.clear();
+}
+
+void SignalHandler::catchSignal( int sig )
+{
+  sighandler_t handler = signal( sig, SignalHandler::sigHandler );
+
+  assert( handler != SIG_ERR );
+
+  SignalRec rec;
+  rec.signal = sig;
+  rec.handler = handler;
+
+  sigRecList.push_front( rec );
+}
+
+void SignalHandler::sigHandler( int sig )
+{
+  std::string sigName = "UNKNOWN";
+
+  switch ( sig )
+  {
+    case SIGSEGV:
+      sigName = "SIGSEGV";
+      break;
+    case SIGABRT:
+      sigName = "SIGABRT";
+      break;
+  }
+
+  printf( "recieved signal %s\ntry to write backtrace to file orxonox.backtrace\n", sigName.c_str() );
+
+  int fd[2];
+
+  assert( pipe(fd) != -1 );
+  
+  int pid = fork();
+
+  assert( pid != -1 );
+
+  if ( pid == 0 )
+  {
+    getInstance()->dontCatch();
+
+    sleep(2);
+
+    
+    return;
+  }
+  else
+  {
+    if ( getInstance()->type == GDB_RUN_WRITE_TO_FILE && fork() == 0 )
+    {
+      sleep(1);
+      write( fd[1], "c\nbt\nq\n", 7 );
+
+      exit(0);
+    }
+    dup2( fd[0], STDIN_FILENO );
+    char command[256];
+    if ( getInstance()->type == GDB_RUN_WRITE_TO_FILE )
+      snprintf( command, 255, "gdb -p %d %s 1>" GDB_BT_FILE " 2>&1", pid, getInstance()->appName.c_str() );
+    else
+      snprintf( command, 255, "gdb -p %d %s", pid, getInstance()->appName.c_str() );
+    execlp( "sh", "sh", "-c", command, (void*)NULL);
+  }
+}
+
Index: branches/signals/src/util/signal_handler.h
===================================================================
--- branches/signals/src/util/signal_handler.h	(revision 7361)
+++ branches/signals/src/util/signal_handler.h	(revision 7361)
@@ -0,0 +1,54 @@
+/*!
+ * @file signalhandler.h
+ * Defines game rules for this game
+ */
+
+#ifndef _SIGNAL_HANDLER_H
+#define _SIGNAL_HANDLER_H
+
+#include <list>
+#include <string>
+#include <signal.h>
+
+#define GDB_BT_FILE "orxonox.backtrace"
+
+struct SignalRec
+{
+  int signal;
+  sighandler_t handler;
+};
+
+typedef std::list<SignalRec> SignalRecList;
+
+enum GdbRunType{
+  GDB_RUN_WRITE_TO_FILE = 1,
+  GDB_RUN_IN_FOREGROUND
+};
+
+class SignalHandler
+{
+  private:
+    SignalHandler();
+  public:
+    inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler();
+      return SignalHandler::singletonRef; }
+
+    void doCatch( std::string appName, GdbRunType type = GDB_RUN_WRITE_TO_FILE );
+    void dontCatch();
+
+  private:
+    static void sigHandler( int sig );
+
+    void catchSignal( int sig );
+    SignalRecList sigRecList;
+
+    static SignalHandler * singletonRef;
+
+    GdbRunType type;
+
+    std::string appName;
+};
+
+
+#endif /* _SIGNAL_HANDLER_H */
+
