1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-15 23:24:37 +03:00

First cut at fix for the EINTR problem... More needs to be done I think.

Jeremy.
(This used to be commit 48475a7a697242b9fd7b1aec24389afb112569c4)
This commit is contained in:
Jeremy Allison 2002-04-19 02:08:52 +00:00
parent dcb572e0b2
commit 302b581ddc
4 changed files with 187 additions and 141 deletions

View File

@ -72,6 +72,51 @@ int sys_usleep(long usecs)
#endif /* HAVE_USLEEP */ #endif /* HAVE_USLEEP */
} }
/*******************************************************************
A read wrapper that will deal with EINTR.
********************************************************************/
ssize_t sys_read(int fd, void *buf, size_t count)
{
ssize_t ret;
do {
errno = 0;
ret = read(fd, buf, count);
} while (ret == -1 && errno == EINTR);
return ret;
}
/*******************************************************************
A write wrapper that will deal with EINTR.
********************************************************************/
ssize_t sys_write(int fd, const void *buf, size_t count)
{
ssize_t ret;
do {
errno = 0;
ret = write(fd, buf, count);
} while (ret == -1 && errno == EINTR);
return ret;
}
/*******************************************************************
A send wrapper that will deal with EINTR.
********************************************************************/
int sys_send(int s, const void *msg, size_t len, int flags)
{
ssize_t ret;
do {
errno = 0;
ret = send(s, msg, len, flags);
} while (ret == -1 && errno == EINTR);
return ret;
}
/******************************************************************* /*******************************************************************
A stat() wrapper that will deal with 64 bit filesizes. A stat() wrapper that will deal with 64 bit filesizes.
********************************************************************/ ********************************************************************/

View File

@ -1353,11 +1353,12 @@ BOOL fcntl_lock(int fd, int op, SMB_OFF_T offset, SMB_OFF_T count, int type)
lock.l_len = count; lock.l_len = count;
lock.l_pid = 0; lock.l_pid = 0;
do {
errno = 0; errno = 0;
ret = fcntl(fd,op,&lock); ret = fcntl(fd,op,&lock);
} while (ret == -1 && errno == EINTR);
if (errno != 0) if (ret == -1 && errno != 0)
DEBUG(3,("fcntl_lock: fcntl lock gave errno %d (%s)\n",errno,strerror(errno))); DEBUG(3,("fcntl_lock: fcntl lock gave errno %d (%s)\n",errno,strerror(errno)));
/* a lock query */ /* a lock query */

View File

@ -247,10 +247,10 @@ static ssize_t read_socket_with_timeout(int fd,char *buf,size_t mincnt,size_t ma
if (fd == sslFd) { if (fd == sslFd) {
readret = SSL_read(ssl, buf + nread, maxcnt - nread); readret = SSL_read(ssl, buf + nread, maxcnt - nread);
} else { } else {
readret = read(fd, buf + nread, maxcnt - nread); readret = sys_read(fd, buf + nread, maxcnt - nread);
} }
#else /* WITH_SSL */ #else /* WITH_SSL */
readret = read(fd, buf + nread, maxcnt - nread); readret = sys_read(fd, buf + nread, maxcnt - nread);
#endif /* WITH_SSL */ #endif /* WITH_SSL */
if (readret == 0) { if (readret == 0) {
@ -304,10 +304,10 @@ static ssize_t read_socket_with_timeout(int fd,char *buf,size_t mincnt,size_t ma
if (fd == sslFd) { if (fd == sslFd) {
readret = SSL_read(ssl, buf + nread, maxcnt - nread); readret = SSL_read(ssl, buf + nread, maxcnt - nread);
}else{ }else{
readret = read(fd, buf + nread, maxcnt - nread); readret = sys_read(fd, buf + nread, maxcnt - nread);
} }
#else /* WITH_SSL */ #else /* WITH_SSL */
readret = read(fd, buf+nread, maxcnt-nread); readret = sys_read(fd, buf+nread, maxcnt-nread);
#endif /* WITH_SSL */ #endif /* WITH_SSL */
if (readret == 0) { if (readret == 0) {
@ -357,10 +357,10 @@ ssize_t read_with_timeout(int fd, char *buf, size_t mincnt, size_t maxcnt,
if(fd == sslFd){ if(fd == sslFd){
readret = SSL_read(ssl, buf + nread, maxcnt - nread); readret = SSL_read(ssl, buf + nread, maxcnt - nread);
}else{ }else{
readret = read(fd, buf + nread, maxcnt - nread); readret = sys_read(fd, buf + nread, maxcnt - nread);
} }
#else /* WITH_SSL */ #else /* WITH_SSL */
readret = read(fd, buf + nread, maxcnt - nread); readret = sys_read(fd, buf + nread, maxcnt - nread);
#endif /* WITH_SSL */ #endif /* WITH_SSL */
if (readret <= 0) if (readret <= 0)
@ -387,10 +387,10 @@ ssize_t read_with_timeout(int fd, char *buf, size_t mincnt, size_t maxcnt,
if(fd == sslFd){ if(fd == sslFd){
readret = SSL_read(ssl, buf + nread, maxcnt - nread); readret = SSL_read(ssl, buf + nread, maxcnt - nread);
}else{ }else{
readret = read(fd, buf + nread, maxcnt - nread); readret = sys_read(fd, buf + nread, maxcnt - nread);
} }
#else /* WITH_SSL */ #else /* WITH_SSL */
readret = read(fd, buf+nread, maxcnt-nread); readret = sys_read(fd, buf+nread, maxcnt-nread);
#endif /* WITH_SSL */ #endif /* WITH_SSL */
if (readret <= 0) if (readret <= 0)
@ -428,26 +428,24 @@ ssize_t read_data(int fd,char *buffer,size_t N)
smb_read_error = 0; smb_read_error = 0;
while (total < N) while (total < N) {
{
#ifdef WITH_SSL #ifdef WITH_SSL
if(fd == sslFd){ if(fd == sslFd){
ret = SSL_read(ssl, buffer + total, N - total); ret = SSL_read(ssl, buffer + total, N - total);
}else{ }else{
ret = read(fd,buffer + total,N - total); ret = sys_read(fd,buffer + total,N - total);
} }
#else /* WITH_SSL */ #else /* WITH_SSL */
ret = read(fd,buffer + total,N - total); ret = sys_read(fd,buffer + total,N - total);
#endif /* WITH_SSL */ #endif /* WITH_SSL */
if (ret == 0) if (ret == 0) {
{
DEBUG(10,("read_data: read of %d returned 0. Error = %s\n", (int)(N - total), strerror(errno) )); DEBUG(10,("read_data: read of %d returned 0. Error = %s\n", (int)(N - total), strerror(errno) ));
smb_read_error = READ_EOF; smb_read_error = READ_EOF;
return 0; return 0;
} }
if (ret == -1)
{ if (ret == -1) {
DEBUG(0,("read_data: read failure for %d. Error = %s\n", (int)(N - total), strerror(errno) )); DEBUG(0,("read_data: read failure for %d. Error = %s\n", (int)(N - total), strerror(errno) ));
smb_read_error = READ_ERROR; smb_read_error = READ_ERROR;
return -1; return -1;
@ -468,26 +466,24 @@ static ssize_t read_socket_data(int fd,char *buffer,size_t N)
smb_read_error = 0; smb_read_error = 0;
while (total < N) while (total < N) {
{
#ifdef WITH_SSL #ifdef WITH_SSL
if(fd == sslFd){ if(fd == sslFd){
ret = SSL_read(ssl, buffer + total, N - total); ret = SSL_read(ssl, buffer + total, N - total);
}else{ }else{
ret = read(fd,buffer + total,N - total); ret = sys_read(fd,buffer + total,N - total);
} }
#else /* WITH_SSL */ #else /* WITH_SSL */
ret = read(fd,buffer + total,N - total); ret = sys_read(fd,buffer + total,N - total);
#endif /* WITH_SSL */ #endif /* WITH_SSL */
if (ret == 0) if (ret == 0) {
{
DEBUG(10,("read_socket_data: recv of %d returned 0. Error = %s\n", (int)(N - total), strerror(errno) )); DEBUG(10,("read_socket_data: recv of %d returned 0. Error = %s\n", (int)(N - total), strerror(errno) ));
smb_read_error = READ_EOF; smb_read_error = READ_EOF;
return 0; return 0;
} }
if (ret == -1)
{ if (ret == -1) {
DEBUG(0,("read_socket_data: recv failure for %d. Error = %s\n", (int)(N - total), strerror(errno) )); DEBUG(0,("read_socket_data: recv failure for %d. Error = %s\n", (int)(N - total), strerror(errno) ));
smb_read_error = READ_ERROR; smb_read_error = READ_ERROR;
return -1; return -1;
@ -506,23 +502,23 @@ ssize_t write_data(int fd,char *buffer,size_t N)
size_t total=0; size_t total=0;
ssize_t ret; ssize_t ret;
while (total < N) while (total < N) {
{
#ifdef WITH_SSL #ifdef WITH_SSL
if(fd == sslFd){ if(fd == sslFd){
ret = SSL_write(ssl,buffer + total,N - total); ret = SSL_write(ssl,buffer + total,N - total);
}else{ }else{
ret = write(fd,buffer + total,N - total); ret = sys_write(fd,buffer + total,N - total);
} }
#else /* WITH_SSL */ #else /* WITH_SSL */
ret = write(fd,buffer + total,N - total); ret = sys_write(fd,buffer + total,N - total);
#endif /* WITH_SSL */ #endif /* WITH_SSL */
if (ret == -1) { if (ret == -1) {
DEBUG(0,("write_data: write failure. Error = %s\n", strerror(errno) )); DEBUG(0,("write_data: write failure. Error = %s\n", strerror(errno) ));
return -1; return -1;
} }
if (ret == 0) return total; if (ret == 0)
return total;
total += ret; total += ret;
} }
@ -538,23 +534,23 @@ ssize_t write_socket_data(int fd,char *buffer,size_t N)
size_t total=0; size_t total=0;
ssize_t ret; ssize_t ret;
while (total < N) while (total < N) {
{
#ifdef WITH_SSL #ifdef WITH_SSL
if(fd == sslFd){ if(fd == sslFd){
ret = SSL_write(ssl,buffer + total,N - total); ret = SSL_write(ssl,buffer + total,N - total);
}else{ }else{
ret = send(fd,buffer + total,N - total, 0); ret = sys_send(fd,buffer + total,N - total, 0);
} }
#else /* WITH_SSL */ #else /* WITH_SSL */
ret = send(fd,buffer + total,N - total,0); ret = sys_send(fd,buffer + total,N - total,0);
#endif /* WITH_SSL */ #endif /* WITH_SSL */
if (ret == -1) { if (ret == -1) {
DEBUG(0,("write_socket_data: write failure. Error = %s\n", strerror(errno) )); DEBUG(0,("write_socket_data: write failure. Error = %s\n", strerror(errno) ));
return -1; return -1;
} }
if (ret == 0) return total; if (ret == 0)
return total;
total += ret; total += ret;
} }
@ -594,8 +590,7 @@ static ssize_t read_smb_length_return_keepalive(int fd,char *inbuf,unsigned int
int msg_type; int msg_type;
BOOL ok = False; BOOL ok = False;
while (!ok) while (!ok) {
{
if (timeout > 0) if (timeout > 0)
ok = (read_socket_with_timeout(fd,inbuf,4,4,timeout) == 4); ok = (read_socket_with_timeout(fd,inbuf,4,4,timeout) == 4);
else else
@ -627,8 +622,7 @@ ssize_t read_smb_length(int fd,char *inbuf,unsigned int timeout)
{ {
ssize_t len; ssize_t len;
for(;;) for(;;) {
{
len = read_smb_length_return_keepalive(fd, inbuf, timeout); len = read_smb_length_return_keepalive(fd, inbuf, timeout);
if(len < 0) if(len < 0)

View File

@ -169,6 +169,7 @@ static int tdb_brlock(TDB_CONTEXT *tdb, tdb_off offset,
int rw_type, int lck_type, int probe) int rw_type, int lck_type, int probe)
{ {
struct flock fl; struct flock fl;
int ret;
if (tdb->flags & TDB_NOLOCK) if (tdb->flags & TDB_NOLOCK)
return 0; return 0;
@ -183,7 +184,12 @@ static int tdb_brlock(TDB_CONTEXT *tdb, tdb_off offset,
fl.l_len = 1; fl.l_len = 1;
fl.l_pid = 0; fl.l_pid = 0;
if (fcntl(tdb->fd,lck_type,&fl) == -1) { do {
errno = 0;
ret = fcntl(tdb->fd,lck_type,&fl);
} while (ret == -1 && errno == EINTR);
if (ret == -1) {
if (!probe) { if (!probe) {
TDB_LOG((tdb, 5,"tdb_brlock failed (fd=%d) at offset %d rw_type=%d lck_type=%d\n", TDB_LOG((tdb, 5,"tdb_brlock failed (fd=%d) at offset %d rw_type=%d lck_type=%d\n",
tdb->fd, offset, rw_type, lck_type)); tdb->fd, offset, rw_type, lck_type));