Add android/utils/eintr_wrapper.h

Add a new Android-specific header that defines two macros to
handle EINTR in a consistent way, as well as allow detecting
when a system call loops too many times and exit with a fatal
error message when that happens.

+ Unit tests.

+ Update existing code under android/ which uses to deal directly
  with EINTR to use the new HANDLE_EINTR() and IGNORE_EINTR()

+ Remove EINTR checks for functions that call socket_xxx() functions
  which already loop around EINTR.

Change-Id: I1d2ee64d9743a2edc506f616465ea091878db620
diff --git a/android/console.c b/android/console.c
index e30e724..ccd0426 100644
--- a/android/console.c
+++ b/android/console.c
@@ -34,6 +34,7 @@
 #include "android/globals.h"
 #include "android/utils/bufprint.h"
 #include "android/utils/debug.h"
+#include "android/utils/eintr_wrapper.h"
 #include "android/utils/stralloc.h"
 #include "android/config/config.h"
 #include "android/tcpdump.h"
@@ -285,9 +286,9 @@
         len = strlen(buff);
 
     while (len > 0) {
-        ret = socket_send( client->sock, buff, len);
+        ret = HANDLE_EINTR(socket_send( client->sock, buff, len));
         if (ret < 0) {
-            if (errno != EINTR && errno != EWOULDBLOCK && errno != EAGAIN)
+            if (errno != EWOULDBLOCK && errno != EAGAIN)
                 return;
         } else {
             buff += ret;
@@ -600,16 +601,11 @@
 
     D(( "control_global_accept: just in (fd=%d)\n", global->listen_fd ));
 
-    for(;;) {
-        fd = socket_accept( global->listen_fd, NULL );
-        if (fd < 0 && errno != EINTR) {
-            D(( "problem in accept: %d: %s\n", errno, errno_str ));
-            perror("accept");
-            return;
-        } else if (fd >= 0) {
-            break;
-        }
-        D(( "relooping in accept()\n" ));
+    fd = HANDLE_EINTR(socket_accept(global->listen_fd, NULL));
+    if (fd < 0) {
+        D(( "problem in accept: %d: %s\n", errno, errno_str ));
+        perror("accept");
+        return;
     }
 
     socket_set_xreuseaddr( fd );