...
Code Block | ||
---|---|---|
| ||
void sigabrt_handler(int signum) { exit(EXIT_FAILURE); } void cleanup(void) { /* delete temporary files, restore consistent state, etc */ } int main(void) { atexit(cleanup); signal(SIGABRT, sigabrt_handler); /* ... */ assert(/* something bad didn't happen */); /* ... */ } |
Please note that this example is not a violation of \[[Note that this example is not a violation of SIG30-C. Call only asynchronous-safe functions within signal handlers]\] because {{ Wiki Markup abort()
}} is called synchronously by {{assert()
}}.
Risk Analysis
Unsafe usage of abort()
may leave files written in an inconsistent state. It may also leave sensitive temporary files on the filesystem.
...