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/config.c b/android/config.c
index 2c37b03..4f4da46 100644
--- a/android/config.c
+++ b/android/config.c
@@ -17,6 +17,7 @@
#include <errno.h>
#include "android/config.h"
+#include "android/utils/eintr_wrapper.h"
#include "android/utils/path.h"
AConfig*
@@ -386,11 +387,7 @@
w->p += avail;
if (w->p == w->end) {
- int ret;
- do {
- ret = write( w->fd, w->buff, w->p - w->buff );
- } while (ret < 0 && errno == EINTR);
- if (ret < 0)
+ if (HANDLE_EINTR(write(w->fd, w->buff, w->p - w->buff)) < 0)
break;
w->p = w->buff;
}
@@ -401,12 +398,9 @@
writer_done( Writer* w )
{
if (w->p > w->buff) {
- int ret;
- do {
- ret = write( w->fd, w->buff, w->p - w->buff );
- } while (ret < 0 && errno == EINTR);
+ HANDLE_EINTR(write(w->fd, w->buff, w->p - w->buff));
}
- close( w->fd );
+ IGNORE_EINTR(close( w->fd ));
}
static void