diff options
Diffstat (limited to 'gnu/usr.sbin/sendmail/libmilter/comm.c')
-rw-r--r-- | gnu/usr.sbin/sendmail/libmilter/comm.c | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/gnu/usr.sbin/sendmail/libmilter/comm.c b/gnu/usr.sbin/sendmail/libmilter/comm.c index 9e8702807ba..692ec2e84a4 100644 --- a/gnu/usr.sbin/sendmail/libmilter/comm.c +++ b/gnu/usr.sbin/sendmail/libmilter/comm.c @@ -9,24 +9,24 @@ */ #ifndef lint -static char id[] = "@(#)$Sendmail: comm.c,v 8.30 2000/02/11 00:12:29 ca Exp $"; +static char id[] = "@(#)$Sendmail: comm.c,v 8.30.4.6 2000/10/05 22:44:01 gshapiro Exp $"; #endif /* ! lint */ #if _FFR_MILTER #include "libmilter.h" #define FD_Z FD_ZERO(&readset); \ - FD_SET(fd, &readset); \ + FD_SET((u_int) sd, &readset); \ FD_ZERO(&excset); \ - FD_SET(fd, &excset) + FD_SET((u_int) sd, &excset) /* ** MI_RD_CMD -- read a command ** ** Parameters: -** fd -- file descriptor +** sd -- socket descriptor ** timeout -- maximum time to wait -** cmd -- single character command read from fd +** cmd -- single character command read from sd ** rlen -- pointer to length of result ** name -- name of milter ** @@ -37,8 +37,8 @@ static char id[] = "@(#)$Sendmail: comm.c,v 8.30 2000/02/11 00:12:29 ca Exp $"; */ char * -mi_rd_cmd(fd, timeout, cmd, rlen, name) - int fd; +mi_rd_cmd(sd, timeout, cmd, rlen, name) + socket_t sd; struct timeval *timeout; char *cmd; size_t *rlen; @@ -55,23 +55,25 @@ mi_rd_cmd(fd, timeout, cmd, rlen, name) *cmd = '\0'; *rlen = 0; - if (fd >= FD_SETSIZE) + + if (sd >= FD_SETSIZE) { smi_log(SMI_LOG_ERR, "%s: fd %d is larger than FD_SETSIZE %d", - name, fd, FD_SETSIZE); + name, sd, FD_SETSIZE); *cmd = SMFIC_SELECT; return NULL; } + FD_Z; i = 0; - while ((ret = select(fd + 1, &readset, NULL, &excset, timeout)) >= 1) + while ((ret = select(sd + 1, &readset, NULL, &excset, timeout)) >= 1) { - if (FD_ISSET(fd, &excset)) + if (FD_ISSET(sd, &excset)) { *cmd = SMFIC_SELECT; return NULL; } - if ((len = read(fd, data + i, sizeof data - i)) < 0) + if ((len = MI_SOCK_READ(sd, data + i, sizeof data - i)) < 0) { smi_log(SMI_LOG_ERR, "%s, mi_rd_cmd: read returned %d: %s", @@ -84,7 +86,7 @@ mi_rd_cmd(fd, timeout, cmd, rlen, name) *cmd = SMFIC_EOF; return NULL; } - if (len >= sizeof data - i) + if (len >= (ssize_t) sizeof data - i) break; i += len; FD_Z; @@ -123,15 +125,15 @@ mi_rd_cmd(fd, timeout, cmd, rlen, name) i = 0; FD_Z; - while ((ret = select(fd + 1, &readset, NULL, &excset, timeout)) == 1) + while ((ret = select(sd + 1, &readset, NULL, &excset, timeout)) == 1) { - if (FD_ISSET(fd, &excset)) + if (FD_ISSET(sd, &excset)) { *cmd = SMFIC_SELECT; free(buf); return NULL; } - if ((len = read(fd, buf + i, expl - i)) < 0) + if ((len = MI_SOCK_READ(sd, buf + i, expl - i)) < 0) { smi_log(SMI_LOG_ERR, "%s: mi_rd_cmd: read returned %d: %s", @@ -181,10 +183,10 @@ mi_rd_cmd(fd, timeout, cmd, rlen, name) return NULL; } /* -** MI_WR_CMD -- write a cmd to fd +** MI_WR_CMD -- write a cmd to sd ** ** Parameters: -** fd -- file descriptor +** sd -- socket descriptor ** timeout -- maximum time to wait (currently unused) ** cmd -- single character command to write ** buf -- buffer with further data @@ -195,8 +197,8 @@ mi_rd_cmd(fd, timeout, cmd, rlen, name) */ int -mi_wr_cmd(fd, timeout, cmd, buf, len) - int fd; +mi_wr_cmd(sd, timeout, cmd, buf, len) + socket_t sd; struct timeval *timeout; int cmd; char *buf; @@ -217,17 +219,19 @@ mi_wr_cmd(fd, timeout, cmd, buf, len) i = 0; sl = MILTER_LEN_BYTES + 1; - do { + do + { FD_ZERO(&wrtset); - FD_SET(fd, &wrtset); - if ((ret = select(fd + 1, NULL, &wrtset, NULL, timeout)) == 0) + FD_SET((u_int) sd, &wrtset); + if ((ret = select(sd + 1, NULL, &wrtset, NULL, timeout)) == 0) return MI_FAILURE; } while (ret < 0 && errno == EINTR); if (ret < 0) return MI_FAILURE; /* use writev() instead to send the whole stuff at once? */ - while ((l = write(fd, (void *) (data + i), sl - i)) < sl) + while ((l = MI_SOCK_WRITE(sd, (void *) (data + i), + sl - i)) < (ssize_t) sl) { if (l < 0) return MI_FAILURE; @@ -241,15 +245,17 @@ mi_wr_cmd(fd, timeout, cmd, buf, len) return MI_SUCCESS; i = 0; sl = len; - do { + do + { FD_ZERO(&wrtset); - FD_SET(fd, &wrtset); - if ((ret = select(fd + 1, NULL, &wrtset, NULL, timeout)) == 0) + FD_SET((u_int) sd, &wrtset); + if ((ret = select(sd + 1, NULL, &wrtset, NULL, timeout)) == 0) return MI_FAILURE; } while (ret < 0 && errno == EINTR); if (ret < 0) return MI_FAILURE; - while ((l = write(fd, (void *) (buf + i), sl - i)) < sl) + while ((l = MI_SOCK_WRITE(sd, (void *) (buf + i), + sl - i)) < (ssize_t) sl) { if (l < 0) return MI_FAILURE; |