servod: Scratch sanitization with multiple stale entries

This changes fixes a bug where if there are multiple stale entries,
scratch sanitization fails. It also adds a unit-test to ensure this does
not regress.

Background: 'stale entries' are found by trying to bind a socket to
the alleged port on localhost. If this succeeds, then the entry is
considered stale, because if there was an active servod instance, it
would have claimed the port. However, the sanitization logic did not
destroy the test-socket before moving onto the next instance. This means
all subsequent checks will appear to have something attached to the
socket - the first test socket.
This gets fixed by
- creating a new test socket for each potential entry
- closing them all individually
This ensures prompt release of resources, and successful detection of
multiple stale entries.

BUG=None
TEST=added unit-test to servodutil

Change-Id: I574159f3e138e3ff20726830d555bebeed7361bd
Signed-off-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1282542
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
2 files changed