D-Bus: Difference between revisions
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
== Reference == |
|||
* [https://wiki.gnome.org/Apps/DFeet] |
|||
: D-Feet is an easy to use D-Bus debugger. |
|||
sudo apt install d-feet |
|||
== Using D-Bus == |
== Using D-Bus == |
||
Revision as of 20:08, 26 April 2022
Reference
- D-Feet is an easy to use D-Bus debugger.
sudo apt install d-feet
Using D-Bus
Introspect D-Bus
Most client connected to D-Bus implement introspection [2].
First, we can query the list of services:
# Query session bus
dbus-send --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames
dbus-send --session --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames
# Query system bus
dbus-send --system --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames
For instance, to find dnsmasq
service:
dbus-send --system --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames \
| grep dnsmasq
# string "org.freedesktop.NetworkManager.dnsmasq"
We can use the org.freedesktop.DBus.Introspectable.Introspect
method to get all methods of a given service, but for this we need both the service name and path, which is not listed above.
For most services, the path can be obtained by converting .
into /
:
# Get the DBUS interface:
dbus-send --session \
--dest=org.freedesktop.DBus \
--type=method_call \
--print-reply \
/org/freedesktop/DBus \
org.freedesktop.DBus.Introspectable.Introspect
For dnsmasq (system D-BUS), the path is /uk/org/thekelleys/dnsmasq
:
# Get dnsmasq D-Bus interface
sudo dbus-send --system --dest=org.freedesktop.NetworkManager.dnsmasq --type=method_call --print-reply /uk/org/thekelleys/dnsmasq org.freedesktop.DBus.Introspectable.Introspect
# ...
# <method name="SetServers">
# <arg name="servers" direction="in" type="av"/>
# </method>
# <method name="SetDomainServers">
# <arg name="servers" direction="in" type="as"/>
Send command via D-Bus
For instance, to set the DNS server in dnsmasq [3]:
dbus-send --system --print-reply \
--dest=org.freedesktop.NetworkManager.dnsmasq \
/uk/org/thekelleys/dnsmasq \
uk.org.thekelleys.SetDomainServers \
"array:string:/my.domain.com/128.129.130.131,8.8.8.8"
Use command that requires D-Bus
Some commands require dbus (eg. gcp
), or we get an error:
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
Use dbus-launch
:
dbus-launch gcp -r dir1 dir2