Internal refactoring of daemon/* code to support exec and related features

@crosbymichael : As per your request, I have extracted out the refactoring part of #7409 into this PR