Open CarlosNihelton opened 2 years ago
Just curious where it is used.
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:
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.
There should be an official way to detect whether wslg is enabled or not without executing any ELF binary or poking a file.
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?
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.
I didn't find any better way other than inspecting sockets.
Wondering what that will be.
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
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.
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?
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 🤐
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.