KEMBAR78
Switch `wslinfo --vm-id` to not rely on presence of VM ID environment variable by benhillis · Pull Request #13318 · microsoft/WSL · GitHub
Skip to content

Conversation

@benhillis
Copy link
Member

@benhillis benhillis commented Jul 31, 2025

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.

@benhillis benhillis force-pushed the user/benhill/vm_id branch from 48ca452 to e421e91 Compare August 4, 2025 18:42
@benhillis
Copy link
Member Author

Still need an updated WSLg to make this work.

@benhillis benhillis changed the title Switch WSLg to use wslinfo --vm-id instead of relying on environment variable. Switch wslinfo --vm-id to not rely on presence of VM ID environment variable Aug 5, 2025
@benhillis benhillis requested a review from Copilot August 5, 2025 17:45
Copy link
Contributor

Copilot AI left a 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 LxInitMessageQueryVmId for 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>
@benhillis benhillis merged commit 6423313 into master Aug 5, 2025
6 checks passed
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 this pull request may close these issues.

2 participants