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.


Can we call this `StreamConfig` or something which makes it more obvious that it's about stdin/stdout/stderr? I understand the choice of `std` but it's not immediately obvious. A small detail but in such a complicated and interleaving part of the codebase, little things matter.