Products › lamco-dbus-tools › Docs

D-Bus match rules on dbus-daemon and dbus-broker

D-Bus match rules as lamco-dbus-tools reads and applies them, and the four places dbus-daemon and dbus-broker read a rule differently, found in their source.

Describes version 0.4.1. The source of truth is src/listen/rule.rs, held to both bus implementations by tests/filter.rs.

dbussee record, watch and dbussee-monitor take match rules with --match, and --service NAME stands for two: sender='NAME' and destination='NAME'. With a monitor of its own the recorder hands them to the bus with BecomeMonitor, and the bus applies them. Reading through dbuskeep, the service applies them itself, and gives the same messages the bus would have, message for message, on dbus-daemon and on dbus-broker. Where the two implementations differ, the service follows the one it's watching. The capture's instrument record says which filtered: filtered_by is the bus or the service.

Reading a rule

A rule is read as the specification's "Match Rules" section gives it: key=value pairs separated by commas. Inside single quotes a backslash is itself and a quote ends the quoting; outside them \' is a quote and any other backslash is itself. A value may be unquoted. Refused before anything is sent:

  • an unknown key, or one given twice;
  • a type other than signal, method_call, method_return or error;
  • a path or path_namespace that isn't an object path, or both together;
  • an argument index past 63, or one argument tested twice (arg0 and arg0path, or arg0namespace with either);
  • an unclosed quote, or eavesdrop other than true or false.

Names aren't judged: The bus accepts a well-known name as a destination, which a stricter check would refuse.

Applying a rule to a monitor

Every key given must hold; a key left out holds for anything.

Key Holds when
type The message is of that type
sender It came from that unique name, or from whoever owned that well-known name when it passed; org.freedesktop.DBus names the bus's own messages
destination It's addressed to that unique name or to whoever owned that well-known name then. Addressed to the bus, or to a name nobody owns, as while a service is being started, it's compared as text
interface, member, path The header field is there and equal
path_namespace The path is the value or under it (/a/b is under /a; /ab isn't); / holds every path
argN The body's Nth top-level value is a string equal to it
argNpath The Nth value is a string or object path equal to it, or either is a prefix of the other ending in /
arg0namespace The first value is a string equal to it, or it followed by . and more
eavesdrop Always: A monitor eavesdrops

A monitor's rules take messages to anyone, not only broadcasts: A rule without destination takes method calls and their answers too. Who owned a name when a message passed is followed through the bus's NameOwnerChanged signals.

Where the two buses differ

Each was found reading the implementations' source and held to the running bus by the test, which records the same traffic with the rule given to the bus and through the service for every key.

dbus-daemon 1.16 dbus-broker 37 Source
An unquoted backslash before a comma, as in the specification's own arg1=\,arg2=',' Keeps the comma in the value: arg1 is \,arg2=, and there's no arg2 Ends the value: arg1 is \, as the specification says dbus bus/signals.c find_value; dbus-broker src/bus/match.c match_copy_value
destination Applied Never applied: Parsed and stored, and not tested by match_keys_match_metadata, so a rule with one takes every message the rest of it takes dbus-broker src/bus/match.c
path_namespace='/' Every path Only the path / itself: match_string_prefix has no case for the root dbus bus/signals.c match_rule_matches; dbus-broker src/bus/match.c
NameAcquired to a connection taking a name nobody owned, with destination that name Not taken: The signal is sent before the owner is recorded (bus_service_add_owner) Not applicable: destination isn't tested dbus bus/services.c

dbus-broker before 37 differs once more. For every argN it checked the type of the zeroth argument and compared the Nth, so arg1='beta' didn't take a message whose zeroth argument is an object path, and took one whose first argument is an object path spelled beta. For argNpath it compared the rule's path as a start of the Nth argument, and the zeroth argument, not the Nth, as a start of the rule's path. Its commit f805f41, "bus/match: fix matching against arguments beyond the zeroth", fixed both in 37, and Ubuntu 24.04 ships 35. dbuskeep reads the version of the dbus-broker it keeps and applies a reader's rules as that version does; one whose version can't be read is taken as 37. Run on 2026-12-04 in an Ubuntu 24.04 container with dbus-broker 35: The test's 23 rules, each the same messages from the bus and through the service.

One consequence for every recording on dbus-broker, through the bus or the service reading rules as the bus does: --service NAME is sender='NAME' or destination='NAME', and since dbus-broker ignores the second, it takes everything. On dbus-daemon it takes the service's own traffic. lamco-dbus-tools says so: A recording given a rule with destination on dbus-broker prints a note before it begins, and its capture gives BUS-004.

As the specification reads them

--rules-as-specified has dbuskeep read and apply the rules as the specification gives them, whatever its bus does: destination applied, / holding every path, a comma after an unquoted backslash ending the value, and the NameAcquired for a new name sent to its owner. On dbus-broker it makes --service NAME take that service's own traffic. Only the service can do it, so it needs dbuskeep keeping the bus and can't be given with --no-keep, --helper or --all. The capture's filtered_by is then the service, as the specification reads rules, and BUS-004 isn't raised.

What a bus's own messages carry

The bus's messages don't have serials of their own: dbus-broker gives every one 4294967295, and dbus-daemon numbers them for each recipient. A message from the bus is told apart by its member, destination and path, not its serial.