Make all poll loops handle EINTR in the same way. Now since the loop is
restarted not poll related functions need to be called in that part of the
code. In rpki-client this only matters for the repo timeout. By merging
repo_next_timeout() and repo_check_timeout() together this function can be
moved above poll().

The http idle timeout handling has a similar issue but it also depends on
revents. Changing that is more complex.

-- 
:wq Claudio

Index: extern.h
===================================================================
RCS file: /cvs/src/usr.sbin/rpki-client/extern.h,v
retrieving revision 1.113
diff -u -p -r1.113 extern.h
--- extern.h    23 Jan 2022 05:59:35 -0000      1.113
+++ extern.h    23 Jan 2022 08:37:42 -0000
@@ -528,9 +528,7 @@ void                 http_fetch(unsigned int, const ch
 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: http.c
===================================================================
RCS file: /cvs/src/usr.sbin/rpki-client/http.c,v
retrieving revision 1.51
diff -u -p -r1.51 http.c
--- http.c      22 Dec 2021 09:35:14 -0000      1.51
+++ http.c      23 Jan 2022 07:35:28 -0000
@@ -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: main.c
===================================================================
RCS file: /cvs/src/usr.sbin/rpki-client/main.c,v
retrieving revision 1.181
diff -u -p -r1.181 main.c
--- main.c      21 Jan 2022 18:49:44 -0000      1.181
+++ main.c      23 Jan 2022 08:37:48 -0000
@@ -1075,7 +1075,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)
@@ -1106,8 +1106,6 @@ main(int argc, char *argv[])
                }
                if (hangup)
                        break;
-
-               repo_check_timeout();
 
                /*
                 * Check the rsync and http process.
Index: parser.c
===================================================================
RCS file: /cvs/src/usr.sbin/rpki-client/parser.c,v
retrieving revision 1.51
diff -u -p -r1.51 parser.c
--- parser.c    23 Jan 2022 05:59:35 -0000      1.51
+++ parser.c    23 Jan 2022 07:37:07 -0000
@@ -1071,8 +1071,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: repo.c
===================================================================
RCS file: /cvs/src/usr.sbin/rpki-client/repo.c,v
retrieving revision 1.25
diff -u -p -r1.25 repo.c
--- repo.c      14 Jan 2022 15:00:23 -0000      1.25
+++ repo.c      23 Jan 2022 08:37:36 -0000
@@ -1165,27 +1165,6 @@ repo_queued(struct repo *rp, struct enti
        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: rrdp.c
===================================================================
RCS file: /cvs/src/usr.sbin/rpki-client/rrdp.c,v
retrieving revision 1.20
diff -u -p -r1.20 rrdp.c
--- rrdp.c      13 Jan 2022 13:18:41 -0000      1.20
+++ rrdp.c      20 Jan 2022 18:08:21 -0000
@@ -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;

Reply via email to