summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2020-10-01 11:06:48 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2020-10-01 11:06:48 +0000
commita8c002835a79e198cf33c4361ce727efdbb82f94 (patch)
tree47a2bc2baa13ffe354db9d526d10623e1ce39168
parent59be033cf0ba57827e08b540ac3dbbef79ba5d43 (diff)
Rewrite the signal handler to just toggle a flag and then exit asap
in the main loop. This removes a few portability issues. OK benno@
-rw-r--r--usr.sbin/rpki-client/main.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/usr.sbin/rpki-client/main.c b/usr.sbin/rpki-client/main.c
index 2d4b7bd1d4a..cb704faab75 100644
--- a/usr.sbin/rpki-client/main.c
+++ b/usr.sbin/rpki-client/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.81 2020/10/01 10:25:26 claudio Exp $ */
+/* $OpenBSD: main.c,v 1.82 2020/10/01 11:06:47 claudio Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -89,6 +89,7 @@ struct repo {
};
int timeout = 60*60;
+volatile sig_atomic_t killme;
void suicide(int sig);
/*
@@ -1357,15 +1358,8 @@ repo_cleanup(const char *cachedir)
void
suicide(int sig __attribute__((unused)))
{
- struct syslog_data sdata = SYSLOG_DATA_INIT;
-
-
- dprintf(STDERR_FILENO,
- "%s: excessive runtime (%d seconds), giving up\n",
- getprogname(), timeout);
- syslog_r(LOG_CRIT|LOG_DAEMON, &sdata,
- "excessive runtime (%d seconds), giving up", timeout);
- _exit(1);
+ killme = 1;
+
}
int
@@ -1576,9 +1570,12 @@ main(int argc, char *argv[])
pfd[1].fd = proc;
pfd[0].events = pfd[1].events = POLLIN;
- while (!TAILQ_EMPTY(&q)) {
- if ((c = poll(pfd, 2, verbose ? 10000 : INFTIM)) == -1)
+ while (!TAILQ_EMPTY(&q) && !killme) {
+ if ((c = poll(pfd, 2, verbose ? 10000 : INFTIM)) == -1) {
+ if (errno == EINTR)
+ continue;
err(1, "poll");
+ }
/* Debugging: print some statistics if we stall. */
@@ -1641,6 +1638,12 @@ main(int argc, char *argv[])
}
}
+ if (killme) {
+ syslog(LOG_CRIT|LOG_DAEMON,
+ "excessive runtime (%d seconds), giving up", timeout);
+ errx(1, "excessive runtime (%d seconds), giving up", timeout);
+ }
+
assert(TAILQ_EMPTY(&q));
logx("all files parsed: generating output");
rc = 0;