From 047ae0b77a64050658bd119e216e56e383e9946c Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 8 Mar 2018 14:37:39 +0000 Subject: [PATCH] Unix _dbus_connect_tcp_socket_with_nonce: Combine all connect() errors Previously, we took the errno from the most recent connect() error, and used a more generic diagnostic message. Signed-off-by: Simon McVittie https://bugs.freedesktop.org/show_bug.cgi?id=61922 --- dbus/dbus-sysdeps-unix.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 55c91026..73c59acb 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -1355,10 +1355,12 @@ _dbus_connect_tcp_socket_with_nonce (const char *host, DBusError *error) { int saved_errno = 0; + DBusList *connect_errors = NULL; DBusSocket fd = DBUS_SOCKET_INIT; int res; struct addrinfo hints; struct addrinfo *ai, *tmp; + DBusError *connect_error; _DBUS_ASSERT_ERROR_IS_CLEAR(error); @@ -1408,6 +1410,29 @@ _dbus_connect_tcp_socket_with_nonce (const char *host, saved_errno = errno; _dbus_close (fd.fd, NULL); _dbus_socket_invalidate (&fd); + + connect_error = dbus_new0 (DBusError, 1); + + if (connect_error == NULL) + { + _DBUS_SET_OOM (error); + goto out; + } + + dbus_error_init (connect_error); + _dbus_set_error_with_inet_sockaddr (connect_error, + tmp->ai_addr, tmp->ai_addrlen, + "Failed to connect to socket", + saved_errno); + + if (!_dbus_list_append (&connect_errors, connect_error)) + { + dbus_error_free (connect_error); + dbus_free (connect_error); + _DBUS_SET_OOM (error); + goto out; + } + tmp = tmp->ai_next; continue; } @@ -1418,10 +1443,8 @@ _dbus_connect_tcp_socket_with_nonce (const char *host, if (!_dbus_socket_is_valid (fd)) { - dbus_set_error (error, - _dbus_error_from_errno (saved_errno), - "Failed to connect to socket \"%s:%s\" %s", - host, port, _dbus_strerror(saved_errno)); + _dbus_combine_tcp_errors (&connect_errors, "Failed to connect", + host, port, error); goto out; } @@ -1449,6 +1472,12 @@ _dbus_connect_tcp_socket_with_nonce (const char *host, } out: + while ((connect_error = _dbus_list_pop_first (&connect_errors))) + { + dbus_error_free (connect_error); + dbus_free (connect_error); + } + return fd; } -- 2.12.3