From 4eb2f34170ddeec8de5841feea7bfd9234f32508 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 4 Feb 2015 13:16:18 +0000 Subject: [PATCH 2/2] _dbus_listen_tcp_socket: comment on another reason to ignore EADDRINUSE Not being aware of the second reason described here caused bug #87999 in the equivalent code on Windows. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=87999 --- dbus/dbus-sysdeps-unix.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index f6ec8ab..dcfddd1 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -1463,9 +1463,18 @@ _dbus_listen_tcp_socket (const char *host, _dbus_close(fd, NULL); if (saved_errno == EADDRINUSE) { - /* Depending on kernel policy, it may or may not - be neccessary to bind to both IPv4 & 6 addresses - so ignore EADDRINUSE here */ + /* Depending on kernel policy, binding to an IPv6 address + might implicitly bind to a corresponding IPv4 + address or vice versa, resulting in EADDRINUSE for the + other one (e.g. bindv6only=0 on Linux). + + Also, after we "goto redo_lookup_with_port" after binding + a port on one of the possible addresses, we will + try to bind that same port on every address, including the + same address again for a second time; that one will + also fail with EADDRINUSE. + + For both those reasons, ignore EADDRINUSE here */ tmp = tmp->ai_next; continue; } -- 2.1.4