Fix Process::BindFd when passing the same fd to the child.

Process::BindFd() allows to map a file descriptor in the parent to a
file descriptor in the child. This was normally used to redirect the
child's stdout or stderr to a given file descriptor in the parent, like
an open file or a pipe. This didn't work when binding a file descriptor
in the parent to the same number in the child, used for example to make
available to the child a file descriptor opened in the parent, but
close all the other file descriptors with SetCloseUnusedFileDescriptors.

Bug: 27880754
TEST=Added unittests for that case.

Change-Id: I5e4545936a36d7d6eaa0f7b68c6033b3ce6182da
2 files changed