Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

startup: Set up the session bus on the boot.iso #5464

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions anaconda.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ def _earlyExceptionHandler(ty, value, traceback):
target=wait_for_connecting_NM_thread
)

# Start the user instance of systemd and the session bus.
display.start_user_systemd()

# now start the interface
display.setup_display(anaconda, opts)
if anaconda.gui_startup_failed:
Expand Down
7 changes: 5 additions & 2 deletions pyanaconda/core/dbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#
import os

from dasbus.connection import SystemMessageBus, MessageBus
from dasbus.connection import SystemMessageBus, MessageBus, SessionMessageBus
from dasbus.constants import DBUS_STARTER_ADDRESS
from dasbus.error import ErrorMapper, get_error_decorator, AbstractErrorRule
from pyanaconda.anaconda_loggers import get_module_logger
Expand All @@ -27,7 +27,7 @@

log = get_module_logger(__name__)

__all__ = ["DBus", "SystemBus", "error_mapper", "dbus_error"]
__all__ = ["DBus", "SystemBus", "SessionBus", "error_mapper", "dbus_error"]


class AnacondaMessageBus(MessageBus):
Expand Down Expand Up @@ -114,6 +114,9 @@ def get_type(self, error_name):
# System bus.
SystemBus = SystemMessageBus()

# Session bus.
SessionBus = SessionMessageBus()

# The mapper of DBus errors.
error_mapper = AnacondaErrorMapper()

Expand Down
12 changes: 10 additions & 2 deletions pyanaconda/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import signal

from pyanaconda.core.configuration.anaconda import conf
from pyanaconda.core.path import join_paths
from pyanaconda.core.process_watchers import WatchProcesses
from pyanaconda import startup_utils
from pyanaconda.core import util, constants, hw
Expand Down Expand Up @@ -70,9 +71,18 @@ def start_user_systemd():
log.debug("Don't start the user instance of systemd.")
return

# Start the user instance of systemd. This call will also cause the launch of
# dbus-broker and start a session bus at XDG_RUNTIME_DIR/bus.
childproc = util.startProgram(["/usr/lib/systemd/systemd", "--user"])
WatchProcesses.watch_process(childproc, "systemd")

# Set up the session bus address. Some services started by Anaconda might call
# dbus-launch with the --autolaunch option to find the existing session bus (or
# start a new one), but dbus-launch doesn't check the XDG_RUNTIME_DIR/bus path.
xdg_runtime_dir = os.environ.get("XDG_RUNTIME_DIR", "/tmp")
session_bus_address = "unix:path=" + join_paths(xdg_runtime_dir, "/bus")
os.environ["DBUS_SESSION_BUS_ADDRESS"] = session_bus_address
log.info("The session bus address is set to %s.", session_bus_address)

# Spice

Expand Down Expand Up @@ -232,8 +242,6 @@ def do_extra_x11_actions(runres, gui_mode):

# Load the system-wide Xresources
util.execWithRedirect("xrdb", ["-nocpp", "-merge", "/etc/X11/Xresources"])

start_user_systemd()
start_spice_vd_agent()


Expand Down
54 changes: 54 additions & 0 deletions tests/unit_tests/pyanaconda_tests/test_display.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#
# Copyright (C) 2024 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
# the GNU General Public License v.2, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY expressed or implied, including the implied warranties of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details. You should have received a copy of the
# GNU General Public License along with this program; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
# source code or documentation are not subject to the GNU General Public
# License and may only be used or replicated with the express permission of
# Red Hat, Inc.
#
import os
from unittest import TestCase
from unittest.mock import patch

from pyanaconda.display import start_user_systemd


class DisplayUtilsTestCase(TestCase):
"""Test the display utils."""

@patch.dict("os.environ", clear=True)
@patch("pyanaconda.display.WatchProcesses")
@patch("pyanaconda.display.conf")
@patch("pyanaconda.display.util")
def test_start_user_systemd(self, util_mock, conf_mock, watch_mock):
"""Start a user instance of systemd on a boot.iso."""
# Don't start systemd --user if this is not a boot.iso.
conf_mock.system.can_start_user_systemd = False
start_user_systemd()

util_mock.startProgram.assert_not_called()
util_mock.reset_mock()

# Start systemd --user on a boot.iso.
os.environ["XDG_RUNTIME_DIR"] = "/my/xdg/path"
conf_mock.system.can_start_user_systemd = True
util_mock.startProgram.return_value = 100
start_user_systemd()

util_mock.startProgram.assert_called_once_with(
["/usr/lib/systemd/systemd", "--user"]
)
watch_mock.watch_process.assert_called_once_with(
100, "systemd"
)
assert os.environ["DBUS_SESSION_BUS_ADDRESS"] == \
"unix:path=/my/xdg/path/bus"
Loading