Close game gracefully with exit code on OS X

I’m looking for a way to close the game with returning a specific exit code to the OS.
Just calling exit(173); as I did in a prototype setup is obviously not an option as it breaks too many things resulting in a crash of the application. My current use case is testing receipt validation for distribution via App Store.