1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-03 06:45:37 -08:00

bgpd and smtpd include their own imsgbuf_read_nofd() implementation.

Adjust that one as well apart from that the conversion to the new
imsgbuf_read read behaviour is trivial.

OK tb@
This commit is contained in:
claudio 2024-11-21 13:22:21 +00:00
parent 668e5ba9d8
commit 16b0c81bb5
9 changed files with 34 additions and 30 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bgpd.c,v 1.275 2024/11/21 13:18:38 claudio Exp $ */
/* $OpenBSD: bgpd.c,v 1.276 2024/11/21 13:22:21 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -1281,7 +1281,7 @@ handle_pollfd(struct pollfd *pfd, struct imsgbuf *i)
}
if (pfd->revents & POLLIN) {
if ((n = imsgbuf_read(i)) == -1 && errno != EAGAIN) {
if ((n = imsgbuf_read(i)) == -1) {
log_warn("imsg read error");
close(i->fd);
i->fd = -1;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: control.c,v 1.126 2024/11/21 13:18:38 claudio Exp $ */
/* $OpenBSD: control.c,v 1.127 2024/11/21 13:22:21 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -37,7 +37,7 @@ struct ctl_conn *control_connbyfd(int);
struct ctl_conn *control_connbypid(pid_t);
int control_close(struct ctl_conn *);
void control_result(struct ctl_conn *, u_int);
ssize_t imsgbuf_read_nofd(struct imsgbuf *);
int imsgbuf_read_nofd(struct imsgbuf *);
int
control_check(char *path)
@ -261,8 +261,7 @@ control_dispatch_msg(struct pollfd *pfd, struct peer_head *peers)
if (!(pfd->revents & POLLIN))
return (0);
if (((n = imsgbuf_read_nofd(&c->imsgbuf)) == -1 && errno != EAGAIN) ||
n == 0)
if (imsgbuf_read_nofd(&c->imsgbuf) != 1)
return control_close(c);
for (;;) {
@ -596,7 +595,7 @@ control_result(struct ctl_conn *c, u_int code)
}
/* This should go into libutil, from smtpd/mproc.c */
ssize_t
int
imsgbuf_read_nofd(struct imsgbuf *imsgbuf)
{
ssize_t n;
@ -607,10 +606,14 @@ imsgbuf_read_nofd(struct imsgbuf *imsgbuf)
len = sizeof(imsgbuf->r.buf) - imsgbuf->r.wpos;
while ((n = recv(imsgbuf->fd, buf, len, 0)) == -1) {
if (errno == EAGAIN)
return (1);
if (errno != EINTR)
return (n);
return (-1);
}
if (n == 0)
return (0);
imsgbuf->r.wpos += n;
return (n);
return (1);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: ca.c,v 1.48 2024/11/21 13:17:02 claudio Exp $ */
/* $OpenBSD: ca.c,v 1.49 2024/11/21 13:22:21 claudio Exp $ */
/*
* Copyright (c) 2014 Reyk Floeter <reyk@openbsd.org>
@ -323,7 +323,7 @@ rsae_send_imsg(int flen, const unsigned char *from, unsigned char *to,
ibuf = &p_ca->imsgbuf;
while (!done) {
if ((n = imsgbuf_read(ibuf)) == -1 && errno != EAGAIN)
if ((n = imsgbuf_read(ibuf)) == -1)
fatalx("imsgbuf_read");
if (n == 0)
fatalx("pipe closed");
@ -431,7 +431,7 @@ ecdsae_send_enc_imsg(const unsigned char *dgst, int dgst_len,
ibuf = &p_ca->imsgbuf;
while (!done) {
if ((n = imsgbuf_read(ibuf)) == -1 && errno != EAGAIN)
if ((n = imsgbuf_read(ibuf)) == -1)
fatalx("imsgbuf_read");
if (n == 0)
fatalx("pipe closed");

View File

@ -1,4 +1,4 @@
/* $OpenBSD: enqueue.c,v 1.124 2024/11/21 13:17:02 claudio Exp $ */
/* $OpenBSD: enqueue.c,v 1.125 2024/11/21 13:22:21 claudio Exp $ */
/*
* Copyright (c) 2005 Henning Brauer <henning@bulabula.org>
@ -788,7 +788,7 @@ open_connection(void)
err(1, "write error");
while (1) {
if ((n = imsgbuf_read(ibuf)) == -1 && errno != EAGAIN)
if ((n = imsgbuf_read(ibuf)) == -1)
errx(1, "imsgbuf_read error");
if (n == 0)
errx(1, "pipe closed");

View File

@ -1,4 +1,4 @@
/* $OpenBSD: mproc.c,v 1.44 2024/11/21 13:18:38 claudio Exp $ */
/* $OpenBSD: mproc.c,v 1.45 2024/11/21 13:22:21 claudio Exp $ */
/*
* Copyright (c) 2012 Eric Faurot <eric@faurot.net>
@ -26,7 +26,7 @@
static void mproc_dispatch(int, short, void *);
static ssize_t imsgbuf_read_nofd(struct imsgbuf *);
static int imsgbuf_read_nofd(struct imsgbuf *);
int
mproc_fork(struct mproc *p, const char *path, char *argv[])
@ -146,8 +146,6 @@ mproc_dispatch(int fd, short event, void *arg)
switch (n) {
case -1:
if (errno == EAGAIN)
break;
log_warn("warn: %s -> %s: imsgbuf_read",
proc_name(smtpd_process), p->name);
fatal("exiting");
@ -199,7 +197,7 @@ mproc_dispatch(int fd, short event, void *arg)
}
/* This should go into libutil */
static ssize_t
static int
imsgbuf_read_nofd(struct imsgbuf *ibuf)
{
ssize_t n;
@ -210,12 +208,16 @@ imsgbuf_read_nofd(struct imsgbuf *ibuf)
len = sizeof(ibuf->r.buf) - ibuf->r.wpos;
while ((n = recv(ibuf->fd, buf, len, 0)) == -1) {
if (errno == EAGAIN)
return (1);
if (errno != EINTR)
return (n);
return (-1);
}
if (n == 0)
return (0);
ibuf->r.wpos += n;
return (n);
return (1);
}
void

View File

@ -1,4 +1,4 @@
/* $OpenBSD: queue_proc.c,v 1.12 2024/11/21 13:17:02 claudio Exp $ */
/* $OpenBSD: queue_proc.c,v 1.13 2024/11/21 13:22:21 claudio Exp $ */
/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
@ -54,7 +54,7 @@ queue_proc_call(void)
return;
}
if ((n = imsgbuf_read(&ibuf)) == -1 && errno != EAGAIN) {
if ((n = imsgbuf_read(&ibuf)) == -1) {
log_warn("warn: queue-proc: imsgbuf_read");
break;
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: scheduler_proc.c,v 1.11 2024/11/21 13:17:02 claudio Exp $ */
/* $OpenBSD: scheduler_proc.c,v 1.12 2024/11/21 13:22:21 claudio Exp $ */
/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
@ -53,7 +53,7 @@ scheduler_proc_call(void)
return;
}
if ((n = imsgbuf_read(&ibuf)) == -1 && errno != EAGAIN) {
if ((n = imsgbuf_read(&ibuf)) == -1) {
log_warn("warn: scheduler-proc: imsgbuf_read");
break;
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: smtpctl.c,v 1.173 2024/11/21 13:17:02 claudio Exp $ */
/* $OpenBSD: smtpctl.c,v 1.174 2024/11/21 13:22:21 claudio Exp $ */
/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
@ -192,7 +192,7 @@ srv_recv(int type)
break;
}
if ((n = imsgbuf_read(ibuf)) == -1 && errno != EAGAIN)
if ((n = imsgbuf_read(ibuf)) == -1)
errx(1, "imsgbuf_read error");
if (n == 0)
errx(1, "pipe closed");

View File

@ -1,4 +1,4 @@
/* $OpenBSD: smtpd.c,v 1.353 2024/11/21 13:17:02 claudio Exp $ */
/* $OpenBSD: smtpd.c,v 1.354 2024/11/21 13:22:21 claudio Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@ -1013,8 +1013,7 @@ imsg_wait(struct imsgbuf *ibuf, struct imsg *imsg, int timeout)
return -1;
}
if (((n = imsgbuf_read(ibuf)) == -1 && errno != EAGAIN) ||
n == 0)
if (imsgbuf_read(ibuf) != 1)
return -1;
}
}