Update imsg*.[ch] from OpenBSD, including bzero->memset.

This commit is contained in:
Nicholas Marriott 2015-07-12 19:46:58 +01:00
parent 8b8a007e8e
commit 235e0bd65a
4 changed files with 14 additions and 20 deletions

View File

@ -185,11 +185,6 @@ typedef uint64_t u_int64_t;
#define flock(fd, op) (0) #define flock(fd, op) (0)
#endif #endif
#ifndef HAVE_BZERO
#undef bzero
#define bzero(buf, len) memset(buf, 0, len);
#endif
#ifndef HAVE_CLOSEFROM #ifndef HAVE_CLOSEFROM
/* closefrom.c */ /* closefrom.c */
void closefrom(int); void closefrom(int);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: imsg-buffer.c,v 1.4 2014/06/30 00:25:17 deraadt Exp $ */ /* $OpenBSD: imsg-buffer.c,v 1.7 2015/07/12 18:40:49 nicm Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -74,7 +74,7 @@ ibuf_realloc(struct ibuf *buf, size_t len)
/* on static buffers max is eq size and so the following fails */ /* on static buffers max is eq size and so the following fails */
if (buf->wpos + len > buf->max) { if (buf->wpos + len > buf->max) {
errno = ENOMEM; errno = ERANGE;
return (-1); return (-1);
} }
@ -149,7 +149,7 @@ ibuf_write(struct msgbuf *msgbuf)
unsigned int i = 0; unsigned int i = 0;
ssize_t n; ssize_t n;
bzero(&iov, sizeof(iov)); memset(&iov, 0, sizeof(iov));
TAILQ_FOREACH(buf, &msgbuf->bufs, entry) { TAILQ_FOREACH(buf, &msgbuf->bufs, entry) {
if (i >= IOV_MAX) if (i >= IOV_MAX)
break; break;
@ -233,8 +233,9 @@ msgbuf_write(struct msgbuf *msgbuf)
char buf[CMSG_SPACE(sizeof(int))]; char buf[CMSG_SPACE(sizeof(int))];
} cmsgbuf; } cmsgbuf;
bzero(&iov, sizeof(iov)); memset(&iov, 0, sizeof(iov));
bzero(&msg, sizeof(msg)); memset(&msg, 0, sizeof(msg));
memset(&cmsgbuf, 0, sizeof(cmsgbuf));
TAILQ_FOREACH(buf, &msgbuf->bufs, entry) { TAILQ_FOREACH(buf, &msgbuf->bufs, entry) {
if (i >= IOV_MAX) if (i >= IOV_MAX)
break; break;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: imsg.c,v 1.6 2014/06/30 00:26:22 deraadt Exp $ */ /* $OpenBSD: imsg.c,v 1.9 2015/07/12 18:40:49 nicm Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -34,12 +34,10 @@ int imsg_get_fd(struct imsgbuf *);
int available_fds(unsigned int); int available_fds(unsigned int);
/* TA: 2014-09-08: Note that the original code calls getdtablecount() which is /*
* OpenBSD specific. Until such time that it's ported elsewhere from * The original code calls getdtablecount() which is OpenBSD specific. Use
* <unistd.h>, I've mimicked what OpenSMTPD are doing, by using available_fds() * available_fds() from OpenSMTPD instead.
* instead.
*/ */
int int
available_fds(unsigned int n) available_fds(unsigned int n)
{ {
@ -68,7 +66,7 @@ void
imsg_init(struct imsgbuf *ibuf, int fd) imsg_init(struct imsgbuf *ibuf, int fd)
{ {
msgbuf_init(&ibuf->w); msgbuf_init(&ibuf->w);
bzero(&ibuf->r, sizeof(ibuf->r)); memset(&ibuf->r, 0, sizeof(ibuf->r));
ibuf->fd = fd; ibuf->fd = fd;
ibuf->w.fd = fd; ibuf->w.fd = fd;
ibuf->pid = getpid(); ibuf->pid = getpid();
@ -89,7 +87,8 @@ imsg_read(struct imsgbuf *ibuf)
int fd; int fd;
struct imsg_fd *ifd; struct imsg_fd *ifd;
bzero(&msg, sizeof(msg)); memset(&msg, 0, sizeof(msg));
memset(&cmsgbuf, 0, sizeof(cmsgbuf));
iov.iov_base = ibuf->r.buf + ibuf->r.wpos; iov.iov_base = ibuf->r.buf + ibuf->r.wpos;
iov.iov_len = sizeof(ibuf->r.buf) - ibuf->r.wpos; iov.iov_len = sizeof(ibuf->r.buf) - ibuf->r.wpos;
@ -317,7 +316,7 @@ int
imsg_flush(struct imsgbuf *ibuf) imsg_flush(struct imsgbuf *ibuf)
{ {
while (ibuf->w.queued) while (ibuf->w.queued)
if (msgbuf_write(&ibuf->w) < 0) if (msgbuf_write(&ibuf->w) <= 0)
return (-1); return (-1);
return (0); return (0);
} }

View File

@ -99,7 +99,6 @@ AC_CHECK_HEADERS(
# Check for some functions that are replaced or omitted. # Check for some functions that are replaced or omitted.
AC_CHECK_FUNCS( AC_CHECK_FUNCS(
[ \ [ \
bzero \
dirfd \ dirfd \
flock \ flock \
setproctitle \ setproctitle \