* Set signal handlers for fatal signals on POSIX systems * * \param signalHandler Pointer to the signal handler function */
| 291 | * \param signalHandler Pointer to the signal handler function |
| 292 | */ |
| 293 | static void setFatalSignalHandler(SigActionHandler signalHandler) |
| 294 | { |
| 295 | struct sigaction new_handler; |
| 296 | |
| 297 | sigemptyset(&new_handler.sa_mask); |
| 298 | #ifdef SA_SIGINFO |
| 299 | new_handler.sa_flags = SA_SIGINFO; |
| 300 | new_handler.sa_sigaction = signalHandler; |
| 301 | #else |
| 302 | new_handler.sa_handler = signalHandler; |
| 303 | #endif |
| 304 | |
| 305 | sigaction(SIGABRT, nullptr, &oldAction[SIGABRT]); |
| 306 | if (oldAction[SIGABRT].sa_handler != SIG_IGN) |
| 307 | { |
| 308 | sigaction(SIGABRT, &new_handler, nullptr); |
| 309 | } |
| 310 | |
| 311 | sigaction(SIGBUS, nullptr, &oldAction[SIGBUS]); |
| 312 | if (oldAction[SIGBUS].sa_handler != SIG_IGN) |
| 313 | { |
| 314 | sigaction(SIGBUS, &new_handler, nullptr); |
| 315 | } |
| 316 | |
| 317 | sigaction(SIGFPE, nullptr, &oldAction[SIGFPE]); |
| 318 | if (oldAction[SIGFPE].sa_handler != SIG_IGN) |
| 319 | { |
| 320 | sigaction(SIGFPE, &new_handler, nullptr); |
| 321 | } |
| 322 | |
| 323 | sigaction(SIGILL, nullptr, &oldAction[SIGILL]); |
| 324 | if (oldAction[SIGILL].sa_handler != SIG_IGN) |
| 325 | { |
| 326 | sigaction(SIGILL, &new_handler, nullptr); |
| 327 | } |
| 328 | |
| 329 | sigaction(SIGQUIT, nullptr, &oldAction[SIGQUIT]); |
| 330 | if (oldAction[SIGQUIT].sa_handler != SIG_IGN) |
| 331 | { |
| 332 | sigaction(SIGQUIT, &new_handler, nullptr); |
| 333 | } |
| 334 | |
| 335 | sigaction(SIGSEGV, nullptr, &oldAction[SIGSEGV]); |
| 336 | if (oldAction[SIGSEGV].sa_handler != SIG_IGN) |
| 337 | { |
| 338 | sigaction(SIGSEGV, &new_handler, nullptr); |
| 339 | } |
| 340 | |
| 341 | #if _XOPEN_UNIX |
| 342 | sigaction(SIGSYS, nullptr, &oldAction[SIGSYS]); |
| 343 | if (oldAction[SIGSYS].sa_handler != SIG_IGN) |
| 344 | { |
| 345 | sigaction(SIGSYS, &new_handler, nullptr); |
| 346 | } |
| 347 | |
| 348 | sigaction(SIGXCPU, nullptr, &oldAction[SIGXCPU]); |
| 349 | if (oldAction[SIGXCPU].sa_handler != SIG_IGN) |
| 350 | { |
no test coverage detected