pigpio: Calling `exit` from a signal handler isn't safe

Here’s a snippet from inside sigHandler, which calls exit at two occasions:

https://github.com/joan2937/pigpio/blob/934874be2fa34a525beb33e8cb75e378df587860/pigpio.c#L5518-L5532

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

Most upvoted comments

The code is executed when the program is killed via SIGINT or SIGTERM, 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, atexit handlers are only called by exit, not the async-signal-safe alternatives _exit and _Exit.