Integration / D Bus Interview Questions
How do you subscribe to D-Bus signals using match rules?
To receive signals, a client registers a match rule with the bus daemon by calling AddMatch, describing which signals it wants delivered by filtering on fields like sender, interface, member (signal name), and path.
dbus-send --system --type=method_call \ --dest=org.freedesktop.DBus \ /org/freedesktop/DBus \ org.freedesktop.DBus.AddMatch \ string:"type='signal',interface='org.freedesktop.NetworkManager',member='StateChanged'"
Once the match is registered, the bus daemon starts forwarding any signal matching those criteria to that connection, which the client then reads from its message queue, typically through a client library's higher-level signal-subscription API rather than raw AddMatch calls in application code.
Match rules can be as broad or narrow as needed: an empty type='signal' rule receives every signal on the bus, while adding sender, interface, and path filters narrows it down to exactly the events an application actually cares about, keeping traffic manageable.
More Related questions...