summaryrefslogtreecommitdiff
path: root/bus/dispatch.c
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2015-01-23 19:11:31 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2015-02-04 17:15:08 +0000
commit00af6389be46d65afcce8cdfd060f278aaaa9466 (patch)
treef5f32aadd98ef4e46b97453a01fa582600acba4b /bus/dispatch.c
parent4a0f1849be319b1b2b7a6d415b57e5544ec191d6 (diff)
downloaddbus-00af6389be46d65afcce8cdfd060f278aaaa9466.tar.gz
Add support for morphing a D-Bus connection into a "monitor"
This is a special connection that is not allowed to send anything, and loses all its well-known names. In future commits, it will get a new set of match rules and the ability to eavesdrop on messages before the rest of the bus daemon has had a chance to process them. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=46787 Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
Diffstat (limited to 'bus/dispatch.c')
-rw-r--r--bus/dispatch.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/bus/dispatch.c b/bus/dispatch.c
index 8f322f8c..97fe3712 100644
--- a/bus/dispatch.c
+++ b/bus/dispatch.c
@@ -47,6 +47,13 @@
* dbus_connection_open_private() does not block. */
#define TEST_DEBUG_PIPE "debug-pipe:name=test-server"
+static inline const char *
+nonnull (const char *maybe_null,
+ const char *if_null)
+{
+ return (maybe_null ? maybe_null : if_null);
+}
+
static dbus_bool_t
send_one_message (DBusConnection *connection,
BusContext *context,
@@ -200,6 +207,54 @@ bus_dispatch (DBusConnection *connection,
/* Ref connection in case we disconnect it at some point in here */
dbus_connection_ref (connection);
+ /* Monitors aren't meant to send messages to us. */
+ if (bus_connection_is_monitor (connection))
+ {
+ sender = bus_connection_get_name (connection);
+
+ /* should never happen */
+ if (sender == NULL)
+ sender = "(unknown)";
+
+ if (dbus_message_is_signal (message,
+ DBUS_INTERFACE_LOCAL,
+ "Disconnected"))
+ {
+ bus_context_log (context, DBUS_SYSTEM_LOG_INFO,
+ "Monitoring connection %s closed.", sender);
+ bus_connection_disconnected (connection);
+ goto out;
+ }
+ else
+ {
+ /* Monitors are not allowed to send messages, because that
+ * probably indicates that the monitor is incorrectly replying
+ * to its eavesdropped messages, and we want the authors of
+ * such monitors to fix them.
+ */
+ bus_context_log (context, DBUS_SYSTEM_LOG_WARNING,
+ "Monitoring connection %s (%s) is not allowed "
+ "to send messages; closing it. Please fix the "
+ "monitor to not do that. "
+ "(message type=\"%s\" interface=\"%s\" "
+ "member=\"%s\" error name=\"%s\" "
+ "destination=\"%s\")",
+ sender, bus_connection_get_loginfo (connection),
+ dbus_message_type_to_string (
+ dbus_message_get_type (message)),
+ nonnull (dbus_message_get_interface (message),
+ "(unset)"),
+ nonnull (dbus_message_get_member (message),
+ "(unset)"),
+ nonnull (dbus_message_get_error_name (message),
+ "(unset)"),
+ nonnull (dbus_message_get_destination (message),
+ DBUS_SERVICE_DBUS));
+ dbus_connection_close (connection);
+ goto out;
+ }
+ }
+
service_name = dbus_message_get_destination (message);
#ifdef DBUS_ENABLE_VERBOSE_MODE