death / dbus

A D-BUS client library for Common Lisp
BSD 2-Clause "Simplified" License
44 stars 29 forks source link

can't connect to system bus #3

Open jollm opened 12 years ago

jollm commented 12 years ago

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.

lucashpandolfo commented 12 years ago

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)

jollm commented 12 years ago

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 commented 12 years ago

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 commented 12 years ago

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 commented 12 years ago

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

futuro commented 12 years ago

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

death commented 12 years ago

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?