17d0a6c19SBarry Smith 2e5c89e4eSSatish Balay /* 3e5c89e4eSSatish Balay Routines to handle signals the program will receive. 4e5c89e4eSSatish Balay Usually this will call the error handlers. 5e5c89e4eSSatish Balay */ 6c6db04a5SJed Brown #include <petscsys.h> /*I "petscsys.h" I*/ 79be4fee8SSatish Balay #include <signal.h> 8e5c89e4eSSatish Balay 90700a824SBarry Smith static PetscClassId SIGNAL_CLASSID = 0; 10156ba1f8SBarry Smith 11e5c89e4eSSatish Balay struct SH { 120700a824SBarry Smith PetscClassId classid; 13e5c89e4eSSatish Balay PetscErrorCode (*handler)(int,void*); 14e5c89e4eSSatish Balay void *ctx; 15e5c89e4eSSatish Balay struct SH *previous; 16e5c89e4eSSatish Balay }; 17e5c89e4eSSatish Balay static struct SH *sh = 0; 18ace3abfcSBarry Smith static PetscBool SignalSet = PETSC_FALSE; 19e5c89e4eSSatish Balay 20e5c89e4eSSatish Balay 21e5c89e4eSSatish Balay 22e5c89e4eSSatish Balay EXTERN_C_BEGIN 23e5c89e4eSSatish Balay #undef __FUNCT__ 24e5c89e4eSSatish Balay #define __FUNCT__ "PetscSignalHandler_Private" 25e5c89e4eSSatish Balay /* 26e5c89e4eSSatish Balay PetscSignalHandler_Private - This is the signal handler called by the system. This calls 27e5c89e4eSSatish Balay any signal handler set by PETSc or the application code. 28e5c89e4eSSatish Balay 29e5c89e4eSSatish Balay Input Parameters: (depends on system) 30e5c89e4eSSatish Balay . sig - integer code indicating the type of signal 31e5c89e4eSSatish Balay . code - ?? 32e5c89e4eSSatish Balay . sigcontext - ?? 33e5c89e4eSSatish Balay . addr - ?? 34e5c89e4eSSatish Balay 35e5c89e4eSSatish Balay Note: this is declared extern "C" because it is passed to the system routine signal() 36e5c89e4eSSatish Balay which is an extern "C" routine. The Solaris 2.7 OS compilers require that this be 37e5c89e4eSSatish Balay extern "C". 38e5c89e4eSSatish Balay 39e5c89e4eSSatish Balay */ 40e5c89e4eSSatish Balay #if defined(PETSC_HAVE_4ARG_SIGNAL_HANDLER) 41e5c89e4eSSatish Balay static void PetscSignalHandler_Private(int sig,int code,struct sigcontext * scp,char *addr) 42e5c89e4eSSatish Balay #else 43e5c89e4eSSatish Balay static void PetscSignalHandler_Private(int sig) 44e5c89e4eSSatish Balay #endif 45e5c89e4eSSatish Balay { 46e5c89e4eSSatish Balay PetscErrorCode ierr; 47e5c89e4eSSatish Balay 48e5c89e4eSSatish Balay PetscFunctionBegin; 49a297a907SKarl Rupp if (!sh || !sh->handler) ierr = PetscDefaultSignalHandler(sig,(void*)0); 50a297a907SKarl Rupp else { 510700a824SBarry Smith if (sh->classid != SIGNAL_CLASSID) SETERRABORT(PETSC_COMM_WORLD,PETSC_ERR_COR,"Signal object has been corrupted"); 52e5c89e4eSSatish Balay ierr = (*sh->handler)(sig,sh->ctx); 53e5c89e4eSSatish Balay } 54e5c89e4eSSatish Balay if (ierr) MPI_Abort(PETSC_COMM_WORLD,0); 55e5c89e4eSSatish Balay } 56e5c89e4eSSatish Balay EXTERN_C_END 57e5c89e4eSSatish Balay 58e5c89e4eSSatish Balay #undef __FUNCT__ 59e5c89e4eSSatish Balay #define __FUNCT__ "PetscDefaultSignalHandler" 60e5c89e4eSSatish Balay /*@ 61e5c89e4eSSatish Balay PetscDefaultSignalHandler - Default signal handler. 62e5c89e4eSSatish Balay 63e5c89e4eSSatish Balay Not Collective 64e5c89e4eSSatish Balay 65e5c89e4eSSatish Balay Level: advanced 66e5c89e4eSSatish Balay 67e5c89e4eSSatish Balay Input Parameters: 68e5c89e4eSSatish Balay + sig - signal value 69e5c89e4eSSatish Balay - ptr - unused pointer 70e5c89e4eSSatish Balay 71e5c89e4eSSatish Balay Concepts: signal handler^default 72e5c89e4eSSatish Balay 73e5c89e4eSSatish Balay @*/ 747087cfbeSBarry Smith PetscErrorCode PetscDefaultSignalHandler(int sig,void *ptr) 75e5c89e4eSSatish Balay { 76e5c89e4eSSatish Balay PetscErrorCode ierr; 77e5c89e4eSSatish Balay const char *SIGNAME[64]; 78e5c89e4eSSatish Balay 79e5c89e4eSSatish Balay PetscFunctionBegin; 80e5c89e4eSSatish Balay SIGNAME[0] = "Unknown signal"; 81e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGABRT) 82e5c89e4eSSatish Balay SIGNAME[SIGABRT] = "Abort"; 83e5c89e4eSSatish Balay #endif 84e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGALRM) 855fa1c062SBarry Smith SIGNAME[SIGALRM] = "Alarm"; 86e5c89e4eSSatish Balay #endif 87e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGBUS) 88e5c89e4eSSatish Balay SIGNAME[SIGBUS] = "BUS: Bus Error, possibly illegal memory access"; 89e5c89e4eSSatish Balay #endif 90e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGCHLD) 91e5c89e4eSSatish Balay SIGNAME[SIGCHLD] = "CHLD"; 92e5c89e4eSSatish Balay #endif 93e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGCONT) 94e5c89e4eSSatish Balay SIGNAME[SIGCONT] = "CONT"; 95e5c89e4eSSatish Balay #endif 96e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGFPE) 97e5c89e4eSSatish Balay SIGNAME[SIGFPE] = "FPE: Floating Point Exception,probably divide by zero"; 98e5c89e4eSSatish Balay #endif 99e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGHUP) 1005fa1c062SBarry Smith SIGNAME[SIGHUP] = "Hang up: Some other process (or the batch system) has told this process to end"; 101e5c89e4eSSatish Balay #endif 102e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGILL) 1035fa1c062SBarry Smith SIGNAME[SIGILL] = "Illegal instruction: Likely due to memory corruption"; 104e5c89e4eSSatish Balay #endif 105e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGINT) 1065fa1c062SBarry Smith SIGNAME[SIGINT] = "Interrupt"; 107e5c89e4eSSatish Balay #endif 108e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGKILL) 1095fa1c062SBarry Smith SIGNAME[SIGKILL] = "Kill: Some other process (or the batch system) has told this process to end"; 110e5c89e4eSSatish Balay #endif 111e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGPIPE) 1125fa1c062SBarry Smith SIGNAME[SIGPIPE] = "Broken Pipe: Likely while reading or writing to a socket"; 113e5c89e4eSSatish Balay #endif 114e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGQUIT) 1155fa1c062SBarry Smith SIGNAME[SIGQUIT] = "Quit: Some other process (or the batch system) has told this process to end"; 116e5c89e4eSSatish Balay #endif 117e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGSEGV) 118e5c89e4eSSatish Balay SIGNAME[SIGSEGV] = "SEGV: Segmentation Violation, probably memory access out of range"; 119e5c89e4eSSatish Balay #endif 120e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGSYS) 121e5c89e4eSSatish Balay SIGNAME[SIGSYS] = "SYS"; 122e5c89e4eSSatish Balay #endif 123e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGTERM) 1245fa1c062SBarry Smith SIGNAME[SIGTERM] = "Terminate: Somet process (or the batch system) has told this process to end"; 125e5c89e4eSSatish Balay #endif 126e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGTRAP) 127e5c89e4eSSatish Balay SIGNAME[SIGTRAP] = "TRAP"; 128e5c89e4eSSatish Balay #endif 129e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGTSTP) 130e5c89e4eSSatish Balay SIGNAME[SIGTSTP] = "TSTP"; 131e5c89e4eSSatish Balay #endif 132e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGURG) 133e5c89e4eSSatish Balay SIGNAME[SIGURG] = "URG"; 134e5c89e4eSSatish Balay #endif 135e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGUSR1) 136e5c89e4eSSatish Balay SIGNAME[SIGUSR1] = "User 1"; 137e5c89e4eSSatish Balay #endif 138e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGUSR2) 139e5c89e4eSSatish Balay SIGNAME[SIGUSR2] = "User 2"; 140e5c89e4eSSatish Balay #endif 141e5c89e4eSSatish Balay 142e5c89e4eSSatish Balay signal(sig,SIG_DFL); 1433f6e4ae9SSatish Balay (*PetscErrorPrintf)("------------------------------------------------------------------------\n"); 144a297a907SKarl Rupp if (sig >= 0 && sig <= 20) (*PetscErrorPrintf)("Caught signal number %d %s\n",sig,SIGNAME[sig]); 145a297a907SKarl Rupp else (*PetscErrorPrintf)("Caught signal\n"); 146a297a907SKarl Rupp 147e5c89e4eSSatish Balay (*PetscErrorPrintf)("Try option -start_in_debugger or -on_error_attach_debugger\n"); 148f08646a8SSatish Balay (*PetscErrorPrintf)("or see http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind"); 149e57ff13aSBarry Smith (*PetscErrorPrintf)("or try http://valgrind.org on GNU/linux and Apple Mac OS X to find memory corruption errors\n"); 1508bf1f09cSShri Abhyankar #if defined(PETSC_USE_DEBUG) 151*dbf62e16SBarry Smith if (!PetscStackActive()) (*PetscErrorPrintf)(" or try option -log_stack\n"); 152a297a907SKarl Rupp else { 153e5c89e4eSSatish Balay PetscStackPop; /* remove stack frames for error handlers */ 154e5c89e4eSSatish Balay PetscStackPop; 155e5c89e4eSSatish Balay (*PetscErrorPrintf)("likely location of problem given in stack below\n"); 1563f6e4ae9SSatish Balay (*PetscErrorPrintf)("--------------------- Stack Frames ------------------------------------\n"); 157639ff905SBarry Smith PetscStackView(PETSC_STDOUT); 158e5c89e4eSSatish Balay } 159e5c89e4eSSatish Balay #endif 160e5c89e4eSSatish Balay #if !defined(PETSC_USE_DEBUG) 161e5c89e4eSSatish Balay (*PetscErrorPrintf)("configure using --with-debugging=yes, recompile, link, and run \n"); 162e5c89e4eSSatish Balay (*PetscErrorPrintf)("to get more information on the crash.\n"); 163e5c89e4eSSatish Balay #endif 164668f157eSBarry Smith ierr = PetscError(PETSC_COMM_SELF,0,"User provided function"," unknown file","unknown directory",PETSC_ERR_SIG,PETSC_ERROR_INITIAL,PETSC_NULL); 165e5c89e4eSSatish Balay MPI_Abort(PETSC_COMM_WORLD,(int)ierr); 166e5c89e4eSSatish Balay PetscFunctionReturn(0); 167e5c89e4eSSatish Balay } 168e5c89e4eSSatish Balay 169e5c89e4eSSatish Balay #if !defined(PETSC_SIGNAL_CAST) 170e5c89e4eSSatish Balay #define PETSC_SIGNAL_CAST 171e5c89e4eSSatish Balay #endif 172e5c89e4eSSatish Balay 173e5c89e4eSSatish Balay #undef __FUNCT__ 174e5c89e4eSSatish Balay #define __FUNCT__ "PetscPushSignalHandler" 175e5c89e4eSSatish Balay /*@C 176e5c89e4eSSatish Balay PetscPushSignalHandler - Catches the usual fatal errors and 177e5c89e4eSSatish Balay calls a user-provided routine. 178e5c89e4eSSatish Balay 179e5c89e4eSSatish Balay Not Collective 180e5c89e4eSSatish Balay 181e5c89e4eSSatish Balay Input Parameter: 182e5c89e4eSSatish Balay + routine - routine to call when a signal is received 183e5c89e4eSSatish Balay - ctx - optional context needed by the routine 184e5c89e4eSSatish Balay 185e5c89e4eSSatish Balay Level: developer 186e5c89e4eSSatish Balay 187e5c89e4eSSatish Balay Concepts: signal handler^setting 188e5c89e4eSSatish Balay 18934b9b2edSBarry Smith .seealso: PetscPopSignalHandler(), PetscDefaultSignalHandler(), PetscPushErrorHandler() 190e5c89e4eSSatish Balay 191e5c89e4eSSatish Balay @*/ 1927087cfbeSBarry Smith PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*routine)(int,void*),void *ctx) 193e5c89e4eSSatish Balay { 194e5c89e4eSSatish Balay struct SH *newsh; 195e5c89e4eSSatish Balay PetscErrorCode ierr; 196e5c89e4eSSatish Balay 197e5c89e4eSSatish Balay PetscFunctionBegin; 1980700a824SBarry Smith if (!SIGNAL_CLASSID) { 1990700a824SBarry Smith /* ierr = PetscClassIdRegister("Signal",&SIGNAL_CLASSID);CHKERRQ(ierr); */ 2000700a824SBarry Smith SIGNAL_CLASSID = 19; 201156ba1f8SBarry Smith } 202e5c89e4eSSatish Balay if (!SignalSet && routine) { 203e5c89e4eSSatish Balay /* Do not catch ABRT, CHLD, KILL */ 204e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGALRM) 205e5c89e4eSSatish Balay /* signal(SIGALRM, PETSC_SIGNAL_CAST PetscSignalHandler_Private); */ 206e5c89e4eSSatish Balay #endif 207e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGBUS) 208e5c89e4eSSatish Balay signal(SIGBUS, PETSC_SIGNAL_CAST PetscSignalHandler_Private); 209e5c89e4eSSatish Balay #endif 210e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGCONT) 211e5c89e4eSSatish Balay /*signal(SIGCONT, PETSC_SIGNAL_CAST PetscSignalHandler_Private);*/ 212e5c89e4eSSatish Balay #endif 213e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGFPE) 214e5c89e4eSSatish Balay signal(SIGFPE, PETSC_SIGNAL_CAST PetscSignalHandler_Private); 215e5c89e4eSSatish Balay #endif 216e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGHUP) 217e5c89e4eSSatish Balay signal(SIGHUP, PETSC_SIGNAL_CAST PetscSignalHandler_Private); 218e5c89e4eSSatish Balay #endif 219e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGILL) 220e5c89e4eSSatish Balay signal(SIGILL, PETSC_SIGNAL_CAST PetscSignalHandler_Private); 221e5c89e4eSSatish Balay #endif 222e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGINT) 223e5c89e4eSSatish Balay /* signal(SIGINT, PETSC_SIGNAL_CAST PetscSignalHandler_Private); */ 224e5c89e4eSSatish Balay #endif 225e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGPIPE) 226e5c89e4eSSatish Balay signal(SIGPIPE, PETSC_SIGNAL_CAST PetscSignalHandler_Private); 227e5c89e4eSSatish Balay #endif 228e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGQUIT) 229e5c89e4eSSatish Balay signal(SIGQUIT, PETSC_SIGNAL_CAST PetscSignalHandler_Private); 230e5c89e4eSSatish Balay #endif 231e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGSEGV) 232e5c89e4eSSatish Balay signal(SIGSEGV, PETSC_SIGNAL_CAST PetscSignalHandler_Private); 233e5c89e4eSSatish Balay #endif 234e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGSYS) 235e5c89e4eSSatish Balay signal(SIGSYS, PETSC_SIGNAL_CAST PetscSignalHandler_Private); 236e5c89e4eSSatish Balay #endif 237e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGTERM) 238e5c89e4eSSatish Balay signal(SIGTERM, PETSC_SIGNAL_CAST PetscSignalHandler_Private); 239e5c89e4eSSatish Balay #endif 240e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGTRAP) 241e5c89e4eSSatish Balay signal(SIGTRAP, PETSC_SIGNAL_CAST PetscSignalHandler_Private); 242e5c89e4eSSatish Balay #endif 243e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGTSTP) 244e5c89e4eSSatish Balay /* signal(SIGTSTP, PETSC_SIGNAL_CAST PetscSignalHandler_Private); */ 245e5c89e4eSSatish Balay #endif 246e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGURG) 247e5c89e4eSSatish Balay signal(SIGURG, PETSC_SIGNAL_CAST PetscSignalHandler_Private); 248e5c89e4eSSatish Balay #endif 249e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGUSR1) 250e5c89e4eSSatish Balay /* signal(SIGUSR1, PETSC_SIGNAL_CAST PetscSignalHandler_Private); */ 251e5c89e4eSSatish Balay #endif 252e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGUSR2) 253e5c89e4eSSatish Balay /* signal(SIGUSR2, PETSC_SIGNAL_CAST PetscSignalHandler_Private); */ 254e5c89e4eSSatish Balay #endif 255e5c89e4eSSatish Balay SignalSet = PETSC_TRUE; 256e5c89e4eSSatish Balay } 257e5c89e4eSSatish Balay if (!routine) { 258e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGALRM) 259e5c89e4eSSatish Balay /* signal(SIGALRM, 0); */ 260e5c89e4eSSatish Balay #endif 261e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGBUS) 262e5c89e4eSSatish Balay signal(SIGBUS, 0); 263e5c89e4eSSatish Balay #endif 264e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGCONT) 265e5c89e4eSSatish Balay /* signal(SIGCONT, 0); */ 266e5c89e4eSSatish Balay #endif 267e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGFPE) 268e5c89e4eSSatish Balay signal(SIGFPE, 0); 269e5c89e4eSSatish Balay #endif 270e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGHUP) 271e5c89e4eSSatish Balay signal(SIGHUP, 0); 272e5c89e4eSSatish Balay #endif 273e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGILL) 274e5c89e4eSSatish Balay signal(SIGILL, 0); 275e5c89e4eSSatish Balay #endif 276e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGINT) 277e5c89e4eSSatish Balay /* signal(SIGINT, 0); */ 278e5c89e4eSSatish Balay #endif 279e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGPIPE) 280e5c89e4eSSatish Balay signal(SIGPIPE, 0); 281e5c89e4eSSatish Balay #endif 282e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGQUIT) 283e5c89e4eSSatish Balay signal(SIGQUIT, 0); 284e5c89e4eSSatish Balay #endif 285e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGSEGV) 286e5c89e4eSSatish Balay signal(SIGSEGV, 0); 287e5c89e4eSSatish Balay #endif 288e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGSYS) 289e5c89e4eSSatish Balay signal(SIGSYS, 0); 290e5c89e4eSSatish Balay #endif 291e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGTERM) 292e5c89e4eSSatish Balay signal(SIGTERM, 0); 293e5c89e4eSSatish Balay #endif 294e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGTRAP) 295e5c89e4eSSatish Balay signal(SIGTRAP, 0); 296e5c89e4eSSatish Balay #endif 297e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGTSTP) 298e5c89e4eSSatish Balay /* signal(SIGTSTP, 0); */ 299e5c89e4eSSatish Balay #endif 300e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGURG) 301e5c89e4eSSatish Balay signal(SIGURG, 0); 302e5c89e4eSSatish Balay #endif 303e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGUSR1) 304e5c89e4eSSatish Balay /* signal(SIGUSR1, 0); */ 305e5c89e4eSSatish Balay #endif 306e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGUSR2) 307e5c89e4eSSatish Balay /* signal(SIGUSR2, 0); */ 308e5c89e4eSSatish Balay #endif 309e5c89e4eSSatish Balay SignalSet = PETSC_FALSE; 310e5c89e4eSSatish Balay } 311e5c89e4eSSatish Balay ierr = PetscNew(struct SH,&newsh);CHKERRQ(ierr); 312156ba1f8SBarry Smith if (sh) { 313e32f2f54SBarry Smith if (sh->classid != SIGNAL_CLASSID) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_COR,"Signal object has been corrupted"); 314156ba1f8SBarry Smith newsh->previous = sh; 315a297a907SKarl Rupp } else newsh->previous = 0; 316e5c89e4eSSatish Balay newsh->handler = routine; 317e5c89e4eSSatish Balay newsh->ctx = ctx; 3180700a824SBarry Smith newsh->classid = SIGNAL_CLASSID; 319e5c89e4eSSatish Balay sh = newsh; 320e5c89e4eSSatish Balay PetscFunctionReturn(0); 321e5c89e4eSSatish Balay } 322e5c89e4eSSatish Balay 323e5c89e4eSSatish Balay #undef __FUNCT__ 324e5c89e4eSSatish Balay #define __FUNCT__ "PetscPopSignalHandler" 325e30d2299SSatish Balay /*@ 326e5c89e4eSSatish Balay PetscPopSignalHandler - Removes the most last signal handler that was pushed. 327e5c89e4eSSatish Balay If no signal handlers are left on the stack it will remove the PETSc signal handler. 328e5c89e4eSSatish Balay (That is PETSc will no longer catch signals). 329e5c89e4eSSatish Balay 330e5c89e4eSSatish Balay Not Collective 331e5c89e4eSSatish Balay 332e5c89e4eSSatish Balay Level: developer 333e5c89e4eSSatish Balay 334e5c89e4eSSatish Balay Concepts: signal handler^setting 335e5c89e4eSSatish Balay 336e5c89e4eSSatish Balay .seealso: PetscPushSignalHandler() 337e5c89e4eSSatish Balay 338e5c89e4eSSatish Balay @*/ 3397087cfbeSBarry Smith PetscErrorCode PetscPopSignalHandler(void) 340e5c89e4eSSatish Balay { 341e5c89e4eSSatish Balay struct SH *tmp; 342e5c89e4eSSatish Balay 343e5c89e4eSSatish Balay PetscFunctionBegin; 344e5c89e4eSSatish Balay if (!sh) PetscFunctionReturn(0); 345e32f2f54SBarry Smith if (sh->classid != SIGNAL_CLASSID) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_COR,"Signal object has been corrupted"); 346156ba1f8SBarry Smith 347e5c89e4eSSatish Balay tmp = sh; 348e5c89e4eSSatish Balay sh = sh->previous; 3492bb46157SSatish Balay PetscFreeVoid(tmp); 350e5c89e4eSSatish Balay if (!sh || !sh->handler) { 351e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGALRM) 352e5c89e4eSSatish Balay /* signal(SIGALRM, 0); */ 353e5c89e4eSSatish Balay #endif 354e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGBUS) 355e5c89e4eSSatish Balay signal(SIGBUS, 0); 356e5c89e4eSSatish Balay #endif 357e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGCONT) 358e5c89e4eSSatish Balay /* signal(SIGCONT, 0); */ 359e5c89e4eSSatish Balay #endif 360e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGFPE) 361e5c89e4eSSatish Balay signal(SIGFPE, 0); 362e5c89e4eSSatish Balay #endif 363e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGHUP) 364e5c89e4eSSatish Balay signal(SIGHUP, 0); 365e5c89e4eSSatish Balay #endif 366e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGILL) 367e5c89e4eSSatish Balay signal(SIGILL, 0); 368e5c89e4eSSatish Balay #endif 369e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGINT) 370e5c89e4eSSatish Balay /* signal(SIGINT, 0); */ 371e5c89e4eSSatish Balay #endif 372e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGPIPE) 373e5c89e4eSSatish Balay signal(SIGPIPE, 0); 374e5c89e4eSSatish Balay #endif 375e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGQUIT) 376e5c89e4eSSatish Balay signal(SIGQUIT, 0); 377e5c89e4eSSatish Balay #endif 378e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGSEGV) 379e5c89e4eSSatish Balay signal(SIGSEGV, 0); 380e5c89e4eSSatish Balay #endif 381e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGSYS) 382e5c89e4eSSatish Balay signal(SIGSYS, 0); 383e5c89e4eSSatish Balay #endif 384e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGTERM) 385e5c89e4eSSatish Balay signal(SIGTERM, 0); 386e5c89e4eSSatish Balay #endif 387e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGTRAP) 388e5c89e4eSSatish Balay signal(SIGTRAP, 0); 389e5c89e4eSSatish Balay #endif 390e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGTSTP) 391e5c89e4eSSatish Balay /* signal(SIGTSTP, 0); */ 392e5c89e4eSSatish Balay #endif 393e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGURG) 394e5c89e4eSSatish Balay signal(SIGURG, 0); 395e5c89e4eSSatish Balay #endif 396e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGUSR1) 397e5c89e4eSSatish Balay /* signal(SIGUSR1, 0); */ 398e5c89e4eSSatish Balay #endif 399e5c89e4eSSatish Balay #if !defined(PETSC_MISSING_SIGUSR2) 400e5c89e4eSSatish Balay /* signal(SIGUSR2, 0); */ 401e5c89e4eSSatish Balay #endif 402e5c89e4eSSatish Balay SignalSet = PETSC_FALSE; 403e5c89e4eSSatish Balay } else { 404e5c89e4eSSatish Balay SignalSet = PETSC_TRUE; 405e5c89e4eSSatish Balay } 406e5c89e4eSSatish Balay PetscFunctionReturn(0); 407e5c89e4eSSatish Balay } 408e5c89e4eSSatish Balay 409e5c89e4eSSatish Balay 410f0c7afdeSSatish Balay #if defined(PETSC_HAVE_SETJMP_H) && defined(PETSC_HAVE_SIGINFO_T) 411a8b45ee7SBarry Smith #include <setjmp.h> 412a8b45ee7SBarry Smith jmp_buf PetscSegvJumpBuf; 413a8b45ee7SBarry Smith /* 414a8b45ee7SBarry Smith This routine is called if a segmentation violation, i.e. inaccessible memory access 415a8b45ee7SBarry Smith is triggered when PETSc is testing for a buggy pointer with PetscCheckPointer() 416a8b45ee7SBarry Smith 417a8b45ee7SBarry Smith It simply unrolls the UNIX signal and returns to the location where setjump(PetscSeqvJumpBuf) is declared. 418a8b45ee7SBarry Smith */ 419a8b45ee7SBarry Smith void PetscSegv_sigaction(int signal, siginfo_t *si, void *arg) 420a8b45ee7SBarry Smith { 421a8b45ee7SBarry Smith longjmp(PetscSegvJumpBuf,1); 422a8b45ee7SBarry Smith return; 423a8b45ee7SBarry Smith } 424a8b45ee7SBarry Smith #endif 425e5c89e4eSSatish Balay 426e5c89e4eSSatish Balay 427