mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-01-19 21:20:34 +01:00
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 <ralf.habacker@freenet.de> Signed-off-by: Simon McVittie <smcv@collabora.com> https://bugs.freedesktop.org/show_bug.cgi?id=61922
This commit is contained in:
parent
23fb280143
commit
6c5be2e146
1 changed files with 33 additions and 4 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue