daemon: decouple init logic from main loop
main() func contained both initialization and main loop logic.
This made certain operations like restarting problematic and
required dirty hacks in form of goto jumps.
This commit moves the main loop logic into daemon_eventloop(),
cleans up main, and makes restart logic clear: daemon_mainloop()
is run in a loop with a restart condition checked at the end.
Reviewed by: kevans
(cherry picked from commit 4c41f4a0d67fc93cfb07ad5287f02d024d19ef5a)