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

Launcher cannot retrieve full subsystem settings. #96

Open
CarlosNihelton opened this issue Nov 24, 2021 · 11 comments · May be fixed by #97
Open

Launcher cannot retrieve full subsystem settings. #96

CarlosNihelton opened this issue Nov 24, 2021 · 11 comments · May be fixed by #97

Comments

@CarlosNihelton
Copy link

Greetings, all!

During development of the Ubuntu launcher we felt the need to retrieve more details from the subsystem configuration (besides the defaut configuration flags), details which are provided by the function WslGetConfiguration(), which is not exposed by WslApiLoader. Reference documentation about that function can be found here.

We implemented a simple addition to that class, which will be presented shortly as a pull request for your appreciation.

@CarlosNihelton CarlosNihelton linked a pull request Nov 24, 2021 that will close this issue
@Biswa96
Copy link

Biswa96 commented Nov 24, 2021

Just curious where it is used.

@CarlosNihelton
Copy link
Author

Hi! We have a custom routine for both distro installation and later reconfiguration. Currently, the preparation for that routine requires detection of subsystem version (1 or 2) and of graphical capabilities. But that might be require us to look into other aspects, like the default environment variables.

For now you can see the usage below:

https://github.com/ubuntu/WSL/blob/9cc33befc0f8af1b837212aa5190d111cbfef273/DistroLauncher/WSLInfo.cpp#L49

@Biswa96
Copy link

Biswa96 commented Nov 24, 2021

I am kind of thinking that mistake (probably). I may be wrong. As far as I can remember, the distributionVersion parameter does not reflect whether the distribution is in WSL1 or WSL2 environment. It reflects lxfs vs. wslfs, old topic.

This is undocumented but works. The wslDistributionFlags provides WSL1 vs WSL2. For WSL2, wslDistributionFlags has 0x08 flag or-ed.

@Biswa96
Copy link

Biswa96 commented Nov 24, 2021

There should be an official way to detect whether wslg is enabled or not without executing any ELF binary or poking a file.

@CarlosNihelton
Copy link
Author

CarlosNihelton commented Nov 24, 2021

I am kind of thinking that mistake (probably). I may be wrong. As far as I can remember, the distributionVersion parameter does not reflect whether the distribution is in WSL1 or WSL2 environment. It reflects lxfs vs. wslfs, old topic.

This is undocumented but works. The wslDistributionFlags provides WSL1 vs WSL2. For WSL2, wslDistributionFlags has 0x08 flag or-ed.

You are indeed right. Thanks for spotting my bug. Really appreciate it. Yet, just by the WSL_DISTRIBUTION_FLAGS_DEFAULT constant I wouldn't be able to detect WSL2.

It would be nice if the API itself provided a function for that specific piece of information. Would the 0x08 trick be documented anytime or you guys consider it an internal detail?

@CarlosNihelton
Copy link
Author

There should be an official way to detect whether wslg is enabled or not without executing any ELF binary or poking a file.

While I totally agree with you, I didn't find any better way other than inspecting sockets.

@Biswa96
Copy link

Biswa96 commented Nov 24, 2021

I didn't find any better way other than inspecting sockets.

Wondering what that will be.

@CarlosNihelton
Copy link
Author

I didn't find any better way other than inspecting sockets.

Wondering what that will be.

You can have a look if you want 😅
https://github.com/ubuntu/WSL/blob/9cc33befc0f8af1b837212aa5190d111cbfef273/DistroLauncher/WSLInfo.cpp#L79-L97

@Biswa96
Copy link

Biswa96 commented Nov 24, 2021

O, I thought AF_VSOCK vs. AF_INET.

In my opinion, the /tmp/.X11-unix path is not only for wslg. A program may use AF_UNIX socket even in WSL1 or in WSL2 for X servers only (like vcxsrv). AF_UNIX was added in 17063 build of Windows 10 whereas WSL2 was added 18362 build.

@CarlosNihelton
Copy link
Author

O, I thought AF_VSOCK vs. AF_INET.

In my opinion, the /tmp/.X11-unix path is not only for wslg. A program may use AF_UNIX socket even in WSL1 or in WSL2 for X servers only (like vcxsrv).

That sounds as interesting as challenging. AFAIK, AF_VSOCK would help to be sure I'm under WSL 2, but would it tell anything about WSLg? While I can ls -l /tmp/.X11-unix | grep wslg , doesn't tell the whole story either, since it also appears mounted on WSL 1 instances. Besides the fact that it still feels a bit hacky to my taste.

Any great tip like the 0x08 for this one or should I just make my commands more strict?

@Biswa96
Copy link

Biswa96 commented Nov 25, 2021

Any great tip like the 0x08 for this one or should I just make my commands more strict?

I'm not the right one to comment on that. But if this was not for Ubuntu or any stable software I have some dangerous tricks in my sleeve 🤐

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

Successfully merging a pull request may close this issue.

2 participants