mviereck / x11docker

Run GUI applications and desktops in docker and podman containers. Focus on security.
MIT License
5.62k stars 378 forks source link

A fatal bug [running two Xorg on same tty] #404

Closed CicadaSeventeen closed 2 years ago

CicadaSeventeen commented 2 years ago

Environment: openSUSE leap 15.3 with xfce and lightDM on Thinkpad P15v gen1 No Xephyr because it is absent in both zypper and opi so I do not bother to install. Files building: 1, ~/test.sh: is to communicate between docker and host: #!/bin/bash while [ 1 -eq 1 ] do tem=$(sed -n '1p' $1) sed -i '1d' $1 bash -c "$tem" sleep 0.2 done 2, touch ~/temcom.txt

Operation: 1, switch to a black tty, ie tty1, and log in 2, input ~/test.sh ~/temcom.txt & 3, input sudo -E x11docker --share=home x11docker/xfce 4, open a xfce4-terminal in xfce and input echo "sudo -E x11docker --hostdisplay --exe xterm" >~/temcom.txt

Result: 1, Crash and back to black tty. However, both Ctrl+C and Enter do not work 2, Three branches: Branch 1: Immediately switch to another tty and then do anything as wanted Branch 2: Wait for several second and then computer will get stuck. Ctrl+Alt+Fx will not work to switch to any other tty. I have to force poweroff by physics. Branch 3: Immediately switch to another tty, wait for several seconds, and switch back to tty1, and then just like Branch 2

It seems that after crash the SHELL of x11docker just stuck itself. It is OK to crash since I do some abnormal thing but it is fatal to crash the whole system. Please check.

Thanks.

CicadaSeventeen commented 2 years ago

The xfce DE run in container is on nothing else but a Xorg. Since after startx running x11docker is OK, it is strange that after using x11docker to open a Xorg then x11docker does not work. I try --ngagent instead of '--hostdisplay'. Well it does not crash, it just run like --desktop covering the xfce desktop rather than in seamless mode.

mviereck commented 2 years ago

The crash happens if Xorg is started on a tty where already an Xorg is running. But x11docker tries to detect and avoid that.

I get a similar crash if I force x11docker to use the same tty twice with option --vt. However, if i don't do that, it detects a free tty as expected.

Maybe the check fails on your system. Can you please show me the output of command tty twice:

Please also show me the output of find /sys/class/vc/vcsa* that should list ttys already in use. This one also twice, before running x11docker and than while it is running.

Edit:

No Xephyr because it is absent in both zypper and opi so I do not bother to install.

The package name is likely xorg-x11-server-xephyr. Compare https://github.com/mviereck/x11docker/wiki/dependencies

mviereck commented 2 years ago

Side note: Instead of your current script setup I recommend tu use a fifo. Example:

CicadaSeventeen commented 2 years ago

Sorry for replying late.


Everything is just fine if I use xhost + echo "export DISPLAY=$DISPLAY;x11docker --hostdisplay --exe xterm" >~/temcom.txt Crash only happens when no DISPLAY exported on host system. I have solve the problem for me, yet this crash is something I think really need fixing for it crash the system at whole.


Before starting x11docker there is nothing worth recording. output of x11docker --share=home x11docker/xfce is included in 1.txt and output of echo "x11docker --hostdisplay --exe xterm" >~/temcom.txt is included in '2.txt' log.tar.gz

mviereck commented 2 years ago

yet this crash is something I think really need fixing for it crash the system at whole.

This happens only in the quite special setup where you send back commands to the parent tty and run another Xorg there. I don't think x11docker should catch that. Just in case, you can specify another tty with option --vt.

xhost + echo "export DISPLAY=$DISPLAY;x11docker --hostdisplay --exe xterm" >~/temcom.txt

I recommend to use --printenv=FILE to get DISPLAY and XAUTHORITY as explained in https://github.com/mviereck/x11docker/issues/405#issuecomment-1002657464.

mviereck commented 2 years ago

I've added sort of a fix: If you add option --vt without an argument, x11docker will be forced to search for an unused tty. That will avoid the crash if sending back an Xorg command to the parent tty as your script does.

Normally, if x11docker is started on a tty, it assumes that it should use the same tty for Xorg and not switch to another one. But in your case, starting x11docker twice on same tty, this leads to a crash that can now be avoided with --vt forcing x11docker to search for another tty.

CicadaSeventeen commented 2 years ago

OK I think that. Sorry for late for I rested during Newyear. Thanks for your advise.