daemon: repace goto exit with daemon_terminate()
Start breaking down big main()
Remove goto exit label and replace it with a function that does cleanup.
Comment re-worded by kevans@.
(cherry picked from commit cf6356fd471cdf4e5c52550f63599881d722962c)