From 468ac0367f5d03d60d004025ba1760231265bc0a Mon Sep 17 00:00:00 2001 From: claudio Date: Thu, 20 Jan 2022 18:06:20 +0000 Subject: [PATCH] Make sure that all poll loops properly restart the poll loop on EINTR. Also either fail hard or restart after other errors. In anycase do not look at pollfds after an error. OK benno@ --- usr.sbin/bgpd/bgpd.c | 6 ++++-- usr.sbin/bgpd/rde.c | 8 ++++---- usr.sbin/bgpd/rtr.c | 8 ++++---- usr.sbin/bgpd/session.c | 10 ++++++---- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/usr.sbin/bgpd/bgpd.c b/usr.sbin/bgpd/bgpd.c index b684cb49f45..537d491b142 100644 --- a/usr.sbin/bgpd/bgpd.c +++ b/usr.sbin/bgpd/bgpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.c,v 1.239 2021/07/20 12:07:46 claudio Exp $ */ +/* $OpenBSD: bgpd.c,v 1.240 2022/01/20 18:06:20 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -345,11 +345,13 @@ BROKEN if (pledge("stdio rpath wpath cpath fattr unix route recvfd sendfd", if (timeout < 0 || timeout > MAX_TIMEOUT) timeout = MAX_TIMEOUT; - if (poll(pfd, npfd, timeout * 1000) == -1) + if (poll(pfd, npfd, timeout * 1000) == -1) { if (errno != EINTR) { log_warn("poll error"); quit = 1; } + continue; + } if (handle_pollfd(&pfd[PFD_PIPE_SESSION], ibuf_se) == -1) { log_warnx("main: Lost connection to SE"); diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c index 65696e253e2..0df59326835 100644 --- a/usr.sbin/bgpd/rde.c +++ b/usr.sbin/bgpd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.532 2021/08/09 08:15:34 claudio Exp $ */ +/* $OpenBSD: rde.c,v 1.533 2022/01/20 18:06:20 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -260,9 +260,9 @@ rde_main(int debug, int verbose) timeout = 0; if (poll(pfd, i, timeout) == -1) { - if (errno != EINTR) - fatal("poll error"); - continue; + if (errno == EINTR) + continue; + fatal("poll error"); } if (handle_pollfd(&pfd[PFD_PIPE_MAIN], ibuf_main) == -1) diff --git a/usr.sbin/bgpd/rtr.c b/usr.sbin/bgpd/rtr.c index 11f2741c532..ebfd88a467d 100644 --- a/usr.sbin/bgpd/rtr.c +++ b/usr.sbin/bgpd/rtr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtr.c,v 1.4 2021/09/01 12:39:52 claudio Exp $ */ +/* $OpenBSD: rtr.c,v 1.5 2022/01/20 18:06:20 claudio Exp $ */ /* * Copyright (c) 2020 Claudio Jeker @@ -167,9 +167,9 @@ rtr_main(int debug, int verbose) i += rtr_poll_events(pfd + i, pfd_elms - i, &timeout); if (poll(pfd, i, timeout * 1000) == -1) { - if (errno != EINTR) - fatal("poll error"); - continue; + if (errno == EINTR) + continue; + fatal("poll error"); } if (handle_pollfd(&pfd[PFD_PIPE_MAIN], ibuf_main) == -1) diff --git a/usr.sbin/bgpd/session.c b/usr.sbin/bgpd/session.c index 6b2f3e50877..61224667d72 100644 --- a/usr.sbin/bgpd/session.c +++ b/usr.sbin/bgpd/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.424 2021/09/03 07:48:24 claudio Exp $ */ +/* $OpenBSD: session.c,v 1.425 2022/01/20 18:06:20 claudio Exp $ */ /* * Copyright (c) 2003, 2004, 2005 Henning Brauer @@ -452,9 +452,11 @@ session_main(int debug, int verbose) timeout = 1; if (timeout < 0) timeout = 0; - if (poll(pfd, i, timeout * 1000) == -1) - if (errno != EINTR) - fatal("poll error"); + if (poll(pfd, i, timeout * 1000) == -1) { + if (errno == EINTR) + continue; + fatal("poll error"); + } /* * If we previously saw fd exhaustion, we stop accept() -- 2.20.1