8be66a
From 9c0ed82f661a2296784970678746b0b4f130870e Mon Sep 17 00:00:00 2001
8be66a
From: Alan Jenkins <alan.christopher.jenkins@gmail.com>
8be66a
Date: Thu, 21 Jun 2018 14:12:30 +0100
8be66a
Subject: [PATCH] core: remove support for API bus "started outside our own
8be66a
 logic"
8be66a
8be66a
Looking at a recent Bad Day, my log contains over 100 lines of
8be66a
8be66a
    systemd[23895]: Failed to connect to API bus: Connection refused
8be66a
8be66a
It is due to "systemd --user" retrying to connect to an API bus.[*]  I
8be66a
would prefer to avoid spamming the logs.  I don't think it is good for us
8be66a
to retry so much like this.
8be66a
8be66a
systemd was mislead by something setting DBUS_SESSION_BUS_ADDRESS.  My best
8be66a
guess is an unfortunate series of events caused gdm to set this.  gdm has
8be66a
code to start a session dbus if there is not a bus available already (and
8be66a
in this case it exports the environment variable).  I believe it does not
8be66a
normally do this when running under systemd, because "systemd --user" and
8be66a
hence "dbus.service" would already have been started by pam_systemd.
8be66a
8be66a
I see two possibilities
8be66a
8be66a
1. Rip out the check for DBUS_SESSION_BUS_ADDRESS entirely.
8be66a
2. Only check for DBUS_SESSION_BUS_ADDRESS on startup.  Not in the
8be66a
   "recheck" logic.
8be66a
8be66a
The justification for 2), is that the recheck is called from unit_notify(),
8be66a
this is used to check whether the service just started (or stopped) was
8be66a
"dbus.service".  This reason for rechecking does not apply if we think
8be66a
the session bus was started outside our logic.
8be66a
8be66a
But I think we can justify 1).  dbus-daemon ships a statically-enabled
8be66a
/usr/lib/systemd/user/dbus.service, which would conflict with an attempt to
8be66a
use an external dbus.  Also "systemd --user" is started from user@.service;
8be66a
if you try to start it manually so that it inherits an environment
8be66a
variable, it will conflict if user@.service was started by pam_systemd
8be66a
(or loginctl enable-linger).
8be66a
8be66a
(cherry picked from commit d3243f55ca9b5f305306ba4105ab29768e372a78)
8be66a
8be66a
Resolves: #1764282
8be66a
---
8be66a
 src/core/manager.c | 5 -----
8be66a
 1 file changed, 5 deletions(-)
8be66a
8be66a
diff --git a/src/core/manager.c b/src/core/manager.c
8be66a
index 012615e537..3c44ad3dbc 100644
8be66a
--- a/src/core/manager.c
8be66a
+++ b/src/core/manager.c
8be66a
@@ -1519,11 +1519,6 @@ static bool manager_dbus_is_running(Manager *m, bool deserialized) {
8be66a
         if (m->test_run_flags != 0)
8be66a
                 return false;
8be66a
 
8be66a
-        /* If we are in the user instance, and the env var is already set for us, then this means D-Bus is ran
8be66a
-         * somewhere outside of our own logic. Let's use it */
8be66a
-        if (MANAGER_IS_USER(m) && getenv("DBUS_SESSION_BUS_ADDRESS"))
8be66a
-                return true;
8be66a
-
8be66a
         u = manager_get_unit(m, SPECIAL_DBUS_SOCKET);
8be66a
         if (!u)
8be66a
                 return false;