I think I may have been doing this wrong for a while, because we just switched to systemd and it's considering my cleanly-killed process to have ended unsuccessfully.
Basically I listen for SIGHUP, SIGINT and SIGTERM and then (by passing the signal code back up to main) cleanly e.g. return 128+SIGHUP.
I expected this to be used to populate $?, but now I think I understand that the shell is responsible for giving $? such a value, and then only if the signal was unhandled. So even if the process exited ultimately due a signal, because the signal was handled, $? will end up being 0 and all evidence that a signal had anything to do with the exiting will be lost. Is that right?
When handling SIGHUP and cleanly exiting, should I return EXIT_SUCCESS from main?