base: add helpers for sending/receiving file descriptors.

Almost all of the uses of cmsg(3) in our source tree are wrong in at
least one of the following ways:

  - not aligning the cmsg buffer
  - leaking fds if more fds are received than expected
  - blindly dereferencing CMSG_DATA without checking the header
  - using CMSG_SPACE instead of CMSG_LEN for .cmsg_len
  - using CMSG_LEN instead of CMSG_SPACE for .msg_controllen
  - using a length specified in number of fds instead of bytes

Implement wrapper functions that implement this dumpster fire of an
API correctly.

Bug: http://b/122047630
Test: libbase_test32
Change-Id: I6ac34d67bbbf1bfa9727ab598248fc178ea19df9
5 files changed