Dbus debug via dbus-monitor

From Ability
Jump to: navigation, search

Introduction

As more and more applications and system services use D-Bus, it becomes more important to know how to see what happens on the bus. There are two buses commonly used: the session bus and the system bus. Either may be used by any application, depending on what it is doing. How to monitor the session bus This one is easy. Just run dbus-monitor and watch the output. This usually gives you enough information about what is happening on the bus.

dbus-monitor

How to monitor the system bus This is trickier, because D-Bus policy typically prevents anything but signals from being viewable by dbus-monitor. But we can change that.

Make a backup of /etc/dbus-1/system.conf:

sudo cp /etc/dbus-1/system.conf /etc/dbus-1/system.conf~

Edit /etc/dbus-1/system.conf

sudo editor /etc/dbus-1/system.conf

Find the <policy context="default"> section and replace it with the following block. This block opens up the system bus to viewing by anyone. This is not a safe policy! You should revert this change after you are done debugging.

<policy context="default">
 <allow send_destination="*" eavesdrop="true"/>
 <allow eavesdrop="true"/>
 <allow own="*"/>
 <allow user="*"/>
</policy>

Then comment out or delete the nearby <includedir> line. This line will include individual policies for specific services. But we don't want those individual policies to further restrict the bus. So we force our above lax policy by not including sub-policies.


Reboot to get a fresh dbus daemon using this new policy.

sudo reboot

Now run dbus-monitor as root. You should be able to see all signals, method calls, and method replies.

sudo dbus-monitor --system

When done debugging, remember to go back to your previous, secure policy:

sudo cp /etc/dbus-1/system.conf~ /etc/dbus-1/system.conf
sudo reboot

Filtering all the noise

If there is just too much information on the bus, pass a match rule like so:

dbus-monitor "type='signal',sender='org.gnome.TypingMonitor',interface='org.gnome.TypingMonitor'"

Multiple rules can be specified. If a message matches any of the rules, the message will be printed. Like so:

dbus-monitor 'type=error' 'sender=org.freedesktop.SystemToolsBackends'