Author: mturk Date: Wed Sep 2 16:50:39 2009 New Revision: 810604 URL: http://svn.apache.org/viewvc?rev=810604&view=rev Log: Use restartable versions of read() and write()
Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h commons/sandbox/runtime/trunk/src/main/native/os/unix/pmutex.c commons/sandbox/runtime/trunk/src/main/native/os/unix/pshm.c commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h?rev=810604&r1=810603&r2=810604&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h Wed Sep 2 16:50:39 2009 @@ -106,6 +106,28 @@ } } +/* restartable read() */ +static ACR_INLINE ssize_t r_read(int fd, void *buf, size_t count) +{ + ssize_t r; + do { + r = read(fd, buf, count); + } while (r < 0 && errno == EINTR); + + return r; +} + +/* restartable write() */ +static ACR_INLINE ssize_t r_write(int fd, const void *buf, size_t count) +{ + ssize_t w; + do { + w = write(fd, buf, count); + } while (w < 0 && errno == EINTR); + + return w; +} + /** * Secure version of zero memory * It should force compiler to always set the Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/pmutex.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/pmutex.c?rev=810604&r1=810603&r2=810604&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/unix/pmutex.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/unix/pmutex.c Wed Sep 2 16:50:39 2009 @@ -152,7 +152,7 @@ if (fname) { size_t nbytes; semblock_t hdr; - int fs, fd = -1; + int fd = -1; fd = open(fname, O_WRONLY | O_CREAT | O_EXCL, 0660); if (fd < 0) { @@ -175,10 +175,7 @@ hdr.creator = getpid(); hdr.magic = ACR_MTX_MAGIC; hdr.value = 1; - do { - fs = write(fd,(const void *)&hdr, nbytes); - } while (fs == (acr_size_t)-1 && errno == EINTR); - if (fs == -1) { + if (r_write(fd,(const void *)&hdr, nbytes) < 0) { rc = ACR_GET_OS_ERROR(); close(fd); ACR_THROW_IO_IF_ERR(rc); Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/pshm.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/pshm.c?rev=810604&r1=810603&r2=810604&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/unix/pshm.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/unix/pshm.c Wed Sep 2 16:50:39 2009 @@ -202,7 +202,7 @@ acr_shm_t *shm = NULL; struct shmid_ds shmbuf; int file; /* file where metadata is stored */ - int rc; + int rc = 0; acr_size_t nbytes; if (reqsize > ACR_SIZE_T_MAX) { @@ -291,10 +291,8 @@ hdr.magic = ACR_SHM_MAGIC; hdr.size = shm->reqsize; hdr.length = shm->realsize; - do { - rc = write(file,(const void *)&hdr, nbytes); - } while (rc == (acr_size_t)-1 && errno == EINTR); - if (rc == -1) { + + if (r_write(file, (const void *)&hdr, nbytes) < 0) { rc = ACR_GET_OS_ERROR(); goto finally; } @@ -348,9 +346,7 @@ nbytes = sizeof(memblock_t); - do { - rc = read(file, (void *)&hdr, nbytes); - } while (rc == -1 && errno == EINTR); + rc = r_read(file, (void *)&hdr, nbytes); if (rc != nbytes) { /* Wrong format */ rc = EBADF; @@ -359,6 +355,7 @@ } rc = close(file); if (rc) { + rc = ACR_GET_OS_ERROR(); goto finally; } if (hdr.magic != ACR_SHM_MAGIC) { Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c?rev=810604&r1=810603&r2=810604&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c Wed Sep 2 16:50:39 2009 @@ -62,4 +62,3 @@ fclose(f); return b; } -