summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-05-11 16:36:31 -0400
committerJune McEnroe <june@causal.agency>2020-05-11 16:36:31 -0400
commite6ca38288f38707fda5f29f5308d089a54551110 (patch)
tree7c09a5dba301879ce21f44aca0158a77ddd3ea97
parentUse . as ${LDLIBS.$@} separator (diff)
downloadpounce-e6ca38288f38707fda5f29f5308d089a54551110.tar.gz
pounce-e6ca38288f38707fda5f29f5308d089a54551110.zip
Check signals after handling ready sockets
In the case where a signal arrives while handling a ready socket, it
should be handled as soon as possible, rather than waiting for poll to
return again. Signals will still be handled immediately if poll returns
-1 due to EINTR.
Diffstat (limited to '')
-rw-r--r--bounce.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/bounce.c b/bounce.c
index 1aae7a3..21355ea 100644
--- a/bounce.c
+++ b/bounce.c
@@ -458,26 +458,19 @@ int main(int argc, char *argv[]) {
 	eventAdd(server, NULL);
 
 	for (;;) {
-		int nfds = poll(event.fds, event.len, -1);
-		if (nfds < 0 && errno != EINTR) err(EX_IOERR, "poll");
-		if (signals[SIGINT] || signals[SIGTERM]) break;
-
-		if (signals[SIGINFO]) {
-			ringInfo();
-			signals[SIGINFO] = 0;
+		for (size_t i = binds + 1; i < event.len; ++i) {
+			assert(event.clients[i]);
+			if (clientDiff(event.clients[i])) {
+				event.fds[i].events |= POLLOUT;
+			} else {
+				event.fds[i].events &= ~POLLOUT;
+			}
 		}
 
-		if (signals[SIGUSR1]) {
-			cert = splitOpen(certSplit);
-			priv = splitOpen(privSplit);
-			localConfig(cert, priv, localCA, !clientPass);
-			fclose(cert);
-			fclose(priv);
-			signals[SIGUSR1] = 0;
-		}
+		int nfds = poll(event.fds, event.len, -1);
+		if (nfds < 0 && errno != EINTR) err(EX_IOERR, "poll");
 
-		if (nfds < 0) continue;
-		for (size_t i = event.len - 1; i < event.len; --i) {
+		for (size_t i = event.len - 1; nfds > 0 && i < event.len; --i) {
 			short revents = event.fds[i].revents;
 			if (!revents) continue;
 
@@ -514,13 +507,20 @@ int main(int argc, char *argv[]) {
 			}
 		}
 
-		for (size_t i = binds + 1; i < event.len; ++i) {
-			assert(event.clients[i]);
-			if (clientDiff(event.clients[i])) {
-				event.fds[i].events |= POLLOUT;
-			} else {
-				event.fds[i].events &= ~POLLOUT;
-			}
+		if (signals[SIGINT] || signals[SIGTERM]) break;
+
+		if (signals[SIGINFO]) {
+			ringInfo();
+			signals[SIGINFO] = 0;
+		}
+
+		if (signals[SIGUSR1]) {
+			cert = splitOpen(certSplit);
+			priv = splitOpen(privSplit);
+			localConfig(cert, priv, localCA, !clientPass);
+			fclose(cert);
+			fclose(priv);
+			signals[SIGUSR1] = 0;
 		}
 	}