Skip to content

Commit

Permalink
xstartup: Require sess dsktop file if WM specified
Browse files Browse the repository at this point in the history
xinitrc is poorly or not at all supported on modern Un*x distributions.
Executing it as a fallback if the session desktop file for the specified
window manager could not be found sometimes caused hard-to-diagnose
issues.
  • Loading branch information
dcommander committed Jul 23, 2024
1 parent 9104edc commit 89c47eb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 24 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ with the TurboVNC Server on Ubuntu 23.10 and later (if the `polkitd-pkla`
package is not installed) and on RHEL 7 and Fedora 19 and later (if the
`polkit-pkla-compat` package is not installed.)

12. The default X startup script (`xstartup.turbovnc`) now throws an error,
rather than trying to execute **xinitrc** or twm, if a window manager is
specified and the session desktop file for the window manager cannot be found.


3.0.3
=====
Expand Down
12 changes: 6 additions & 6 deletions unix/vncserver.man.in
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ another command to launch the window manager.
.TP
\fB-wm\fR \fIwindow-manager\fR
This sets the value of the \fBTVNC_WM\fR environment variable to
\fIwindow-manager\fR. The default X startup script will launch the window
manager specified in the \fBTVNC_WM\fR environment variable, if it is set and a
\fIwindow-manager\fR. If the \fBTVNC_WM\fR environment variable is set, then
the default X startup script will launch the specified window manager if a
corresponding session desktop file exists under \fB/usr/share/xsessions\fR
(\fB/usr/local/share/xsessions\fR on *BSD systems.) If the window manager is
not specified, then the default X startup script will launch the "gnome" or
"ubuntu" window manager if a corresponding session desktop file exists and
execute \fB/etc/X11/xinit/xinitrc\fR otherwise.
(\fB/usr/local/share/xsessions\fR on *BSD systems) and fail otherwise. If the
window manager is not specified, then the default X startup script will launch
the "gnome" or "ubuntu" window manager if a corresponding session desktop file
exists and execute \fB/etc/X11/xinit/xinitrc\fR otherwise.
.TP
\fB\-x509cert\fR \fIcert\fR
Specify the X.509 signed certificate file (in PEM format) to use with X.509
Expand Down
51 changes: 33 additions & 18 deletions unix/xstartup.turbovnc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,31 @@ OS=`uname -s`

# Emulate GDM

find_session()
{
for SESSION in $SESSIONS; do
if [ "$XSESSIONSDIR" != "" -a -f $XSESSIONSDIR/$SESSION.desktop ]; then
DESKTOP_SESSION=$SESSION; export DESKTOP_SESSION
fi
done
if [ "$DESKTOP_SESSION" = "" ]; then
if [ "$TVNC_WM" = "" ]; then
echo "xstartup.turbovnc: The session desktop file for the default window manager was"
echo "xstartup.turbovnc: not found at:"
else
echo "xstartup.turbovnc: The session desktop file for the '$TVNC_WM'"
echo "xstartup.turbovnc: window manager was not found at:"
fi
for SESSION in $SESSIONS; do
echo "xstartup.turbovnc: $XSESSIONSDIR/$SESSION.desktop"
done
if [ "$TVNC_WM" != "" ]; then
exit 1
fi
fi
unset SESSIONS
}

# Use Unity 2D on Ubuntu 12 if no WM is specified. Historically, Unity 3D
# 5.20.x didn't even pretend to work properly with our X server, although it
# probably would now.
Expand Down Expand Up @@ -113,16 +138,12 @@ case "$TVNC_WM" in
NOXSESSION=1
TVNC_WM=`echo $TVNC_WM | $SED -r 's/:noxsession$//g'`
fi
# RHEL 7, Fedora: gnome-classic
# RHEL 7+, Fedora: gnome-classic
# Ubuntu 12: ubuntu-2d
# Ubuntu 14: gnome-fallback
# Ubuntu 16+: gnome-flashback-metacity
for SESSION in "gnome-classic" "gnome-fallback" "ubuntu-2d" "2d-gnome" \
"gnome-flashback-metacity"; do
if [ "$XSESSIONSDIR" != "" -a -f $XSESSIONSDIR/$SESSION.desktop ]; then
DESKTOP_SESSION=$SESSION; export DESKTOP_SESSION
fi
done
SESSIONS="gnome-classic gnome-fallback ubuntu-2d 2d-gnome gnome-flashback-metacity"
find_session
unset TVNC_WM
;;
*)
Expand All @@ -136,22 +157,16 @@ case "$TVNC_WM" in
esac
if [ "$TVNC_WM" = "" ]; then
# No window manager was specified. Use GNOME or Unity if it exists.
for SESSION in "gnome" "ubuntu"; do
if [ "$XSESSIONSDIR" != "" -a -f $XSESSIONSDIR/$SESSION.desktop ]; then
DESKTOP_SESSION=$SESSION; export DESKTOP_SESSION
fi
done
SESSIONS="gnome ubuntu"
find_session
else
# For backward compatibility with TurboVNC 2.2.x, we allow a window
# manager's startup script (e.g. mate-session, gnome-session) to be
# specified using -wm / $wm, but if there is a matching session desktop
# file for it, we use that instead.
SESSION=`echo $TVNC_WM | $SED -r 's/^.*\/|-session$//g'`
if [ "$XSESSIONSDIR" != "" -a -f "$XSESSIONSDIR/$SESSION.desktop" ]; then
DESKTOP_SESSION=$SESSION; export DESKTOP_SESSION
unset TVNC_WM
fi
unset SESSION
SESSIONS="`echo $TVNC_WM | $SED -r 's/^.*\/|-session$//g'`"
find_session
unset TVNC_WM
fi
;;
esac
Expand Down

0 comments on commit 89c47eb

Please sign in to comment.