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