pigpio: Calling `exit` from a signal handler isn't safe
Here’s a snippet from inside sigHandler, which calls exit at two occasions:
According to man 7 signal, this is not a safe thing to do. Only _Exit and _exit are async-signal-safe, not the regular exit. In my case, this causes my atexit handler to run in signal context, which is very unexpected.
(note that this might not be the only signal safety issue in the handler)
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 15 (9 by maintainers)
Commits related to this issue
- Issue #220 Calling exit from a signal handler is not safe. — committed to joan2937/pigpio by guymcswain 4 years ago
- Revert "Issue #220 Calling exit from a signal handler is not safe." — committed to joan2937/pigpio by guymcswain 4 years ago
- Issue #220 Calling exit from a signal handler is not safe. — committed to joan2937/pigpio by guymcswain 4 years ago
- Revert "Issue #220 Calling exit from a signal handler is not safe." — committed to joan2937/pigpio by guymcswain 4 years ago
The code is executed when the program is killed via
SIGINTorSIGTERM, nothing is compromised in that case. You also shouldn’t exit with a code of -1 in that case, which indicates an error.I think it’s best to just shutdown pigpio normally and don’t call any exit function. The default action of the signal will then be executed and usually terminate the process.
Yeah,
atexithandlers are only called byexit, not the async-signal-safe alternatives_exitand_Exit.