7

Okay, here is the strange behavior. I created myself WSL shortcuts in my taskbar to be able to open for instance the gnome-terminal linux graphical app from the shortcut CTRL+ALT+T. The shortcut worked the day I created it, but it doesn't work anymore.

Here is the command of the shortcut located in C:\Users\guill\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Ubuntu file: wslg ~ gnome-terminal

The app will or will not open in these situations depending on wheter or not I have already opened it a first time from the cmd wsl:

  • Once I'm logged in to Windows and that my computer had sufficient time to boot and open the startup applications, the app won't open at this moment with the shortcut.
  • Then, if I first open cmd.exe and then type in wsl to get into wsl, then I have wsl opened in the background. At this moment, trying the shortcut still won't work.
  • Then, if I type in gnome-terminal in the wsl command-line session opened from the cmd, the gnome terminal will properly open. If I then do the keyboard shortcut, the gnome terminal will open.

Note that in the text above, each time that I say that I pressed the keyboard shortcut, it has the same result as trying to open the application from the pinned icon in the taskbar, and vice-versa. The one with the wslg ~ gnome-terminal command in the start menu folder.

So what's up with that? It seems that the graphical apps needs to be opened at least one time before I'm able to open them from the start menu or keyboard shortcut. I'd like WSL to always open at startup. I'd also like WSL to always be ready to open apps from shortcuts. I don't know what to do at this point.

I am considering installing Linux again on this computer. WSL doesn't meet my expectations right now. I am on Windows 11.

Thanks!

2 Answers 2

3

Short answer:

Try:

wslg ~ dbus-launch gnome-terminal

Explanation:

This doesn't appear to be a problem with "graphical apps" in general, but rather with specific applications.

For instance, if you install xterm and set it up as a shortcut the same way, I think you'll find that the shortcut works as you would expect without having previously launched from within the command-line.

Gnome Terminal, on the other hand, is (to state the obvious) a Gnome application. Most Gnome applications require at least D-Bus support, and many require Systemd. Fortunately, Gnome Terminal just requires D-Bus.

If you launch it from the command-line in a new WSL instance, you'll see with a ps -efH that it has started a user-session D-Bus instance for you. If you have gvfs installed (which isn't by default, although perhaps it was installed as a dependency of Gnome Terminal), you'll also see that its daemon has been started (via D-Bus).

So when you then, subsequently, launch wslg ~ gnome-terminal, D-Bus is already running and Gnome Terminal launches properly. (Note: It's actually a little more complicated than that, since Gnome Terminal really launches as part of a client-server application and it's the server that doesn't start in this case.)

But when you attempt to launch it directly via:

  • wslg ~ gnome-terminal
  • Or even just wsl ~ gnome-terminal

... then it seems to me that a fairly obscure WSL bug comes into play. It's possible that this is "expected" in the way that WSL starts up, but I've run into this in the past, and it appears to me that WSL's init process is overly aggressive about reaping and terminating orphaned processes that are launched by another process during startup.

So in this case, as far as I can tell (and I haven't strace'd it yet to confirm), Gnome Terminal attempts to start D-Bus, but the init reaps it and closes it (improperly, I believe). As a result, without D-Bus running, Gnome Terminal (actually the server, I believe) does not start.

The workaround above, though, explicitly launches Gnome Terminal inside a D-Bus session, so things work as expected.

3
  • Hi! Thanks, it seems to work for what regards starting it the first time. However, it works one time out of two. Sometimes the new windows open a fraction of a second and it closes as soon as it was opened. Any thoughts? Commented Jun 13, 2022 at 13:31
  • 1
    @GuillaumeChevalier "Any thoughts" - Yup! That sounds suspiciously like this issue, although you'll need to read my answer there to understand why I think they are the same. It happens to me in xterm -- If you exit with Ctrl+D, either that or just "d" will get sent to the gnome-terminal window the second time you open it. If that's really what you are seeing in this case, then it's a WSLg bug that's fixed in the latest preview. Commented Jun 13, 2022 at 13:36
  • Sounds like it's this issue, ha! Thank you. Commented Jun 13, 2022 at 13:47
2

This sounds pretty similar to my problem: Windows 11 WSL LxTerminal closes after pressing first character

My work-around was to start automatically some of Ubuntu's services from the Startup folder, as follows (copy&paste from my own post):

  1. Created /home/ktuulos/scripts/init-wsl.sh with following content, and chmodded it as executable:

    #!/bin/sh
    sudo service rsyslog start
    sudo service cron start
    
  2. Created /etc/sudoers.d/10-service (using visudo):

    %sudo   ALL=(ALL) NOPASSWD: /usr/sbin/service
    
  3. Opened Windows File Explorer, went to shell:startup folder and created file init-wsl.cmd:

    wsl /home/ktuulos/scripts/init-wsl.sh
    

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .