From f2dc63d0444525a759fc1a395e996276cec35dca Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 16 Oct 2014 18:18:04 +0100 Subject: [PATCH 8/8] Distinguish between local and remote disconnection --- bus/connection.c | 3 ++- dbus/dbus-errors.c | 2 ++ dbus/dbus-protocol.h | 2 ++ dbus/dbus-transport-socket.c | 6 +++--- test/corrupt.c | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/bus/connection.c b/bus/connection.c index a7fbf9c..9b75d82 100644 --- a/bus/connection.c +++ b/bus/connection.c @@ -205,7 +205,8 @@ bus_connection_disconnected (DBusConnection *connection) _dbus_assert_not_reached ("should already be disconnected"); } - if (strcmp (error.name, DBUS_ERROR_DISCONNECTED) != 0) + if (strcmp (error.name, DBUS_ERROR_DISCONNECTED) != 0 && + strcmp (error.name, DBUS_ERROR_END_OF_STREAM) != 0) { bus_context_log (d->connections->context, DBUS_SYSTEM_LOG_INFO, diff --git a/dbus/dbus-errors.c b/dbus/dbus-errors.c index ca7045b..fb51a2f 100644 --- a/dbus/dbus-errors.c +++ b/dbus/dbus-errors.c @@ -125,6 +125,8 @@ message_from_error (const char *error) return "File doesn't exist."; else if (strcmp (error, DBUS_ERROR_OBJECT_PATH_IN_USE) == 0) return "Object path already in use"; + else if (strcmp (error, DBUS_ERROR_END_OF_STREAM) == 0) + return "Disconnected by other end of connection"; else return error; } diff --git a/dbus/dbus-protocol.h b/dbus/dbus-protocol.h index 60605ab..c0df3ee 100644 --- a/dbus/dbus-protocol.h +++ b/dbus/dbus-protocol.h @@ -446,6 +446,8 @@ extern "C" { /** The message meta data does not match the payload. e.g. expected number of file descriptors were not sent over the socket this message was received on. */ #define DBUS_ERROR_INCONSISTENT_MESSAGE "org.freedesktop.DBus.Error.InconsistentMessage" +/** The other end of the connection closed it. */ +#define DBUS_ERROR_END_OF_STREAM "org.freedesktop.DBus.Error.EndOfStream" /* XML introspection format */ diff --git a/dbus/dbus-transport-socket.c b/dbus/dbus-transport-socket.c index 2f8cc20..deb4d0a 100644 --- a/dbus/dbus-transport-socket.c +++ b/dbus/dbus-transport-socket.c @@ -298,7 +298,7 @@ read_data_into_auth (DBusTransport *transport, _dbus_assert (bytes_read == 0); _dbus_verbose ("Disconnected from remote app\n"); - do_io_error (transport, DBUS_ERROR_DISCONNECTED, NULL); + do_io_error (transport, DBUS_ERROR_END_OF_STREAM, NULL); return FALSE; } @@ -894,7 +894,7 @@ do_reading (DBusTransport *transport) else if (bytes_read == 0) { _dbus_verbose ("Disconnected from remote app\n"); - do_io_error (transport, DBUS_ERROR_DISCONNECTED, NULL); + do_io_error (transport, DBUS_ERROR_END_OF_STREAM, NULL); goto out; } else @@ -962,7 +962,7 @@ socket_handle_watch (DBusTransport *transport, { _dbus_verbose ("Hang up or error on watch\n"); /* FIXME: should this be treated as abnormal disconnection? */ - _dbus_transport_disconnect (transport, DBUS_ERROR_DISCONNECTED, NULL); + _dbus_transport_disconnect (transport, DBUS_ERROR_END_OF_STREAM, NULL); return TRUE; } diff --git a/test/corrupt.c b/test/corrupt.c index 8447d0c..4cf56d3 100644 --- a/test/corrupt.c +++ b/test/corrupt.c @@ -342,7 +342,7 @@ test_byte_order (Fixture *f, connected = dbus_connection_check_connected (f->server_conn, &f->e); g_assert (!connected); - g_assert_cmpstr (f->e.name, ==, DBUS_ERROR_DISCONNECTED); + g_assert_cmpstr (f->e.name, ==, DBUS_ERROR_END_OF_STREAM); g_message ("sender of corrupt message got: %s: %s", f->e.name, f->e.message); dbus_error_free (&f->e); -- 2.1.1