From 11225f0a18ad4be15f46c736de468c835a1512be Mon Sep 17 00:00:00 2001 From: DRC Date: Wed, 5 Feb 2025 12:43:38 -0500 Subject: [PATCH] Server: TVNC_USERDBUS config var/command-line opt Introduce a new turbovncserver.conf variable ($userDBus) and vncserver command-line option (-userdbus) corresponding to the TVNC_USERDBUS environment variable used by xstartup.turbovnc. This allows users to more easily enable the use of the per-user D-Bus session bus instance on a system-wide, per-user, or per-TurboVNC-session basis. The feature is still undocumented except in turbovncserver.conf and xstartup.turbovnc. --- unix/turbovncserver.conf | 11 +++++++++++ unix/vncserver.in | 16 +++++++++++++--- unix/xstartup.turbovnc | 17 +++++++---------- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/unix/turbovncserver.conf b/unix/turbovncserver.conf index 558e020b0..e37add305 100644 --- a/unix/turbovncserver.conf +++ b/unix/turbovncserver.conf @@ -29,6 +29,16 @@ ## (passed to Xvnc in the -securitytypes argument) ## $serverArgs -- additional arguments to pass to Xvnc (refer to the Xvnc man ## page for a list of accepted arguments) +## $userDBus -- Using a unique D-Bus session bus instance for each TurboVNC +## session is necessary in order to run multiple TurboVNC +## sessions (or a local session and a TurboVNC +## session) simultaneously under the same user account, but +## this also causes issues with Control Group (cgroup) v2 on +## some systems. If this variable is set to 1, then the +## TurboVNC session will use the per-user D-Bus session bus +## instance provided by systemd rather than a unique D-Bus +## session bus instance. That improves cgroup v2 +## compatibility at the expense of multi-session capability. ## $useUDS -- listen on a Unix domain socket rather than a TCP port for ## connections from VNC viewers ## [equivalent of -uds command-line option] @@ -65,6 +75,7 @@ # $noxstartup = 0; # $securityTypes = "TLSVnc, TLSOtp, TLSPlain, X509Vnc, X509Otp, X509Plain, VNC, OTP, UnixLogin, Plain"; # $serverArgs = ""; +# $userDBus = 0; # $useUDS = 0; # $useVGL = 0; # $vncUserDir = "$ENV{HOME}/.vnc"; diff --git a/unix/vncserver.in b/unix/vncserver.in index 50ff3299e..4c379aca6 100644 --- a/unix/vncserver.in +++ b/unix/vncserver.in @@ -1,7 +1,7 @@ #!/usr/bin/env perl # -# Copyright (C) 2009-2018, 2020-2022, 2024 D. R. Commander. -# All Rights Reserved. +# Copyright (C) 2009-2018, 2020-2022, 2024-2025 D. R. Commander. +# All Rights Reserved. # Copyright (C) 2021 Steffen Kieß # Copyright (C) 2010 University Corporation for Atmospheric Research. # All Rights Reserved. @@ -61,6 +61,7 @@ $autokill = 1; $bits = @BITS@; $noVNC = ""; $serverArgs = ""; +$userDBus = 0; $useUDS = 0; $udsPath = ""; @@ -209,7 +210,8 @@ foreach $_registrydir (@registrydirs) { "-3dwm", 0, "-vgl", 0, "-debug", 0, "-x509cert", 1, "-x509key", 1, "-autokill", 0, "-quiet", 0, "-wm", 1, "-sessionlist", 0, "-sessionstart", 0, "-novnc", 1, - "-noautokill", 0, "-rfbport", 1, "-rfbunixpath", 1, "-uds", 0); + "-noautokill", 0, "-rfbport", 1, "-rfbunixpath", 1, "-uds", 0, + "-userdbus", 0); &Usage() if ($opt{'-help'} || $opt{'-h'} || $opt{'--help'}); @@ -267,6 +269,9 @@ if ($opt{'-xstartup'}) { if ($opt{'-wm'}) { $wm = $opt{'-wm'}; } +if ($opt{'-userdbus'}) { + $userDBus = 1; +} if ($opt{'-3dwm'} || $opt{'-vgl'}) { $useVGL = 1; } @@ -590,6 +595,10 @@ if (!$noxstartup) { if ($wm) { $ENV{TVNC_WM} = $wm; } + if ($userDBus) { + warn "(Using per-user D-Bus session bus instance)\n"; + $ENV{TVNC_USERDBUS} = "1"; + } if ($useVGL) { warn "(Enabling VirtualGL)\n"; $ENV{TVNC_VGL} = "1"; @@ -1242,6 +1251,7 @@ sub ReadConfiguration passwdFile securityTypes serverArgs + userDBus useUDS useVGL vncUserDir diff --git a/unix/xstartup.turbovnc b/unix/xstartup.turbovnc index f7f5f2909..56c5e265a 100644 --- a/unix/xstartup.turbovnc +++ b/unix/xstartup.turbovnc @@ -1,7 +1,7 @@ #!/bin/sh -# Copyright (C) 2014-2018, 2021-2022, 2024 D. R. Commander. -# All Rights Reserved. +# Copyright (C) 2014-2018, 2021-2022, 2024-2025 D. R. Commander. +# All Rights Reserved. # Copyright (C) 2005-2008 Sun Microsystems, Inc. All Rights Reserved. # Copyright (C) 2002 Constantin Kaplinsky. All Rights Reserved. # @@ -44,14 +44,11 @@ GDK_BACKEND=x11; export GDK_BACKEND # Ubuntu 18.04+), it is necessary to explicitly create a new session bus # instance by invoking dbus-launch. # -# Using a separate D-Bus session bus instance for each TurboVNC session is -# necessary in order to run multiple TurboVNC sessions (or a local session and -# a TurboVNC session) simultaneously under the same user account, but this also -# causes issues with Control Group (cgroup) v2 on some systems. If -# TVNC_USERDBUS is set to 1 in the environment (currently undocumented except -# here), then we forego creating a unique D-Bus session bus instance for the -# TurboVNC session and use the per-user D-Bus session bus instance provided by -# systemd instead. That improves cgroup v2 compatibility at the expense of +# If TVNC_USERDBUS is set to 1 in the environment (which will be the case if +# $userDBus = 1 in turbovncserver.conf or -userdbus is passed to vncserver), +# then we forego creating a unique D-Bus session bus instance for the TurboVNC +# session and use the per-user D-Bus session bus instance provided by systemd +# instead. That improves cgroup v2 compatibility at the expense of # multi-session capability. case "$DBUS_SESSION_BUS_ADDRESS" in unix:path=/run/user/*)