libbrillo: dup and scope file descriptor

brillo::dbus_utils::FileDescriptor may be used to pass FDs
back out of adaptor code into D-Bus bindings, in which case the
adaptor code does not pass ownership of the FDs to the D-Bus
bindings but the D-Bus FD will probably outlive the lifetime of
the FD in the adaptor code.

To deal with this, we use brillo::dbus_utils::FileDescriptor as a
wrapper around a ScopedFD which dups file descriptors that are
put in. This means adaptor code can pass FDs without having to
give up ownership or manually try to mitigate leaks later, and
does not have to deal with e.g. duping into a ScopedFD at all
callsites.

BUG=b:37434548
TEST=unit tests, use in permission_broker/session_manager/etc

Change-Id: Ic3f139d4af817bb0bbe975cec3855e44a09bcda9
Reviewed-on: https://chromium-review.googlesource.com/987197
Commit-Ready: Eric Caruso <ejcaruso@chromium.org>
Tested-by: Eric Caruso <ejcaruso@chromium.org>
Reviewed-by: Dan Erat <derat@chromium.org>
3 files changed