Skip to content

Commit

Permalink
Server: TVNC_USERDBUS config var/command-line opt
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dcommander committed Feb 5, 2025
1 parent c6692ed commit 11225f0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
11 changes: 11 additions & 0 deletions unix/turbovncserver.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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";
Expand Down
16 changes: 13 additions & 3 deletions unix/vncserver.in
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -61,6 +61,7 @@ $autokill = 1;
$bits = @BITS@;
$noVNC = "";
$serverArgs = "";
$userDBus = 0;
$useUDS = 0;
$udsPath = "";

Expand Down Expand Up @@ -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'});

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -1242,6 +1251,7 @@ sub ReadConfiguration
passwdFile
securityTypes
serverArgs
userDBus
useUDS
useVGL
vncUserDir
Expand Down
17 changes: 7 additions & 10 deletions unix/xstartup.turbovnc
Original file line number Diff line number Diff line change
@@ -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.
#
Expand Down Expand Up @@ -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/*)
Expand Down

0 comments on commit 11225f0

Please sign in to comment.