-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Switch wslinfo --vm-id to not rely on presence of VM ID environment variable
#13318
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
Conversation
48ca452 to
e421e91
Compare
|
Still need an updated WSLg to make this work. |
wslinfo --vm-id to not rely on presence of VM ID environment variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>
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.