Merge "Make adb robust against EINTR"

This commit is contained in:
Kenny Root 2012-10-12 23:45:46 -07:00 committed by Gerrit Code Review
commit 207c17ff1f
2 changed files with 10 additions and 9 deletions

View file

@ -202,7 +202,7 @@ static void echo_service(int fd, void *cookie)
int c; int c;
for(;;) { for(;;) {
r = read(fd, buf, 4096); r = adb_read(fd, buf, 4096);
if(r == 0) goto done; if(r == 0) goto done;
if(r < 0) { if(r < 0) {
if(errno == EINTR) continue; if(errno == EINTR) continue;

View file

@ -272,6 +272,7 @@ static __inline__ int adb_is_absolute_host_path( const char* path )
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/tcp.h> #include <netinet/tcp.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#define OS_PATH_SEPARATOR '/' #define OS_PATH_SEPARATOR '/'
#define OS_PATH_SEPARATOR_STR "/" #define OS_PATH_SEPARATOR_STR "/"
@ -306,7 +307,7 @@ static __inline__ int unix_open(const char* path, int options,...)
{ {
if ((options & O_CREAT) == 0) if ((options & O_CREAT) == 0)
{ {
return open(path, options); return TEMP_FAILURE_RETRY( open(path, options) );
} }
else else
{ {
@ -315,19 +316,19 @@ static __inline__ int unix_open(const char* path, int options,...)
va_start( args, options ); va_start( args, options );
mode = va_arg( args, int ); mode = va_arg( args, int );
va_end( args ); va_end( args );
return open(path, options, mode); return TEMP_FAILURE_RETRY( open( path, options, mode ) );
} }
} }
static __inline__ int adb_open_mode( const char* pathname, int options, int mode ) static __inline__ int adb_open_mode( const char* pathname, int options, int mode )
{ {
return open( pathname, options, mode ); return TEMP_FAILURE_RETRY( open( pathname, options, mode ) );
} }
static __inline__ int adb_open( const char* pathname, int options ) static __inline__ int adb_open( const char* pathname, int options )
{ {
int fd = open( pathname, options ); int fd = TEMP_FAILURE_RETRY( open( pathname, options ) );
if (fd < 0) if (fd < 0)
return -1; return -1;
close_on_exec( fd ); close_on_exec( fd );
@ -353,7 +354,7 @@ static __inline__ int adb_close(int fd)
static __inline__ int adb_read(int fd, void* buf, size_t len) static __inline__ int adb_read(int fd, void* buf, size_t len)
{ {
return read(fd, buf, len); return TEMP_FAILURE_RETRY( read( fd, buf, len ) );
} }
#undef read #undef read
@ -361,7 +362,7 @@ static __inline__ int adb_read(int fd, void* buf, size_t len)
static __inline__ int adb_write(int fd, const void* buf, size_t len) static __inline__ int adb_write(int fd, const void* buf, size_t len)
{ {
return write(fd, buf, len); return TEMP_FAILURE_RETRY( write( fd, buf, len ) );
} }
#undef write #undef write
#define write ___xxx_write #define write ___xxx_write
@ -382,7 +383,7 @@ static __inline__ int adb_unlink(const char* path)
static __inline__ int adb_creat(const char* path, int mode) static __inline__ int adb_creat(const char* path, int mode)
{ {
int fd = creat(path, mode); int fd = TEMP_FAILURE_RETRY( creat( path, mode ) );
if ( fd < 0 ) if ( fd < 0 )
return -1; return -1;
@ -397,7 +398,7 @@ static __inline__ int adb_socket_accept(int serverfd, struct sockaddr* addr,
{ {
int fd; int fd;
fd = accept(serverfd, addr, addrlen); fd = TEMP_FAILURE_RETRY( accept( serverfd, addr, addrlen ) );
if (fd >= 0) if (fd >= 0)
close_on_exec(fd); close_on_exec(fd);