]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sched: allow file handler with multiple events to remove itself
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 31 Jul 2018 14:44:43 +0000 (16:44 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 3 Aug 2018 15:21:02 +0000 (17:21 +0200)
Before dispatching a handler, check if it is still valid. This allows a
handler to remove itself when a descriptor has two different events at
the same time.

sched.c

diff --git a/sched.c b/sched.c
index 45ef11c55caea5ef7f3f7b69fffe3e30551897de..fce9f0684e86d1b73be34d23e1f3bfa513e0425c 100644 (file)
--- a/sched.c
+++ b/sched.c
@@ -534,7 +534,8 @@ dispatch_filehandlers(int nfd, fd_set *read_fds, fd_set *write_fds, fd_set *exce
     if (except_fds && FD_ISSET(fd, except_fds)) {
       /* This descriptor has an exception, dispatch its handler */
       ptr = (FileHandlerEntry *)ARR_GetElement(file_handlers, fd);
-      (ptr->handler)(fd, SCH_FILE_EXCEPTION, ptr->arg);
+      if (ptr->handler)
+        (ptr->handler)(fd, SCH_FILE_EXCEPTION, ptr->arg);
       nfd--;
 
       /* Don't try to read from it now */
@@ -547,14 +548,16 @@ dispatch_filehandlers(int nfd, fd_set *read_fds, fd_set *write_fds, fd_set *exce
     if (read_fds && FD_ISSET(fd, read_fds)) {
       /* This descriptor can be read from, dispatch its handler */
       ptr = (FileHandlerEntry *)ARR_GetElement(file_handlers, fd);
-      (ptr->handler)(fd, SCH_FILE_INPUT, ptr->arg);
+      if (ptr->handler)
+        (ptr->handler)(fd, SCH_FILE_INPUT, ptr->arg);
       nfd--;
     }
 
     if (write_fds && FD_ISSET(fd, write_fds)) {
       /* This descriptor can be written to, dispatch its handler */
       ptr = (FileHandlerEntry *)ARR_GetElement(file_handlers, fd);
-      (ptr->handler)(fd, SCH_FILE_OUTPUT, ptr->arg);
+      if (ptr->handler)
+        (ptr->handler)(fd, SCH_FILE_OUTPUT, ptr->arg);
       nfd--;
     }
   }