termpty: avoid race between exit of the program and reading from it
termpty: avoid race between exit of the program and reading from it

Also ensure we read what was already in the pipe before we ever polled it.

Closes T4925

godfath3r/terminology,godfath3r/terminology,godfath3r/terminology