Fix sendto_kdc.c on OS X after cm refactoring
authorGreg Hudson <ghudson@mit.edu>
Fri, 4 Apr 2014 18:58:33 +0000 (14:58 -0400)
committerGreg Hudson <ghudson@mit.edu>
Sat, 5 Apr 2014 21:50:08 +0000 (17:50 -0400)
Treat POLLHUP without POLLIN or POLLOUT as an exception in the poll
version of cm_get_ssflags, to correctly handle TCP connection errors
on OS X.

src/lib/krb5/os/sendto_kdc.c

index e773a0ad9096adfcd207c4840dbf5ea04b3b80c8..67e2a600c9ed7d8767ba97910a93fa50b12ff32f 100644 (file)
@@ -179,6 +179,15 @@ cm_get_ssflags(struct select_state *selstate, int fd)
 {
     struct pollfd *pfd = find_pollfd(selstate, fd);
 
+    /*
+     * OS X sets POLLHUP without POLLOUT on connection error.  Catch this as
+     * well as other error events such as POLLNVAL, but only if POLLIN and
+     * POLLOUT aren't set, as we can get POLLHUP along with POLLIN with TCP
+     * data still to be read.
+     */
+    if (pfd->revents != 0 && !(pfd->revents & (POLLIN | POLLOUT)))
+        return SSF_EXCEPTION;
+
     return ((pfd->revents & POLLIN) ? SSF_READ : 0) |
         ((pfd->revents & POLLOUT) ? SSF_WRITE : 0) |
         ((pfd->revents & POLLERR) ? SSF_EXCEPTION : 0);