mirror of
https://github.com/samba-team/samba.git
synced 2024-12-28 07:21:54 +03:00
First cut at fix for the EINTR problem... More needs to be done I think.
Jeremy.
(This used to be commit 48475a7a69
)
This commit is contained in:
parent
dcb572e0b2
commit
302b581ddc
@ -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.
|
||||||
********************************************************************/
|
********************************************************************/
|
||||||
|
@ -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;
|
||||||
|
|
||||||
errno = 0;
|
do {
|
||||||
|
errno = 0;
|
||||||
|
ret = fcntl(fd,op,&lock);
|
||||||
|
} while (ret == -1 && errno == EINTR);
|
||||||
|
|
||||||
ret = fcntl(fd,op,&lock);
|
if (ret == -1 && errno != 0)
|
||||||
|
|
||||||
if (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 */
|
||||||
|
@ -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)
|
||||||
@ -409,12 +409,12 @@ send a keepalive packet (rfc1002)
|
|||||||
|
|
||||||
BOOL send_keepalive(int client)
|
BOOL send_keepalive(int client)
|
||||||
{
|
{
|
||||||
unsigned char buf[4];
|
unsigned char buf[4];
|
||||||
|
|
||||||
buf[0] = SMBkeepalive;
|
buf[0] = SMBkeepalive;
|
||||||
buf[1] = buf[2] = buf[3] = 0;
|
buf[1] = buf[2] = buf[3] = 0;
|
||||||
|
|
||||||
return(write_socket_data(client,(char *)buf,4) == 4);
|
return(write_socket_data(client,(char *)buf,4) == 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -423,38 +423,36 @@ BOOL send_keepalive(int client)
|
|||||||
|
|
||||||
ssize_t read_data(int fd,char *buffer,size_t N)
|
ssize_t read_data(int fd,char *buffer,size_t N)
|
||||||
{
|
{
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
size_t total=0;
|
size_t total=0;
|
||||||
|
|
||||||
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;
|
}
|
||||||
}
|
total += ret;
|
||||||
total += ret;
|
}
|
||||||
}
|
return (ssize_t)total;
|
||||||
return (ssize_t)total;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -463,38 +461,36 @@ ssize_t read_data(int fd,char *buffer,size_t N)
|
|||||||
|
|
||||||
static ssize_t read_socket_data(int fd,char *buffer,size_t N)
|
static ssize_t read_socket_data(int fd,char *buffer,size_t N)
|
||||||
{
|
{
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
size_t total=0;
|
size_t total=0;
|
||||||
|
|
||||||
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;
|
}
|
||||||
}
|
total += ret;
|
||||||
total += ret;
|
}
|
||||||
}
|
return (ssize_t)total;
|
||||||
return (ssize_t)total;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -503,30 +499,30 @@ static ssize_t read_socket_data(int fd,char *buffer,size_t N)
|
|||||||
|
|
||||||
ssize_t write_data(int fd,char *buffer,size_t N)
|
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;
|
||||||
}
|
}
|
||||||
return (ssize_t)total;
|
return (ssize_t)total;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -535,30 +531,30 @@ ssize_t write_data(int fd,char *buffer,size_t N)
|
|||||||
|
|
||||||
ssize_t write_socket_data(int fd,char *buffer,size_t N)
|
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;
|
||||||
}
|
}
|
||||||
return (ssize_t)total;
|
return (ssize_t)total;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -567,17 +563,17 @@ write to a socket
|
|||||||
|
|
||||||
ssize_t write_socket(int fd,char *buf,size_t len)
|
ssize_t write_socket(int fd,char *buf,size_t len)
|
||||||
{
|
{
|
||||||
ssize_t ret=0;
|
ssize_t ret=0;
|
||||||
|
|
||||||
DEBUG(6,("write_socket(%d,%d)\n",fd,(int)len));
|
DEBUG(6,("write_socket(%d,%d)\n",fd,(int)len));
|
||||||
ret = write_socket_data(fd,buf,len);
|
ret = write_socket_data(fd,buf,len);
|
||||||
|
|
||||||
DEBUG(6,("write_socket(%d,%d) wrote %d\n",fd,(int)len,(int)ret));
|
DEBUG(6,("write_socket(%d,%d) wrote %d\n",fd,(int)len,(int)ret));
|
||||||
if(ret <= 0)
|
if(ret <= 0)
|
||||||
DEBUG(0,("write_socket: Error writing %d bytes to socket %d: ERRNO = %s\n",
|
DEBUG(0,("write_socket: Error writing %d bytes to socket %d: ERRNO = %s\n",
|
||||||
(int)len, fd, strerror(errno) ));
|
(int)len, fd, strerror(errno) ));
|
||||||
|
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -590,30 +586,29 @@ timeout is in milliseconds.
|
|||||||
|
|
||||||
static ssize_t read_smb_length_return_keepalive(int fd,char *inbuf,unsigned int timeout)
|
static ssize_t read_smb_length_return_keepalive(int fd,char *inbuf,unsigned int timeout)
|
||||||
{
|
{
|
||||||
ssize_t len=0;
|
ssize_t len=0;
|
||||||
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
|
ok = (read_socket_data(fd,inbuf,4) == 4);
|
||||||
ok = (read_socket_data(fd,inbuf,4) == 4);
|
|
||||||
|
|
||||||
if (!ok)
|
if (!ok)
|
||||||
return(-1);
|
return(-1);
|
||||||
|
|
||||||
len = smb_len(inbuf);
|
len = smb_len(inbuf);
|
||||||
msg_type = CVAL(inbuf,0);
|
msg_type = CVAL(inbuf,0);
|
||||||
|
|
||||||
if (msg_type == SMBkeepalive)
|
if (msg_type == SMBkeepalive)
|
||||||
DEBUG(5,("Got keepalive packet\n"));
|
DEBUG(5,("Got keepalive packet\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG(10,("got smb length of %d\n",len));
|
DEBUG(10,("got smb length of %d\n",len));
|
||||||
|
|
||||||
return(len);
|
return(len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -625,23 +620,22 @@ timeout is in milliseconds.
|
|||||||
|
|
||||||
ssize_t read_smb_length(int fd,char *inbuf,unsigned int timeout)
|
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)
|
||||||
return len;
|
return len;
|
||||||
|
|
||||||
/* Ignore session keepalives. */
|
/* Ignore session keepalives. */
|
||||||
if(CVAL(inbuf,0) != SMBkeepalive)
|
if(CVAL(inbuf,0) != SMBkeepalive)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG(10,("read_smb_length: got smb length of %d\n",len));
|
DEBUG(10,("read_smb_length: got smb length of %d\n",len));
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
@ -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));
|
||||||
|
Loading…
Reference in New Issue
Block a user