AU: fix bug in GPIO handler that caused failed discovery to be ignored

This solves two issues:

* The GPIO handler will attempt to use GPIO devices even when discovery
  via udev has failed. Not any more.

* GPIO discovery would return success even when it failed on a previous
  attempt. Now it'll reflect the actual result of the discovery attempt.

* Reporting of file descriptor open errors is obscured due to
  intermittent operations that reset errno, now fixed.

* Added test case to ensure that repeat GPIO discovery is not attempted,
  and that test mode check will automatically fail if a previous
  initialization/discovery had failed.

BUG=None
TEST=Passes unit tests
TEST=All symptoms gone on real update attempt w/ x86-alex

Change-Id: I01a7b1e316dbb5b94487a5aad1560d994feae9ff
Reviewed-on: https://gerrit.chromium.org/gerrit/40946
Commit-Queue: Gilad Arnold <garnold@chromium.org>
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
diff --git a/gpio_mock_udev_interface.cc b/gpio_mock_udev_interface.cc
index 22c7b7f..d7e7a41 100644
--- a/gpio_mock_udev_interface.cc
+++ b/gpio_mock_udev_interface.cc
@@ -368,4 +368,15 @@
 }
 
 
+void FailInitGpioMockUdevInterface::ExpectNumInitAttempts(
+    unsigned count) const {
+  EXPECT_EQ(num_init_attempts_, count);
+}
+
+struct udev* FailInitGpioMockUdevInterface::New() {
+  // Increment udev init attempt counter, failing the first attempt.
+  num_init_attempts_++;
+  return num_init_attempts_ == 1 ? NULL : StandardGpioMockUdevInterface::New();
+}
+
 }  // namespace chromeos_update_engine