agent: Synchronize end of process to prevent from race condition
agent: Synchronize end of process to prevent from race condition

In some cases, the agent returns the exit code before it has been
able to forward all the output provided on stdout and stderr.

This is a race condition issue fixed by this patch. The idea is to
wait for the end of every go routines, meaning there is nothing
else to be read on stdout or stderr. That way, we ensure that all
that have been received on stdout or stderr is properly sent to
the proxy before to send the exit code and the exit pattern.

We have to close the pipes that we provided in case no terminal was
setup. In case there is a terminal, then libcontainer will close the
other end for us.
In both cases, when the other end is closed, the blocking read inside
each go routines will fail and this will lead to its termination.

Signed-off-by: Sebastien Boeuf <90b401417360b1924ef3f520ddee932686110f85@intel.com>

clearcontainers/agent,clearcontainers/agent