Simplifies main() so that it is responsive to signals.

With the prior implementation cleanup would never run on SIGINT or
SIGTERM.