WhitewaterFoundry / Pengwin

A Linux distro optimized for WSL based on Debian.
Other
1.48k stars 105 forks source link

WLinux does not support "hot-launch" an XServer app (without explicitly specifying DISPLAY) #129

Closed n3rd4i closed 4 years ago

n3rd4i commented 6 years ago

Describe the bug One of the main features that WLinux is providing is:

Support for many Linux graphical applications with no need to configure display or libGL in Wlinux. (Requires a Windows-based X client, such as X410.)

The issue that I've found is that does not work in case of user wants to hot-launch an XServer app from e.g.:

  1. cmd.exe
  2. windows RUN (WIN + R)

To Reproduce Steps to reproduce the behavior:

  1. Install x11-apps in Wlinux: sudo apt update && sudo apt install -y x11-apps
  2. Run command (in cmd.exe): wlinux run DISPLAY=:0 xeyes
  3. The xeyes window is now visible
  4. Close the xeyes window
  5. Run command (in cmd.exe): wlinux run xeyes
  6. The xeyes window is NOT visible, error: Error: Can't open display:
  7. Behaviour is identical in case of replacing wlinux run <xserver command> with wsl <xserver command> (assuming WLinux is default distro)

Expected behavior Based on the main features of WLinux expectation was that hot-launch is supported.

Basic Troubleshooting Checklist

[x] I have confirmed WSL is enabled: https://docs.microsoft.com/en-us/windows/wsl/troubleshooting#confirm-wsl-is-enabled. [x] I have searched Google for the error message. [x] I have searched the official Microsoft WSL issues page: https://github.com/Microsoft/WSL/issues. [x] I have searched the WLinux issues page: https://github.com/WhitewaterFoundry/WLinux/issues. [x] I have reset WLinux: Settings->Apps->Apps & features->WLinux->Advanced Options->Reset. [x] I have disabled and re-enabled WSL in Windows Features. [x] I have run Windows 10 updates and restarted.

What other troubleshooting have you attempted?

Insert here:

WLinux Version

Find: Settings->Apps->Apps & features->WLinux->Advanced Options->Version.

Insert here: 1.1.22.0

Windows Build

Run systeminfo | findstr /C:"OS" | clip in Command Prompt and insert here: OS Name: Microsoft Windows 10 Pro Insider Preview OS Version: 10.0.18252 N/A Build 18252 OS Manufacturer: Microsoft Corporation OS Configuration: Standalone Workstation OS Build Type: Multiprocessor Free

For help on retrieving: https://docs.microsoft.com/en-us/windows/wsl/troubleshooting#check-your-build-number

sirredbeard commented 6 years ago

Thank you for an excellent bug report. I will try to reproduce and report back.

n3rd4i commented 6 years ago

Just run this command ONLY at first launch of WLinux: echo export DISPLAY=:0 >> ~/.bashrc. This will append the command at last of .bashrc file. Also .zshrc for zsh.

The above allegedly workaround does not fix anything, problem persists after executing the proposed command.

n3rd4i commented 6 years ago

Check if this line export DISPLAY=:0 present at the end of .bashrc file in your WSL user home directory. If not then add that.

I can confirm that .bashrc contains export DISPLAY=:0 and behavior is as I already explained (issue not fixed). I guess that the file .bashrc is not even evaluated in case of "hot-launch" so it does not matter what this file contains.

khuongduybui commented 6 years ago

I'm using Fish shell and have X410 launched (if not already) and DISPLAY variable setting in my config.fish file. I also set my shell to /usr/bin/fish -l with chsh (I think the new setup script also asks to do this for you).

When I run wlinux run code from Win + R dialog, it does launch Visual Studio Code in x410.

n3rd4i commented 6 years ago

I also set my shell to /usr/bin/fish -l with chsh (I think the new setup script also asks to do this for you).

Indeed, using the above command parses the .bashrc file because the --login argument does that. (having export DISPLAY=:0 in .bashrc is not needed, it seems --login takes that from somewhere else)

So the question becomes how to change the /bin/bash to /bin/bash -l. Directly changing with chsh does not work (trying that break the shell).

chsh: Warning: /bin/bash -l does not exist

After this trying sudo su:

Cannot execute /bin/bash -l: No such file or directory

Luckily one could change it back to default with sudo vipw

I also tried this and it works as expected: wlinux run /bin/bash -lc xeyes

khuongduybui commented 6 years ago

Actually my bad. I don't have -l in my chsh either, just /usr/bin/fish. When I run wlinux run code, for example, it does load my config.fish without launching byobu (which is set to launch if status --is-login).

n3rd4i commented 6 years ago

So basically the only simple/supported way to hot-launch XServer based app is to install fish instead of bash and configure it.

@khuongduybui Maybe you could add a sample-partial configuration (config.fish) for such support? Or only export DISPLAY=:0 should exist @ the end of the file?

This could be a workable workaround even if breaks the original No need to configure DISPLAY quote from the docs

PeteSL commented 5 years ago

I added export DISPLAY=:0 to /etc/bash.bashrc before the interactive test and it now is set when I start WLinux from File Explorer on a directory but not when I use "wlinux run". A little closer...

crramirez commented 5 years ago

Please run this script in bash:

#!/bin/bash

#Copy configuration to  fish
sudo mkdir -p "${__fish_sysconf_dir:=/etc/fish/conf.d}"
echo "set -x DISPLAY :0" | sudo tee "${__fish_sysconf_dir}/display.fish"
# enable external libgl
echo "set -x LIBGL_ALWAYS_INDIRECT 1" | sudo tee -a "${__fish_sysconf_dir}/display.fish"
# speed up some GUI apps
echo "set -x NO_AT_BRIDGE 1" | sudo tee -a "${__fish_sysconf_dir}/display.fish"

And additionally you can now use Ctrl+V in fish

PeteSL commented 5 years ago

That's great if you want to run fish but I prefer bash since that is what most of my clients are running on their Linux systems. Origin of this thread is to get bash to work properly.

crramirez commented 5 years ago

Sorry man I didn't understand well the issue. Let me read it well. I tough that the problem was with fish. Probably the problem is with nologin shell which won't read the /etc/profile. I will make some tests

crramirez commented 5 years ago

Doesn't it work?

wlinux.exe run "bash -l -c xeyes" or wlinux.exe run "bash -l -c code" ?

Regards

PeteSL commented 5 years ago

wlinux.exe run xeyes or wlinux.exe run code does not have DISPLAY=:0. run wlinux run set to see that it is not set. Running your commands calling out the bash shell with the -l switch does set DISPLAY=:0 with my change to /etc/bash.bashrc Apparently, the "hot-launch" of the bash shell (default) does not execute /etc/bash.bashrc. So the question is, what does it execute so we can export DISPLAY=:0?

crramirez commented 5 years ago

This is because it executes a non-login shell. Read this with the explanation where to put the environment variables: https://unix.stackexchange.com/questions/38175/difference-between-login-shell-and-non-login-shell.

Here is a good explanation about this: https://stackoverflow.com/questions/902946/about-bash-profile-bashrc-and-where-should-alias-be-written-in

Regards

PeteSL commented 5 years ago

When a shell runs a script or a command passed on its command line, it's a non-interactive, non-login shell. Such shells run all the time: it's very common that when a program calls another program, it really runs a tiny script in a shell to invoke that other program. Some shells read a startup file in this case (bash runs the file indicated by the BASH_ENV variable

Where does BASH_ENV get set? /etc/profile already comes with export DISPLAY=:0 and, as I indicated, we can get the File Explorer shell start to set it via /etc/bash.bashrc. So it may be we can't set it automatically when simply running a command using the "run" command with wlinux, at least using the default bash shell?

crramirez commented 5 years ago

BASH_ENV is not set and setting it in an initialization files would cause the same issues as setting DISPLAY one

sirredbeard commented 5 years ago

I think one solution might be calling a bash script with wlinux.exe run script.sh that sets variables instead of a GUI app directly.

The other option might be to call the silently set DISPLAY using a shell call in the C++ launcher code on each launch here: https://github.com/WhitewaterFoundry/WLinux/blob/master/DistroLauncher/DistroLauncher.cpp#L117. But that would not be user configurable, would prevent users from forwarding X display to other servers. It would also have a slight impact on launch speed.

n3rd4i commented 4 years ago

since this is stalled, I will close.