Handle EINTR the same way in all poll loops. In all cases restart the
authorclaudio <claudio@openbsd.org>
Sun, 23 Jan 2022 12:09:24 +0000 (12:09 +0000)
committerclaudio <claudio@openbsd.org>
Sun, 23 Jan 2022 12:09:24 +0000 (12:09 +0000)
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
usr.sbin/rpki-client/http.c
usr.sbin/rpki-client/main.c
usr.sbin/rpki-client/parser.c
usr.sbin/rpki-client/repo.c
usr.sbin/rpki-client/rrdp.c

index 44585ad..66a460c 100644 (file)
@@ -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 <kristaps@bsd.lv>
  *
@@ -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). */
 
index 20cbd3c..117c706 100644 (file)
@@ -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 <nils_fisher@hotmail.com>
  * Copyright (c) 2020 Claudio Jeker <claudio@openbsd.org>
@@ -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;
index 2031572..746f0c4 100644 (file)
@@ -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 <claudio@openbsd.org>
  * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -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
index 491151c..17d6c26 100644 (file)
@@ -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 <claudio@openbsd.org>
  * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -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");
 
index 773290d..7242ed2 100644 (file)
@@ -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 <claudio@openbsd.org>
  * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -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 **
index 80c22b9..4d39421 100644 (file)
@@ -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 <nils_fisher@hotmail.com>
  * Copyright (c) 2021 Claudio Jeker <claudio@openbsd.org>
@@ -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;