all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michael Albinus <michael.albinus@gmx.de>
To: Alexis <flexibeast@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Unable to get dbus.el to work with the Gentoo OpenRC 'emacs' service
Date: Sat, 10 Jun 2023 18:16:36 +0200	[thread overview]
Message-ID: <877csb1ee3.fsf@gmx.de> (raw)
In-Reply-To: <87edmudofk.fsf@gmail.com> (Alexis's message of "Fri, 02 Jun 2023 22:39:52 +1000")

[-- Attachment #1: Type: text/plain, Size: 2735 bytes --]

Alexis <flexibeast@gmail.com> writes:

> Hi all,

Hi Alexis,

> 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)

I can reproduce it. On my Fedora desktop, I have reproduced it with
running from a shell

--8<---------------cut here---------------start------------->8---
# unsetenv DBUS_SESSION_BUS_ADDRESS
# emacs -Q
--8<---------------cut here---------------end--------------->8---

If I now eval the following in the *scratch* buffer

--8<---------------cut here---------------start------------->8---
(setenv "DBUS_SESSION_BUS_ADDRESS" "unix:path=/run/user/1000/bus")
(dbus--init-bus :session)
--8<---------------cut here---------------end--------------->8---

I get the same error like you

--8<---------------cut here---------------start------------->8---
-> (dbus-error "No connection to bus" :session)
--8<---------------cut here---------------end--------------->8---

Debugging Fdbus__init_bus in dbusbind.c shows, that the error happens in
XD_DBUS_VALIDATE_BUS_ADDRESS. This macro calls on C level

--8<---------------cut here---------------start------------->8---
getenv ("DBUS_SESSION_BUS_ADDRESS")
--8<---------------cut here---------------end--------------->8---

However, the (setenv ...) form above is on Lisp level, and it writes the
change into the internal Lisp variable process-environment. This doesn't
match.

> 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?

The appended patch has fixed this for me. Could you, please, check?

> Alexis.

Best regards, Michael.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 1518 bytes --]

diff --git a/src/dbusbind.c b/src/dbusbind.c
index d96b735c79a..96f9329a97e 100644
--- a/src/dbusbind.c
+++ b/src/dbusbind.c
@@ -276,7 +276,9 @@ XD_OBJECT_TO_STRING (Lisp_Object object)

 #define XD_DBUS_VALIDATE_BUS_ADDRESS(bus)				\
   do {									\
-    char const *session_bus_address = getenv ("DBUS_SESSION_BUS_ADDRESS"); \
+    Lisp_Object session_bus_address					\
+      = Fgetenv_internal (build_string ("DBUS_SESSION_BUS_ADDRESS"),	\
+			  Qnil);					\
     if (STRINGP (bus))							\
       {									\
 	DBusAddressEntry **entries;					\
@@ -289,9 +291,8 @@ #define XD_DBUS_VALIDATE_BUS_ADDRESS(bus)				\
 	dbus_error_free (&derror);					\
 	dbus_address_entries_free (entries);				\
 	/* Canonicalize session bus address.  */			\
-	if ((session_bus_address != NULL)				\
-	    && (!NILP (Fstring_equal					\
-		       (bus, build_string (session_bus_address)))))	\
+	if ((STRINGP (session_bus_address))				\
+	    && (!NILP (Fstring_equal (bus, session_bus_address))))	\
 	  bus = QCsession;						\
       }									\
 									\
@@ -304,7 +305,7 @@ #define XD_DBUS_VALIDATE_BUS_ADDRESS(bus)				\
 	  XD_SIGNAL2 (build_string ("Wrong bus name"), bus);		\
 	/* We do not want to have an autolaunch for the session bus.  */ \
 	if ((EQ (bus, QCsession) || EQ (bus, QCsession_private))	\
-	    && session_bus_address == NULL)				\
+	    && NILP (session_bus_address))				\
 	  XD_SIGNAL2 (build_string ("No connection to bus"), bus);	\
       }									\
   } while (0)

  parent reply	other threads:[~2023-06-10 16:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877csb1ee3.fsf@gmx.de \
    --to=michael.albinus@gmx.de \
    --cc=emacs-devel@gnu.org \
    --cc=flexibeast@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.