dbus icon indicating copy to clipboard operation
dbus copied to clipboard

can't connect to system bus

Open jollm opened this issue 13 years ago • 7 comments

Debian squeeze, dbus 1.2.24-4

Example:

(dbus:with-open-bus (bus (dbus:system-server-addresses)) (dbus:with-introspected-object (wicd-wireless bus "/org/wicd/daemon/wireless" "org.wicd.daemon")))

Error: No more mechanisms to try.

Seems to be related to cookie sha1 auth

Python and scheme bindings via libdbus are working

Working example in scheme:

(define wicd-wireless-context (dbus:make-context bus: dbus:system-bus service: 'org.wicd.daemon interface: 'org.wicd.daemon.wireless path: '/org/wicd/daemon/wireless)) (dbus:call wicd-wireless-context "GetWirelessProperty" 0 "bssid") ("88:43:E1:13:FC:B2")

I don't yet know enough to attempt a fix unfortunately.

jollm avatar Jan 16 '12 20:01 jollm

That's the expected result (i think).

Look at 'system-server-addresses' function. It retrieves DBUS address from the environment variables. If env variables are not defined then you won't be able to connect to the bus.

The 'standard' way to retrieve the bus address is to read the file ".dbus/session-bus/[machine-id]-[display]".

try


(defun get-machine-id ()
  (with-open-file (machine-id-file "/var/lib/dbus/machine-id" 
                   :direction :input)
    (read-line machine-id-file)))

(defun get-display-number ()
  (let ((display (getenv "DISPLAY")))
    (if (null display)
    (error "DISPLAY variable not set.")
    (handler-case
        (parse-integer (subseq display (1+ (position #\: display)) (position #\. display)))
      (parse-error () (error "Can not parse DISPLAY variable."))))))

(defun update-environment-variables ()
  "Sets the 'DBUS_SESSION_BUS_ADDRESS' environment variable (if not present)."
  (when (not (getenv "DBUS_SESSION_BUS_ADDRESS"))
    (let (machine-id display)
      (setq machine-id (get-machine-id))
      (setq display (format nil "~d" (get-display-number)))
      (iolib.syscalls:setenv 
       "DBUS_SESSION_BUS_ADDRESS" 
       (get-session-bus-address-from-file 
    (concatenate 'string "~/.dbus/session-bus/" machine-id "-" display))
       t))))

That is how i got it working (take a look at my fork, i also have EXTERNAL auth method)

lucashpandolfo avatar Jan 19 '12 15:01 lucashpandolfo

I appreciate the thorough response. The system bus connection is obtained through /var/run/dbus/system_bus_socket by default. This seems the correct approach, but it doesn't work. I will try your fork.

jollm avatar Feb 02 '12 10:02 jollm

That does in fact work! Is it the external auth that makes the difference? I will need to investigate further to eliminate the mystery.

jollm avatar Feb 02 '12 10:02 jollm

After playing around some more, I discovered the proper syntax for variant type signatures:

(with-open-bus (bus (system-server-addresses))
  (with-introspected-object (wicd-wireless bus "/org/wicd/daemon/wireless" "org.wicd.daemon")
    (wicd-wireless "org.wicd.daemon.wireless" "GetWirelessProperty" '((:int32) 0) '((:string) "bssid"))))

This is cumbersome for auto-generating functions to the interface. Is there a mechanism to introspecting further into a variant type, or is the only way to guess from the type of arguments passed in?

jollm avatar Feb 02 '12 11:02 jollm

The external SASL authentication method fixes this issue. I would suggest pulling this in from lucashpandolfo.

jollm avatar Feb 07 '12 11:02 jollm

I can verify this issue as well. The most basic replication method is to run (notify-example) from examples/notify.lisp.

futuro avatar Jul 21 '12 21:07 futuro

Hello (after a long vacation :)

  1. Joseph tried to use the system bus, but Lucas's code deals with the session bus.
  2. I gather by Joseph's comment that the system bus code should work given support for EXTERNAL auth mechanism.
  3. If Lucas could extract a set of patches I will review and apply them.
  4. Perhaps Joseph could further explain his issue with the variant type signatures in another issue?

death avatar Jul 22 '12 10:07 death