Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 936475 - net-misc/tigervnc-1.13.1-r3: the server service ignores session= parameter, exits right away without a DM
Summary: net-misc/tigervnc-1.13.1-r3: the server service ignores session= parameter, e...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Viorel Munteanu
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-07-22 00:35 UTC by Andrey
Modified: 2024-07-27 19:36 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrey 2024-07-22 00:35:37 UTC
I had a hard time getting tigervnc service to work on a headless machine.

Basically, Xvnc starts but then exits right away.

Installing x11-misc/slim as the ebuild recommends "for proper session support" doesn't help either.


Reproducible: Always

Steps to Reproduce:
1. Start with a system with no X11, no desktop environments.
2. USE="server" emerge -v net-misc/tigervnc x11-wm/awesome
   (any other WM can be used as well)
3. ln -s tigervnc /etc/init.d/tigervnc.10
4. echo ":10=myuser" >> /etc/tigervnc/vncserver.users
5. mkdir -p /home/myuser/.vnc/
6. echo "session=awesome" >> /home/myuser/.vnc/config
7. /etc/init.d/tigervnc.10 restart
Actual Results:  

No Xvnc is server running.


~/.xsession-errors contains the following:
```
/etc/X11/Sessions/Xsession: line 112: exec: xsm: not found
```


~/.vnc/*:10.log doesn't contain anything suspicious -- it just indicates that the server exited right away:
```
Using desktop session awesome

New 'myhostname:10 (myuser)' desktop is myhostname:10

Starting desktop session awesome


Xvnc TigerVNC 1.13.1 - built Jul 22 2024 03:10:57
Copyright (C) 1999-2022 TigerVNC Team and many others (see README.rst)
See https://www.tigervnc.org for information on TigerVNC.
Underlying X server release 12101008


Mon Jul 22 03:12:36 2024
 vncext:      VNC extension running!
 vncext:      Listening for VNC connections on local interface(s), port 5910
 vncext:      created VNC server for screen 0
[mi] mieq: warning: overriding existing handler (nil) with 0x55f19420dbd0 for event 2
[mi] mieq: warning: overriding existing handler (nil) with 0x55f19420dbd0 for event 3
xinit: XFree86_VT property unexpectedly has 0 items instead of 1
xinit: connection to X server lost

waiting for X server to shut down  ComparingUpdateTracker: 0 pixels in / 0 pixels out
 ComparingUpdateTracker: (1:-nan ratio)

```

Expected Results:  
Xvnc is running, the WM session is launched.
Comment 1 Andrey 2024-07-22 00:58:31 UTC
I tracked down what's going on to some extent.


`/etc/init.d/tigervnc` calls `/usr/libexec/vncsession-start`,
which does a couple of sanity checks.
It then calls `/usr/sbin/vncsession`.

`/usr/sbin/vncsession` handles PAM and daemonization, sets `XDG_SESSION_CLASS` and `XDG_SESSION_TYPE`, and then calls `/usr/bin/vncserver`.
This is where the fun starts -- it reads VNC configs and goes on calling `xinit`.

In my case the `xinit` call looks as follows:
`xinit /etc/X11/Sessions/Xsession /etc/X11/Sessions/awesome -- /usr/bin/Xvnc :10 -depth 24 -geometry 1280x900 -localhost -auth /home/myuser/.Xauthority -desktop "myhostname:10 (myuser)" -pn -rfbauth /home/myuser/.vnc/passwd -rfbport 5910`

Basically, the problem here is that `/etc/X11/Sessions/Xsession` ignores any arguments passed to it (unless the argument is "failsafe").


> Installing x11-misc/slim as the ebuild recommends "for proper session support" doesn't help either.

And this doesn't work because `/usr/share/slim/Xsession` is non-executable,
so `vncserver` ignores it.

Doing `chmod a+x /usr/share/slim/Xsession` fixes the problem and let's the X11 session start normally.


I suspect that x11-misc/sddm might have the same problem as it also installs its Xsession under `/usr/share` -- `/usr/share/sddm/scripts/Xsession`.
Comment 2 Andrey 2024-07-22 01:49:11 UTC
I don't know the xsession stuff well enough (or rather at all),
but I see the following issues:

1. `vncserver` tries to find and start Xsession in order to start a `session=` defined in the config file.
    At least, on Gentoo, `/etc/X11/Sessions/Xsession` and `/etc/X11/Sessions/awesome` are almost identical (with the latter derived from the former), so it seems like `/etc/X11/Sessions/awesome` can just be run directly instead.

2. `vncserver` wants `Xsession` to be executable,
   but apparently `xinit` doesn't actually care and runs `/usr/share/slim/Xsession` just fine even if it's not executable.

A trivial fix for this would be
```diff
--- vncserver.orig 2024-07-22 03:08:31.000000000 +0300
+++ vncserver   2024-07-22 04:32:16.887261909 +0300
@@ -442,7 +442,7 @@ sub SanityCheck
     $Xsession=$ENV{TIGERVNC_XSESSION_FILE};
     if (not defined $Xsession) {
        foreach $cmd ("/usr/share/sddm/scripts/Xsession", "/etc/gdm/Xsession", "/etc/lightdm/Xsession", "/usr/share/slim/Xsession", "/etc/X11/Sessions/Xsession", "/etc/X11/xinit/Xsession", "/etc/X11/Xsession") {
-           if (-x "$cmd") {
+           if (-r "$cmd") {
                $Xsession = $cmd;
                last;
            }
```


3. `/etc/X11/Sessions/Xsession` basically ignores any arguments passed to it.
   For comparison, the one from x11-misc/slim ends with `exec $command` (where `command="$@"`).
   x11-misc/lightdm and x11-misc/sddm also do `exec $command` in the end.


A bet this has decades worth of history,
so any change can probably break something.
But nevertheless, this looks pretty low-risk to me:
```diff
--- Xsession.orig       2024-07-22 03:44:43.951197197 +0300
+++ Xsession    2024-07-22 04:46:54.475274950 +0300
@@ -100,15 +100,20 @@

 unset XKB_IN_USE

+if [ -n "$*" ] ; then
+       "$@" &
+fi
+
 if [ -x "$startup" ]; then
-       exec "$startup"
+       "$startup"
 elif [ -x "$HOME/.Xclients" ]; then
-       exec "$HOME/.Xclients"
+       "$HOME/.Xclients"
 elif [ -x /etc/X11/xinit/Xclients ]; then
-       exec /etc/X11/xinit/Xclients
+       /etc/X11/xinit/Xclients
 elif [ -x /etc/X11/Xclients ]; then
-       exec /etc/X11/Xclients
+       /etc/X11/Xclients
 else
-       exec xsm
+       xsm
 fi
+wait
 true
```
Comment 3 Andrey 2024-07-22 02:02:49 UTC
The simplest workaround I've found so far
(which doesn't require installing a DM or hacking `/etc/X11/Sessions/Xsession`)
is setting `TIGERVNC_XSESSION_FILE="/usr/bin/env"` in `/etc/conf.d/tigervnc`.
(or creating a display-specific `/etc/conf.d/tigervnc.10` and setting it there)


Setting `TIGERVNC_XSESSION_FILE=/etc/X11/Sessions/awesome` also works,
but then the `session=` parameter from `~/.vnc/config` gets ignored essentially.
Comment 4 Viorel Munteanu gentoo-dev 2024-07-22 08:15:24 UTC
Thank you for your in-depth analysis.

I'll try to test a few of your suggestions and see what I can do without breaking things.
Comment 5 Viorel Munteanu gentoo-dev 2024-07-27 17:43:58 UTC
(In reply to Andrey from comment #2)
> 2. `vncserver` wants `Xsession` to be executable,
>    but apparently `xinit` doesn't actually care and runs
> `/usr/share/slim/Xsession` just fine even if it's not executable.
> 
> A trivial fix for this would be
> ```diff
> --- vncserver.orig 2024-07-22 03:08:31.000000000 +0300
> +++ vncserver   2024-07-22 04:32:16.887261909 +0300
> @@ -442,7 +442,7 @@ sub SanityCheck
>      $Xsession=$ENV{TIGERVNC_XSESSION_FILE};
>      if (not defined $Xsession) {
>         foreach $cmd ("/usr/share/sddm/scripts/Xsession",
> "/etc/gdm/Xsession", "/etc/lightdm/Xsession", "/usr/share/slim/Xsession",
> "/etc/X11/Sessions/Xsession", "/etc/X11/xinit/Xsession",
> "/etc/X11/Xsession") {
> -           if (-x "$cmd") {
> +           if (-r "$cmd") {
>                 $Xsession = $cmd;
>                 last;
>             }
> ```

On my system slim's session file is indeed not executable.

$ ls -l /usr/share/sddm/scripts/Xsession /etc/gdm/Xsession /etc/lightdm/Xsession /usr/share/slim/Xsession /etc/X11/Sessions/Xsession
-rwxr-xr-x 1 root root 6092 mar 31 21:19 /etc/gdm/Xsession
-rwxr-xr-x 1 root root 1962 mar 31 05:58 /etc/lightdm/Xsession
-rwxr-xr-x 1 root root 2187 mar 30 16:16 /etc/X11/Sessions/Xsession
-rwxr-xr-x 1 root root 2852 mai  6 15:22 /usr/share/sddm/scripts/Xsession
-rw-r--r-- 1 root root 4045 mar 30 15:33 /usr/share/slim/Xsession

Considering I was already patching vncserver, I'll change it to `-r`.


> 3. `/etc/X11/Sessions/Xsession` basically ignores any arguments passed to it.
>    For comparison, the one from x11-misc/slim ends with `exec $command`
> (where `command="$@"`).
>    x11-misc/lightdm and x11-misc/sddm also do `exec $command` in the end.

This is exactly why I added that message about installing a proper display manager.
Comment 6 Larry the Git Cow gentoo-dev 2024-07-27 19:36:36 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=6f4b28e562378215406f8481c84f1ad95062145c

commit 6f4b28e562378215406f8481c84f1ad95062145c
Author:     Viorel Munteanu <ceamac@gentoo.org>
AuthorDate: 2024-07-27 19:21:50 +0000
Commit:     Viorel Munteanu <ceamac@gentoo.org>
CommitDate: 2024-07-27 19:36:02 +0000

    net-misc/tigervnc: add 1.14.0
    
    Add 1.14.0.
    Small changes to configuration files.
    
    Closes: https://bugs.gentoo.org/936442
    Closes: https://bugs.gentoo.org/936475
    Signed-off-by: Viorel Munteanu <ceamac@gentoo.org>

 net-misc/tigervnc/Manifest                         |   1 +
 .../files/tigervnc-1.14.0-xsession-path.patch      |  28 +++
 net-misc/tigervnc/files/tigervnc-1.14.0.confd      |  13 ++
 net-misc/tigervnc/files/tigervnc-1.14.0.initd      |  90 ++++++++
 net-misc/tigervnc/tigervnc-1.14.0.ebuild           | 235 +++++++++++++++++++++
 5 files changed, 367 insertions(+)