Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User sessions started from non-wsl.exe sources (such as systemd services) don't have WSL_INTEROP #8846

Open
1 of 2 tasks
cerebrate opened this issue Sep 22, 2022 · 5 comments

Comments

@cerebrate
Copy link

Version

Microsoft Windows [Version 10.0.22000.856]

WSL Version

  • WSL 2
  • WSL 1

Kernel Version

5.15.62.1-20220921-1-microsoft-custom-WSL2+

Distro Version

Debian bookworm/sid

Other Software

No response

Repro Steps

  1. Ensure that your WSL distro has systemd-machined installed and enabled.
  2. Start a WSL session.
  3. At this point, in the shell created by wsl.exe, echo $WSL_INTEROP will return a value, such as /run/WSL/136_interop
  4. Use sudo machinectl shell <username>@.host to enter a user session under systemd.

(This is used as a workaround to get a systemd user session created; see #8842 . But the same issue applies to any user session created under systemd/by non-wsl.exe means, including ssh, etc.)

  1. At this point, echo $WSL_INTEROP will show nothing.
  2. Attempt to run a Windows application, such as /mnt/c/Windows/notepad.exe

Expected Behavior

The Windows application should run as normal for interop.

Actual Behavior

The Windows application fails to run and exit code 1 is returned:

❯ /mnt/c/Windows/notepad.exe
[1]    31535 exit 1     /mnt/c/Windows/notepad.exe

Diagnostic Logs

No response

@cerebrate
Copy link
Author

The failure in this case is obviously from the lack of WSL_INTEROP in systemd-started sessions. It can be worked around, if you have a long-running WSL session, by pushing the WSL_INTEROP environment variable for that session into the system environment block using

systemctl import-environment WSL_INTEROP

at which point it is inherited by all systemd services and sessions.

(The problem with that is that while it was a viable solution for genie, because the init above genie would always be around for as long as systemd would be, there isn't such a guaranteed-present-as-long-as-systemd init around under the native systemd support - and so this workaround relies on keeping one particular WSL session open perpetually to provide the socket behind WSL_INTEROP.)

@benhillis
Copy link
Member

Thanks - I agree launching Windows processes from things launched from systemd would be a good enhancement and shouldn't be too bad to implement. I'll see what I can do.

@jelical
Copy link

jelical commented Sep 24, 2022

Voting for this enhancement - I am specifically prefer to use my XWin instead of wslg and till now i enabled it from systemd user unit. Unfortunately it stopped working when I moved to builtin systemd

@cerebrate
Copy link
Author

Same problem in 68.2, I'm afraid. Both, in fact - no WSL_INTEROP in the systemd or systemd user session environment, and the binfmt is lost.

@qcasey
Copy link

qcasey commented Dec 19, 2023

The solutions provided in #5065 are a workaround for my own systemd services

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants