Fix exit code issue with TTY mode

Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <guillaume.charmes@docker.com> (github: creack)
Merge pull request #4346 from creack/fix_race_exit_code

Fix exit code issue with TTY mode