Refactoring of daemon/* code to support exec and related features

This PR should not affect any existing functionality.

@crosbymichael : As per your request, I have extracted out the refactoring part of #7409 into this PR.


Making this a pointer is failing integration tests. Leaving it as-is for now. We can make it a pointer in a separate PR.