2

How can I list the object path under a dbus services using ONLY dbus-send command line utility?

For now, I can only list services:

dbus-send --system --dest=org.freedesktop.DBus --type=method_call --print-reply  /org/freedesktop/DBus org.freedesktop.DBus.ListNames

or interfaces:

dbus-send --system --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.Introspectable.Introspect

This question is very similar to:

How to list all object paths under a dbus service?

but it requires to use some utilities that are not available to me.

I use a closed embedded system and I cannot install anything, so I cannot use any of the following utilities:

  • qdbusviewer
  • qdbus
  • d-feet
  • python

1 Answer 1

0

You can use the GetManagedObjects method on the org.freedesktop.DBus.ObjectManager interface. But that won't print just list of paths but dump the entire object so you'd need to parse the paths from the outputted dictionary.

If busctl (from systemd) is an option for you, I'd recommend using it because it has JSON output so you can parse it with jq. Example for UDisks2 JSON dump:

# busctl call org.freedesktop.UDisks2 /org/freedesktop/UDisks2 org.freedesktop.DBus.ObjectManager GetManagedObjects --json=short | jq ".data[0] | keys[]"
"/org/freedesktop/UDisks2/Manager"
"/org/freedesktop/UDisks2/block_devices/sda"
"/org/freedesktop/UDisks2/block_devices/sda1"
...

With dbus-send the call would look like

# dbus-send --system --dest=org.freedesktop.UDisks2 --type=method_call --print-reply  /org/freedesktop/UDisks2 org.freedesktop.DBus.ObjectManager.GetManagedObjects

but you need to parse the output manually.

Edit: For org.bluez the commands are:

# busctl call org.bluez / org.freedesktop.DBus.ObjectManager GetManagedObjects --json pretty | jq ".data[0] | keys[]"
"/org/bluez"
"/org/bluez/hci0"
"/org/bluez/hci0/dev_00_1B_66_C1_56_01"

and

# dbus-send --system --dest=org.bluez --type=method_call --print-reply  / org.freedesktop.DBus.ObjectManager.GetManagedObject

and you can try something like

# dbus-send --system --dest=org.bluez --type=method_call --print-reply  / org.freedesktop.DBus.ObjectManager.GetManagedObjects | grep -A 1 "dict entry" | grep "object path" | cut -d"\"" -f2
/org/bluez
/org/bluez/hci0
/org/bluez/hci0/dev_00_1B_66_C1_56_01

for parsing the output to get just the object paths.

6
  • Unfortunately busctl is not an option
    – Luis
    Commented May 12, 2022 at 8:58
  • The other command that you suggested gives the following result: Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UDisks2 was not provided by any .service files
    – Luis
    Commented May 12, 2022 at 8:59
  • I can do something like this for bluez: dbus-send --system --dest=org.bluez --type=method_call --print-reply / org.freedesktop.DBus.ObjectManager.GetManagedObjects but unfortunately doesn't work for bluealsa (the service I need to get object paths from) because the interface is missing
    – Luis
    Commented May 12, 2022 at 9:09
  • I've update my answer with dbus-send command working with bluez. Something more advanced for parsing the output than grep | grep | cut would be probably better but I was never good with awk and/or sed. Commented May 12, 2022 at 12:23
  • Thank you for your help, but it is not bluez the problem. I can manage bluez. It is bluealsa that I cannot investigate (github.com/Arkq/bluez-alsa). The latter is the bridge services between the bluetooth stack and alsa. Bluealsa does not have a ObjectManager interface, so I cannot call the GetManagedObjects method.
    – Luis
    Commented May 12, 2022 at 14:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .