Avoid race condition by opening file in blocking mode as opposed to opening file and then setting it to blocking mode. If the latter is done go with register the file descriptor with the runtime and begin polling, which will cause reads to block if there is no data ready to be read.
Avoid race condition by opening file in blocking mode as opposed to
opening file and then setting it to blocking mode.
If the latter is done go with register the file descriptor with the
runtime and begin polling, which will cause reads to block if there is
no data ready to be read.

Additionally Close fd on errors

Change-Id: Id1708ddb26ca9980d86fef99789f9bc15e0dad17

google/devx-tools,google/devx-tools