D-Bus: Difference between revisions
Jump to navigation
Jump to search
(Created page with "== Using D-Bus == === Introspect D-Bus === Most client connected to D-Bus implement introspection [http://www.kaizou.org/2014/06/dbus-command-line/]. First, we can query th...") |
|||
Line 57: | Line 57: | ||
uk.org.thekelleys.SetDomainServers \ |
uk.org.thekelleys.SetDomainServers \ |
||
"array:string:/my.domain.com/128.129.130.131,8.8.8.8" |
"array:string:/my.domain.com/128.129.130.131,8.8.8.8" |
||
</source> |
|||
=== Use command that requires D-Bus === |
|||
Some commands require dbus (eg. <code>gcp</code>), 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 <code>dbus-launch</code>: |
|||
<source lang="bash"> |
|||
dbus-launch gcp -r dir1 dir2 |
|||
</source> |
</source> |
Revision as of 14:51, 5 December 2020
Using D-Bus
Introspect D-Bus
Most client connected to D-Bus implement introspection [1].
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 [2]:
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