]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
dbus-transport-socket: Handle _DBUS_POLLHUP case in socket_do_iteration
authorGleb Popov <6yearold@gmail.com>
Mon, 19 May 2025 05:39:45 +0000 (08:39 +0300)
committerSimon McVittie <smcv@collabora.com>
Mon, 11 Aug 2025 13:37:56 +0000 (13:37 +0000)
Without this change the bus-normal-activation test on FreeBSD ends up with
a busy-loop under one of malloc failures.

Fixes #553

dbus/dbus-transport-socket.c

index d3c2b914e78f3c00298ec7141142e5f0592b0bb7..1ddb5689e5ac01e99bb6b1a31f8f38ca0e429b2e 100644 (file)
@@ -1208,8 +1208,15 @@ socket_do_iteration (DBusTransport *transport,
             do_io_error (transport);
           else
             {
-              dbus_bool_t need_read = (poll_fd.revents & _DBUS_POLLIN) > 0;
-              dbus_bool_t need_write = (poll_fd.revents & _DBUS_POLLOUT) > 0;
+              /* FreeBSD does not deliver POLLERR when the other side gets disconnected.
+               * Instead it delivers POLLHUP that is not coupled with POLLIN nor POLLOUT.
+               * On the input side, treat this as equivalent to the POLLHUP|POLLIN we
+               * would see in this situation on Linux, so that we will enter
+               * do_reading() and detect the end-of-stream condition; and similarly,
+               * on the output side, treat it as equivalent to POLLHUP|POLLOUT.
+               */
+              dbus_bool_t need_read = (poll_fd.revents & (_DBUS_POLLIN | _DBUS_POLLHUP)) > 0;
+              dbus_bool_t need_write = (poll_fd.revents & (_DBUS_POLLOUT | _DBUS_POLLHUP)) > 0;
              dbus_bool_t authentication_completed;
 
               _dbus_verbose ("in iteration, need_read=%d need_write=%d\n",