DebuggingDBus
This page is part of the debugging series — pages with debugging details for a variety of Ubuntu packages. |
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
If it's too much information, pass a match rule like so:
dbus-monitor "type='signal',sender='org.gnome.TypingMonitor',interface='org.gnome.TypingMonitor'"
See the D-Bus documentation for more information on match rules.
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 everything to be sent --> <allow send_destination="*" eavesdrop="true"/> <!-- Allow everything to be received --> <allow eavesdrop="true"/> <!-- Allow anyone to own anything --> <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.
<!-- <includedir>system.d</includedir> -->
- 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