Commit 6c5be2e1 authored by Simon McVittie's avatar Simon McVittie Committed by Ralf Habacker

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.
Reviewed-by: Ralf Habacker's avatarRalf Habacker <ralf.habacker@freenet.de>
Signed-off-by: Simon McVittie's avatarSimon McVittie <smcv@collabora.com>
https://bugs.freedesktop.org/show_bug.cgi?id=61922
parent 23fb2801
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment