unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Unable to get dbus.el to work with the Gentoo OpenRC 'emacs' service
@ 2023-06-02 12:39 Alexis
  2023-06-02 13:18 ` Alexis
  2023-06-10 16:16 ` Michael Albinus
  0 siblings, 2 replies; 7+ messages in thread
From: Alexis @ 2023-06-02 12:39 UTC (permalink / raw)
  To: emacs-devel


[Please cc me on replies as i'm not currently subscribed to the 
list.]

Hi all,

For a while i've been manually starting an Emacs server on login 
(via my .zlogin), after a D-Bus session has been started (also via 
my .zlogin). However, i recently tried moving to the Gentoo OpenRC 
service, and have run into a problem regarding D-Bus.

The 'emacs' OpenRC service gets started at boot, prior to 
login. There is thus no D-Bus session bus available at that time; 
the DBUS_SESSION_BUS_ADDRESS env var isn't set. As noted above, 
this changes once i log in; the DBUS_SESSION_BUS_ADDRESS variable 
gets set. However, the Emacs server still thinks that var is 
unset.

i had assumed that running:

   emacsclient --eval "(setenv \"DBUS_SESSION_BUS_ADDRESS\" 
   \"${DBUS_SESSION_BUS_ADDRESS}\")"

in my WM startup script, to set that var in the environment of the 
server process, would address this.

However, while it addresses some issues - such as Emacs being able 
to open a new tab in an existing Firefox instance - it doesn't 
seem to affect the D-Bus environment in Emacs more generally:

    (dbus-get-unique-name :session)
    -> (dbus-error "No connection to bus" :session)

    (dbus-monitor :session)
    -> (dbus-error "No connection to bus" :session-private)

There seems to be no way of 'restarting' the "dbus" feature from 
within Emacs in order to get it to pick up the session bus 
address.

* (dbus-init-bus :session)
  -> (dbus-error "No connection to bus" :session)

* (dbus-init-bus (getenv "DBUS_SESSION_BUS_ADDRESS"))
  -> 2

  which means a new connection has been created, but:

  (dbus-monitor :session)
  -> "No connection to bus"

* (dbus-list-hash-table)
  -> (((:signal "unix:path=/tmp/dbus-[etc]

  where [etc] is the correct current value of 
  DBUS_SESSION_BUS_ADDRESS for the session, and yet:

  (dbus-monitor :session)
  -> "No connection to bus"

* Redefining `dbus-handle-bus-disconnect`:

(defun my-dbus-handle-bus-disconnect ()
  "React to a bus disconnection.
BUS is the bus that disconnected.  This routine unregisters all
handlers on the given bus and causes all synchronous calls
pending at the time of disconnect to fail."
  (let ((bus (getenv "DBUS_SESSION_BUS_ADDRESS"))
        keys-to-remove)
    (maphash
     (lambda (key value)
       (when (and (eq (nth 0 key) :serial)
                  (eq (nth 1 key) bus))
         (run-hook-with-args
          'dbus-event-error-functions
          (list 'dbus-event
                bus
                dbus-message-type-error
                (nth 2 key) ; serial
                nil         ; service
                nil         ; destination
                nil         ; path
                nil         ; interface
                nil         ; member
                value)      ; handler
          (list 'dbus-error dbus-error-disconnected  "Bus 
          disconnected" bus))
         (push key keys-to-remove)))
     dbus-registered-objects-table)
    (dolist (key keys-to-remove)
      (remhash key dbus-registered-objects-table))))

  followed by:

  (my-dbus-handle-bus-disconnect)
  (dbus-ignore-errors
    (dbus-init-bus :session))

  returns `nil` (i.e. without errors), but

  (dbus-monitor :session)
  -> "No connection to bus"

* (unload-feature 'dbus t)

where `t` is required due to various in-tree packages having a 
dependency on dbus.el, returns `nil` (i.e. without errors), but:

  (require 'dbus)
  -> dbus
  (dbus-monitor :session)
  -> "No connection to bus"

What am i missing? Or is it simply not possible to 'restart' 
dbus.el from ELisp in order to get it to create a :session bus 
based on the updated value of DBUS_SESSION_BUS_ADDRESS in the 
server process environment?


Alexis.



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-06-12 10:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-02 12:39 Unable to get dbus.el to work with the Gentoo OpenRC 'emacs' service Alexis
2023-06-02 13:18 ` Alexis
2023-06-10 16:16 ` Michael Albinus
2023-06-12  3:02   ` Alexis
2023-06-12 10:51     ` Michael Albinus
2023-06-12  8:25   ` Robert Pluim
2023-06-12 10:48     ` Michael Albinus

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).