Assume that a cocoa app must execute some vitally important objective-c operation before it exits (for any reason—crash or quit).
Is it possible to ensure the execution of arbitrary objective-c code in response to every crash event? (SIGINT, SIGBUS, SIGSEGV, etc, ignoring the “uncatchables” (SIGSTOP, SIGKILL, bolt of lightning, etc.))
It would be helpful to know what your hooks are trying to do.
For example: let’s say that for the app to operate, it absolutely must change the value of some mutable system-wide configuration variable X. On launch, the app takes a snapshot of X’s current state and then modifies it. When the app exits successfully, it just restores X to the stashed, original value before terminating. My question is this: is it possible to ensure that X gets restored even if the app crashes?
The short answer is no.
A longer answer is still no, but you can minimise the opportunity for not being able to reset you system-wide mutable configuration variable. In outline:
wait(2)& friends) till its parent expires;Your faceless background app should be short and simple, and therefore hopefully robust. It’s far from foolproof, or safe against a user with infanticide on their minds, but it narrows the opportunities for thwarting the reset of your variable.