2

In the process of hacking around with dbus-monitor, I tried connecting to the Avahi daemon:

$ dbus-monitor --system \
  "type='signal',interface='org.freedesktop.Avahi.Server',member='StateChanged'"

This will respond to changes in the state of the Avahi daemon.

$ sudo restart avahi-daemon

signal sender=org.freedesktop.DBus -> 
         dest=:1.315 
         serial=2
         path=/org/freedesktop/DBus;
         interface=org.freedesktop.DBus;
         member=NameAcquired
    string ":1.315"

signal sender=:1.318 ->
         dest=(null destination)
         serial=4
         path=/;
         interface=org.freedesktop.Avahi.Server; 
         member=StateChanged
    int32 1
    string "org.freedesktop.Avahi.Success"

signal sender=:1.318 -> 
         dest=(null destination)
         serial=13
         path=/;
         interface=org.freedesktop.Avahi.Server;
         member=StateChanged
    int32 2
    string "org.freedesktop.Avahi.Success"

However, I cannot browse services like this.

$ dbus-send --system --dest=org.freedesktop.Avahi --print-reply \
    / org.freedesktop.Avahi.Server.ServiceBrowserNew \
    int32:-1 int32:-1 string:'_http._tcp' string:'local' uint32:0

method return sender=:1.345 -> 
         dest=:1.354
         reply_serial=2
    object path "/Client5/ServiceBrowser1"

$ dbus-monitor --system \
    "type='signal',interface='org.freedesktop.Avahi.ServiceBrowser'"

As far as I understand, this should respond to new/removed http service instances, but it does not.

Why?

Update:

Executing the equivalent of the above shell commands with the python and c APIs worked as expected. However, they could not connect to a ServiceBrowser which I had constructed using dbus-send and I could not use dbus-monitor to listen to a ServiceBrowser they constructed.

At this point, my best guesses are:

  1. Once the connection is closed (by the termination of the dbus-send command), the ServiceBrowser I created is destroyed. However this does not explain why dbus-monitor is unable to connect to a ServiceBrowser which is in active communication with my python script.
  2. The signals from the ServiceBrowser are emitted only to the connection which instantiated them.
Kietz
  • 1,186
  • 11
  • 19
  • What happens if you create browser from python and then do `dbus-monitor --system \ "type='signal',interface='org.freedesktop.Avahi.ServiceBrowser'"`? As far as I know, avahi does not know when client closed connection (And it's client's responsibility to free browser). Also, signal message is sent to bus, ind dbus-daemon routs it to subscribers - so as far as I know 1 and 2 are incorrect – Andrey Sidorov Feb 14 '14 at 00:49
  • I have node.js wrapper around avahi - might be useful to debug your problem - https://github.com/sidorares/node-gday/blob/master/examples/discover-rfb.js – Andrey Sidorov Feb 14 '14 at 00:50
  • Browser created in Python or C is inaccessible with `dbu-monitor`. I already have working code in those languages, so this question is more about curiosity than fixing a bug. I expected shell hackery to be an easy first step, but my understanding of DBus is incomplete. How could I use `node-gday` to answer my question? – Kietz Feb 16 '14 at 04:06

1 Answers1

0

I believe the problem is caused by the dbus policy. Try to change the avahi dbus policy in /etc/dbus-1/system.d/avahi-dbus.conf like this (remember to restart avahi daemon):

<busconfig>

  <policy context="default">
    <!-- All messages may be received by default -->
    <allow receive_requested_reply="false" receive_type="method_call" eavesdrop="true"/>
    <allow receive_requested_reply="false" receive_type="method_return" eavesdrop="true"/>
    <allow receive_requested_reply="false" receive_type="error" eavesdrop="true"/>
    <allow receive_requested_reply="false" receive_type="signal" eavesdrop="true"/>
    <allow eavesdrop="true"/>
  </policy>
  <policy user="root">
      <allow send_destination="*" eavesdrop="true"/>
      <allow receive_sender="*" eavesdrop="true"/>
  </policy>
</busconfig>

And use root privilege to run dbus-monitor:

sudo dbus-monitor --system \
    "type='signal',interface='org.freedesktop.Avahi.ServiceBrowser'"

reference: http://blog.nutsfactory.net/2011/03/08/test-and-debug-dbus/

user2925565
  • 1,302
  • 2
  • 11
  • 14