From: Simon McVittie Date: Wed, 4 Feb 2015 13:16:18 +0000 (+0000) Subject: _dbus_listen_tcp_socket: comment on another reason to ignore EADDRINUSE X-Git-Tag: dbus-1.9.10~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f05dc97445a84f226cf9c055c9d3ed70ed6c7b4;p=thirdparty%2Fdbus.git _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 --- diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index f6ec8abc5..dcfddd17c 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; }