I have a Mac OS X Carbon Daemon that runs as root. It needs to receive and handle SIGTERM (and other signals) in order for it to terminate properly. The code looks something like this:
static void sig_hup(int sig)
{
fprintf(stderr, "Caught signal %d.\n" sig); fflush(stderr);
}
int main(int argc, const char * argv[]) {
...
signal(SIGTERM, sig_hup);
...
CFRunLoopRun(); // run the event loop
...
return 0;
}
The problem is that sig_hup() is never gets called.
Perhaps the signal is caught by the CFRunLoopRun()? If so, how does the Daemon get notified about that something (e.g. sudo launchctl unload ...) is trying to terminate it?