Use os.write in tee so we can handle short writes correctly.
Use os.write in tee so we can handle short writes correctly.

f.write() is not necessarily atomic, so files may get written partially.
To handle this, I've switched to os.write. This promises to be atomic
if you're writing less than PIPE_BUF bytes, which is guaranteed to be
at least 512 (4096 bytes on Linux).

BUG=chromium-os:18049
TEST=Run sample buildbot run. Run unit tests and example test program
     which provokes EAGAIN.

Change-Id: I415954c663ed924c2f142abf56e90f1caf854149
Reviewed-on: http://gerrit.chromium.org/gerrit/4944
Reviewed-by: Ryan Cui <5ce1592d53754a87a44fc2eb7b63d5f77cf50fdb@chromium.org>
Tested-by: David James <f231dc574bbeb62604660cbc162d1b8642a0a3af@chromium.org>

bpsinc-native/src_third_party_chromite,chadversary/chromiumos.chromite,coreos/chromite,zhang0137/chromite,bpsinc-native/src_third_party_chromite,coreos/chromite,bpsinc-native/src_third_party_chromite,coreos/chromite,zhang0137/chromite,zhang0137/chromite,chadversary/chromiumos.chromite