Subject: | Reduce use of 'exit()' in 'dig' |
In porting "dig" to iOS I've got a few places where use of exit() outside of main() can cause problems.
At the moment I just use #define to turn exit() into a no-op, since having the program terminate arbitrarily wouldn't be acceptable for the AppStore, but neither would having it crash if the no-op'd exit() leaves the program in an indeterminate state.
1. In dig's batch mode, if you supply illegal parameters in the input file (e.g. "-y foo") it causes dig to exit, rather than just carry on with the next input line.
2. In arg processing, "-h" calls usage() which in turn calls exit()
3. Numerous calls to fatal(), which also cause an exit()
It would be highly preferable if the termination conditions were passed back up the call stack so that the application gets the chance to clean up properly (and perhaps keep running).