From 16b0c81bb5f6edbf5168189a20f4f8992d1e7bb5 Mon Sep 17 00:00:00 2001 From: claudio Date: Thu, 21 Nov 2024 13:22:21 +0000 Subject: [PATCH] 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@ --- usr.sbin/bgpd/bgpd.c | 4 ++-- usr.sbin/bgpd/control.c | 17 ++++++++++------- usr.sbin/smtpd/ca.c | 6 +++--- usr.sbin/smtpd/enqueue.c | 4 ++-- usr.sbin/smtpd/mproc.c | 16 +++++++++------- usr.sbin/smtpd/queue_proc.c | 4 ++-- usr.sbin/smtpd/scheduler_proc.c | 4 ++-- usr.sbin/smtpd/smtpctl.c | 4 ++-- usr.sbin/smtpd/smtpd.c | 5 ++--- 9 files changed, 34 insertions(+), 30 deletions(-) diff --git a/usr.sbin/bgpd/bgpd.c b/usr.sbin/bgpd/bgpd.c index 8e34809d92d..6e5836a10e5 100644 --- a/usr.sbin/bgpd/bgpd.c +++ b/usr.sbin/bgpd/bgpd.c @@ -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 @@ -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; diff --git a/usr.sbin/bgpd/control.c b/usr.sbin/bgpd/control.c index 3f5540ddabe..ea9b1f8730f 100644 --- a/usr.sbin/bgpd/control.c +++ b/usr.sbin/bgpd/control.c @@ -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 @@ -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); } diff --git a/usr.sbin/smtpd/ca.c b/usr.sbin/smtpd/ca.c index 214312b865c..b41d655b29c 100644 --- a/usr.sbin/smtpd/ca.c +++ b/usr.sbin/smtpd/ca.c @@ -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 @@ -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"); diff --git a/usr.sbin/smtpd/enqueue.c b/usr.sbin/smtpd/enqueue.c index a8e003fae5d..a901482be03 100644 --- a/usr.sbin/smtpd/enqueue.c +++ b/usr.sbin/smtpd/enqueue.c @@ -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 @@ -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"); diff --git a/usr.sbin/smtpd/mproc.c b/usr.sbin/smtpd/mproc.c index 561ce04e989..2f7d279b5b9 100644 --- a/usr.sbin/smtpd/mproc.c +++ b/usr.sbin/smtpd/mproc.c @@ -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 @@ -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 diff --git a/usr.sbin/smtpd/queue_proc.c b/usr.sbin/smtpd/queue_proc.c index 81530f5128a..f406693b12f 100644 --- a/usr.sbin/smtpd/queue_proc.c +++ b/usr.sbin/smtpd/queue_proc.c @@ -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 @@ -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; } diff --git a/usr.sbin/smtpd/scheduler_proc.c b/usr.sbin/smtpd/scheduler_proc.c index ba815c46ec2..7be5ded442c 100644 --- a/usr.sbin/smtpd/scheduler_proc.c +++ b/usr.sbin/smtpd/scheduler_proc.c @@ -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 @@ -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; } diff --git a/usr.sbin/smtpd/smtpctl.c b/usr.sbin/smtpd/smtpctl.c index 9293a704532..c403d217d97 100644 --- a/usr.sbin/smtpd/smtpctl.c +++ b/usr.sbin/smtpd/smtpctl.c @@ -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 @@ -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"); diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c index 40ffc6c35f2..0e3a7854aae 100644 --- a/usr.sbin/smtpd/smtpd.c +++ b/usr.sbin/smtpd/smtpd.c @@ -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 @@ -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; } }