src/server/daemon/event_bsd.c

changeset 547
280bf87c8689
parent 541
1e1fca11aaff
child 552
4ed0e46aa9dc
--- a/src/server/daemon/event_bsd.c	Tue Aug 13 20:08:13 2024 +0200
+++ b/src/server/daemon/event_bsd.c	Thu Aug 15 21:46:57 2024 +0200
@@ -64,6 +64,19 @@
     return ev;
 }
 
+static volatile int ev_close = 0;
+
+void ev_instance_close(EventHandler *h) {
+    EventHandlerKqueue *ev = (EventHandlerKqueue*)h;
+    close(ev->kqueue);
+    ev_close = 1;
+}
+
+// unique event addr that indicates shutdown
+static Event shutdown_event;
+void ev_instance_shutdown(EventHandler *h) {
+    event_send(h, &shutdown_event);
+}
 
 void ev_handle_events(EventHandlerKqueue *ev) {
     EventHandler *h = (EventHandler*)ev;
@@ -81,7 +94,12 @@
         // wait for events
         int nev = kevent(ev->kqueue, changes, numchanges, events, EV_MAX_EVENTS, &timeout);  
         if(nev == -1) {
-            log_ereport(LOG_FAILURE, "kevent: %s", strerror(errno));
+            if(errno != EINTR) {
+                if(!ev_close) {
+                    log_ereport(LOG_CATASTROPHE, "kevent failed: %s", strerror(errno));
+                }
+                break;
+            }
             continue;
         }
         
@@ -140,6 +158,8 @@
                         }
                     }
                 }
+            } else if(event == &shutdown_event) {
+                ev_instance_close(h);
             }
         }
         // call event finish handlers
@@ -156,6 +176,8 @@
             nsapi_saf_return(ret.sn, ret.rq, ret.ret);
         }
     }
+    
+    free(ev);
 }
 
 int ev_pollin(EventHandler *h, int fd, Event *event) {

mercurial