// BLSignal.cc /* This source file is part of G4beamline, http://g4beamline.muonsinc.com Copyright (C) 2003,2004,2005,2006 by Tom Roberts, all rights reserved. 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 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. http://www.gnu.org/copyleft/gpl.html */ #include #include "BLSignal.hh" #ifdef WIN32 #include #include #include #else #include #include #include #include #include #include #include #endif extern void g4bl_exit(int value); bool BLSignal::signalReceived = false; bool BLSignal::usr1 = false; bool BLSignal::usr2 = false; int BLSignal::prev = 0; void *BLSignal::stackTrace[256] = { 0 }; int BLSignal::nStackTrace = 0; int BLSignal::sigStackTrace = 0; #ifdef WIN32 static BOOL CtrlHandler( DWORD fdwCtrlType ) { BLSignal::setSignalReceived(true); return TRUE; } #endif void BLSignal::init() { #ifdef WIN32 static int sigs[] = {SIGINT, SIGILL, SIGABRT, SIGSEGV, SIGTERM, SIGFPE}; #else static int sigs[] = {SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGKILL, SIGBUS, SIGSEGV, SIGSYS, SIGPIPE, SIGTERM, SIGXCPU, SIGUSR1, SIGUSR2}; #endif signalReceived = false; prev = 0; for(unsigned i=0; i 0) { char msg[1024]; snprintf(msg,sizeof(msg),"\nStack Trace for signal %d:\n", sigStackTrace); write(fd,msg,strlen(msg)); for(int i=0; i