daemon: Factor out code into new function fork_and_wait_for_startup().