From 7ba5db230c0ff2715181699543fde49e05c11225 Mon Sep 17 00:00:00 2001 From: claudio Date: Sun, 23 Jan 2022 12:09:24 +0000 Subject: [PATCH] Handle EINTR the same way in all poll loops. In all cases restart the poll loop. In the main process move the timeout handling for repositories into a single function that does the timeouts and the calculation of the timeout in one go. OK tb@ --- usr.sbin/rpki-client/extern.h | 6 ++---- usr.sbin/rpki-client/http.c | 7 +++++-- usr.sbin/rpki-client/main.c | 6 ++---- usr.sbin/rpki-client/parser.c | 7 +++++-- usr.sbin/rpki-client/repo.c | 33 +++++++++------------------------ usr.sbin/rpki-client/rrdp.c | 7 +++++-- 6 files changed, 28 insertions(+), 38 deletions(-) diff --git a/usr.sbin/rpki-client/extern.h b/usr.sbin/rpki-client/extern.h index 44585adc15c..66a460c4aea 100644 --- a/usr.sbin/rpki-client/extern.h +++ b/usr.sbin/rpki-client/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.113 2022/01/23 05:59:35 claudio Exp $ */ +/* $OpenBSD: extern.h,v 1.114 2022/01/23 12:09:24 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -528,9 +528,7 @@ void http_fetch(unsigned int, const char *, const char *, int); void rrdp_fetch(unsigned int, const char *, const char *, struct rrdp_session *); void rrdp_http_done(unsigned int, enum http_result, const char *); - -int repo_next_timeout(int); -void repo_check_timeout(void); +int repo_check_timeout(int); /* Logging (though really used for OpenSSL errors). */ diff --git a/usr.sbin/rpki-client/http.c b/usr.sbin/rpki-client/http.c index 20cbd3cd75f..117c706885c 100644 --- a/usr.sbin/rpki-client/http.c +++ b/usr.sbin/rpki-client/http.c @@ -1,4 +1,4 @@ -/* $OpenBSD: http.c,v 1.51 2021/12/22 09:35:14 claudio Exp $ */ +/* $OpenBSD: http.c,v 1.52 2022/01/23 12:09:24 claudio Exp $ */ /* * Copyright (c) 2020 Nils Fisher * Copyright (c) 2020 Claudio Jeker @@ -1847,8 +1847,11 @@ proc_http(char *bind_addr, int fd) errx(1, "too many connections"); } - if (poll(pfds, i, timeout) == -1) + if (poll(pfds, i, timeout) == -1) { + if (errno == EINTR) + continue; err(1, "poll"); + } if (pfds[0].revents & POLLHUP) break; diff --git a/usr.sbin/rpki-client/main.c b/usr.sbin/rpki-client/main.c index 20315728a1a..746f0c4d029 100644 --- a/usr.sbin/rpki-client/main.c +++ b/usr.sbin/rpki-client/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.182 2022/01/23 07:21:12 claudio Exp $ */ +/* $OpenBSD: main.c,v 1.183 2022/01/23 12:09:24 claudio Exp $ */ /* * Copyright (c) 2021 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -1078,7 +1078,7 @@ main(int argc, char *argv[]) pfd[i].events |= POLLOUT; } - polltim = repo_next_timeout(INFTIM); + polltim = repo_check_timeout(INFTIM); if ((c = poll(pfd, NPFD, polltim)) == -1) { if (errno == EINTR) @@ -1110,8 +1110,6 @@ main(int argc, char *argv[]) if (hangup) break; - repo_check_timeout(); - /* * Check the rsync and http process. * This means that one of our modules has completed diff --git a/usr.sbin/rpki-client/parser.c b/usr.sbin/rpki-client/parser.c index 491151c82cb..17d6c262fdc 100644 --- a/usr.sbin/rpki-client/parser.c +++ b/usr.sbin/rpki-client/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.52 2022/01/23 07:21:12 claudio Exp $ */ +/* $OpenBSD: parser.c,v 1.53 2022/01/23 12:09:24 claudio Exp $ */ /* * Copyright (c) 2019 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -1081,8 +1081,11 @@ proc_parser(int fd) if (msgq.queued) pfd.events |= POLLOUT; - if (poll(&pfd, 1, INFTIM) == -1) + if (poll(&pfd, 1, INFTIM) == -1) { + if (errno == EINTR) + continue; err(1, "poll"); + } if ((pfd.revents & (POLLERR|POLLNVAL))) errx(1, "poll: bad descriptor"); diff --git a/usr.sbin/rpki-client/repo.c b/usr.sbin/rpki-client/repo.c index 773290dc055..7242ed24536 100644 --- a/usr.sbin/rpki-client/repo.c +++ b/usr.sbin/rpki-client/repo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: repo.c,v 1.25 2022/01/14 15:00:23 claudio Exp $ */ +/* $OpenBSD: repo.c,v 1.26 2022/01/23 12:09:24 claudio Exp $ */ /* * Copyright (c) 2021 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -1165,27 +1165,6 @@ repo_queued(struct repo *rp, struct entity *p) return 0; } -int -repo_next_timeout(int timeout) -{ - struct repo *rp; - time_t now; - - now = getmonotime(); - /* Look up in repository table. (Lookup should actually fail here) */ - SLIST_FOREACH(rp, &repos, entry) { - if (repo_state(rp) == REPO_LOADING) { - int diff = rp->alarm - now; - if (diff < 0) - diff = 0; - diff *= 1000; - if (timeout == INFTIM || diff < timeout) - timeout = diff; - } - } - return timeout; -} - static void repo_fail(struct repo *rp) { @@ -1202,8 +1181,8 @@ repo_fail(struct repo *rp) errx(1, "%s: bad repo", rp->repouri); } -void -repo_check_timeout(void) +int +repo_check_timeout(int timeout) { struct repo *rp; time_t now; @@ -1216,9 +1195,15 @@ repo_check_timeout(void) warnx("%s: synchronisation timeout", rp->repouri); repo_fail(rp); + } else { + int diff = rp->alarm - now; + diff *= 1000; + if (timeout == INFTIM || diff < timeout) + timeout = diff; } } } + return timeout; } static char ** diff --git a/usr.sbin/rpki-client/rrdp.c b/usr.sbin/rpki-client/rrdp.c index 80c22b97207..4d3942105b1 100644 --- a/usr.sbin/rpki-client/rrdp.c +++ b/usr.sbin/rpki-client/rrdp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rrdp.c,v 1.20 2022/01/13 13:18:41 claudio Exp $ */ +/* $OpenBSD: rrdp.c,v 1.21 2022/01/23 12:09:24 claudio Exp $ */ /* * Copyright (c) 2020 Nils Fisher * Copyright (c) 2021 Claudio Jeker @@ -554,8 +554,11 @@ proc_rrdp(int fd) if (msgq.queued) pfds[0].events |= POLLOUT; - if (poll(pfds, i, INFTIM) == -1) + if (poll(pfds, i, INFTIM) == -1) { + if (errno == EINTR) + continue; err(1, "poll"); + } if (pfds[0].revents & POLLHUP) break; -- 2.20.1