]> mj.ucw.cz Git - libucw.git/commitdiff
Mainloop: Be benevolent when file_del() is called on a closed fd
authorMartin Mares <mj@ucw.cz>
Sun, 9 Nov 2014 12:32:28 +0000 (13:32 +0100)
committerMartin Mares <mj@ucw.cz>
Sun, 9 Nov 2014 12:32:28 +0000 (13:32 +0100)
I recently wrote a couple of wrappers for connecting other mainloop
interfaces to UCW mainloop. Unfortunately, asking a mainloop to stop
watching a file a moment after close() is a common (mal)practice.
Working around it in the wrapper is hard to do, so I relax the checks
in LibUCW instead.

ucw/mainloop.c

index 091b5f186957c152ee3a4bc437679f6a4b7953d6..46604d869174a455ed23e7ee9cd260a046b78806 100644 (file)
@@ -360,7 +360,11 @@ file_del_ctx(struct main_context *m, struct main_file *fi)
   m->file_cnt--;
 #ifdef CONFIG_UCW_EPOLL
   if (m->epoll_fd >= 0 && epoll_ctl(m->epoll_fd, EPOLL_CTL_DEL, fi->fd, NULL) < 0)
-    die("epoll_ctl() failed: %m");
+    {
+      // Some clients call file_del() on an already closed descriptor. Trying to be benevolent.
+      if (errno != EBADF)
+       die("epoll_ctl() failed: %m");
+    }
 #else
   m->poll_table_obsolete = 1;
 #endif