diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2022-02-08 14:57:05 +0400 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2022-07-15 16:26:18 +0100 |
commit | 581344c17daa7bb77b7456644020bc709cacc9a4 (patch) | |
tree | 25a9dbed65039246523e3863f281375696a9f27c /dbus/dbus-sysdeps-unix.c | |
parent | 7d20a3c6049f96f396ac757a6954554dfb6452c8 (diff) | |
download | dbus-581344c17daa7bb77b7456644020bc709cacc9a4.tar.gz |
dbus: set the socket as invalid in _dbus_close_socket()
This can simplify error handling in many situation where a socket is
returned, such as in the following commits.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Diffstat (limited to 'dbus/dbus-sysdeps-unix.c')
-rw-r--r-- | dbus/dbus-sysdeps-unix.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 152a3862..c77adc09 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -297,8 +297,12 @@ _dbus_open_unix_socket (int *fd, } /** - * Closes a socket. Should not be used on non-socket - * file descriptors or handles. + * Closes a socket and invalidates it. Should not be used on non-socket file + * descriptors or handles. + * + * If an error is detected, this function returns #FALSE and sets the error, but + * the socket is still closed and invalidated. Callers can use the error in a + * diagnostic message, but should not retry closing the socket. * * @param fd the socket * @param error return location for an error @@ -308,10 +312,15 @@ dbus_bool_t _dbus_close_socket (DBusSocket *fd, DBusError *error) { + dbus_bool_t rv; + _dbus_assert (fd != NULL); _DBUS_ASSERT_ERROR_IS_CLEAR (error); - return _dbus_close (fd->fd, error); + rv = _dbus_close (fd->fd, error); + _dbus_socket_invalidate (fd); + + return rv; } /** |