We have launchd daemon which should be running forever and be started as soon as system is booted, therefore in its plist we say:
<key>KeepAlive</key>
<true/>
Everything is OK until the system is shutdown. Agent needs to inform the remote server about the system being shutdown, via HTTP. System sends SIGTERM to the agent just fine and agent is able to process it. However, by the time it receives SIGTERM, DNS (or maybe entire networking subsystem) is already down, and it cannot send status to the server as it cannot resolve its name. All network functions fail, so I suspect networking is down. On Linux this is resolved by SNN/KMM symlinks with NN=99 and MM=00. However on OSX it is explicitly said that launchd daemons don't have any priorities. How then can we have OSX to send SIGTERM to our daemon before it shuts down DNS/networking?
I have quickly looked at ability to register a listener for system shutdown event as program can register itself to listen for power mode changes (namely, sleep), however a few sources told that this is not possible either - Receiving power notifications (especially shutdown) on Mac OSX.