Switch wslinfo --vm-id to not rely on presence of VM ID environment variable#13318
Merged
Switch wslinfo --vm-id to not rely on presence of VM ID environment variable#13318
wslinfo --vm-id to not rely on presence of VM ID environment variable#13318Conversation
benhillis
commented
Jul 31, 2025
6 tasks
OneBlue
reviewed
Jul 31, 2025
48ca452 to
e421e91
Compare
Member
Author
|
Still need an updated WSLg to make this work. |
OneBlue
reviewed
Aug 5, 2025
wslinfo --vm-id to not rely on presence of VM ID environment variable
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR changes wslinfo --vm-id to query the VM ID directly from the init process rather than relying on the WSL2_VM_ID environment variable, making the implementation more robust and discouraging fragile assumptions about environment variables.
- Adds a new message type
LxInitMessageQueryVmIdfor querying VM ID from the init process - Implements
UtilGetVmId()function to communicate with init via socket channel - Updates test to validate VM ID format and ensure environment variable is not exposed to user commands
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/windows/UnitTests.cpp | Updates test to validate VM ID format and verify environment variable is not propagated to user commands |
| src/shared/inc/lxinitshared.h | Adds new message type and struct for VM ID queries |
| src/linux/init/wslinfo.cpp | Changes VM ID retrieval to use new UtilGetVmId() function instead of environment variable |
| src/linux/init/util.h | Declares new UtilGetVmId() function |
| src/linux/init/util.cpp | Implements UtilGetVmId() to query VM ID from init process via socket |
| src/linux/init/main.cpp | Adds WSL2_SYSTEM_DISTRO environment variable for system distros |
| src/linux/init/init.cpp | Stores VM ID in config and conditionally unsets environment variable for user distros |
| src/linux/init/config.cpp | Handles VM ID query messages and removes VM ID from environment block |
| src/linux/init/WslDistributionConfig.h | Adds optional VM ID field to configuration struct |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
OneBlue
approved these changes
Aug 5, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change is a follow up from #13212. This is preferred because it discourages users of WSL from making assumptions about what environment variables may be present, which is fragile because processes can and do modify their environment.