I found a problem with input_handler(). If a reference clock
passes a blocking file descriptor, input_handler can block
forever. Symptoms include but are not limited to UDP sockets not
working, several signal types being ignored, and the main loop
stopping in its' tracks. I've included a patch to handle it for
you, but there has to be a better way.
From 2da42fec2b314fa9dd60ab4190b6b686f7eeeca0 Mon Sep 17 00:00:00 2001
From: James Browning <jamesb.f...@gmail.com>
Date: Fri, 3 Feb 2023 11:14:54 -0800
Subject: [PATCH] Fix a small issue in input_handler with excessive glue.

---
 ntpd/ntp_io.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/ntpd/ntp_io.c b/ntpd/ntp_io.c
index 0b00cd1c9..d1abe3071 100644
--- a/ntpd/ntp_io.c
+++ b/ntpd/ntp_io.c
@@ -2355,9 +2355,26 @@ input_handler(
 			maintain_activefds(fd, true);
 		} else {
 			/* drain any remaining refclock input */
-			do {
-				buflen = read_refclock_packet(fd, rp);
-			} while (buflen > 0);
+			do
+			{
+				fd_set rfds;
+				struct timespec no = {0, 0};
+				FD_ZERO(&rfds);
+				FD_SET(fd, &rfds);
+				if(1 == pselect(
+					    fd + 1, &rfds, NULL, NULL,
+					    &no, NULL
+					))
+				{
+					buflen = read_refclock_packet(
+					    fd, rp
+					);
+				}
+				else
+				{
+					buflen = 0;
+				}
+			} while(buflen > 0);
 		}
 	}
 #endif /* REFCLOCK */
-- 
2.38.1

_______________________________________________
devel mailing list
devel@ntpsec.org
https://lists.ntpsec.org/mailman/listinfo/devel

Reply via email to