Commit Graph

1203 Commits

Author SHA1 Message Date
Ben Hillis
d7828e8d84 Release COM DLLs before installer test MSI operations (#40093)
* Release COM DLLs before installer test MSI operations

Add PrepareForMsiOperation() that calls CoFreeUnusedLibrariesEx(0)
before each msiexec invocation. This releases in-process COM DLLs
like wslserviceproxystub.dll loaded by prior test classes, preventing
the Restart Manager from detecting the test process as holding file
locks and failing the install on older Server SKUs like ni_release.

* fix CoFreeUnusedLibrariesEx

---------

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
2026-04-03 11:15:49 -07:00
Blue
4ee26e6a80 Localization change from build: 143632468 (#40094)
Co-authored-by: WSL localization <noreply@microsoft.com>
2026-04-03 17:52:47 +00:00
beena352
3cf4cfae27 Allow small timestamp difference in ContainerRecoveryFromStorage test (#40081)
* Allow small timestamp difference in ContainerRecoveryFromStorage test

* feedback
2026-04-02 20:50:08 -07:00
Ben Hillis
d780923d9e Fix callback parameter shadow in CreateInternal (#40086)
* Remove unused callback parameter from CreateInternal

The IProgressCallback* parameter was always passed as nullptr by both
callers. The auto-pull path creates its own PullImageCallback locally.
Remove the dead parameter entirely per review feedback.

* format

---------

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
2026-04-02 18:31:56 -07:00
Ben Hillis
f8dc1ce035 Remove dead code: SetContainerTTYOptions and SetContainerArguments (#40087)
Both static functions in ContainerService.cpp are defined but never
called from anywhere in the codebase. They appear to be remnants of
an earlier implementation before the WSLCContainerLauncher and
WSLCProcessLauncher classes took over this responsibility.

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
2026-04-03 01:25:34 +00:00
Ben Hillis
d3383312e6 Add week/month/year support to FormatRelativeTime (#40083)
* Add week/month/year support to FormatRelativeTime

Previously only handled seconds, minutes, hours, and days. Containers
older than a week would show e.g. '720 days ago' instead of '2 years ago'.

Now matches Docker-style output with weeks, months, and years.
Also refactors repeated pluralization logic into a lambda.

* Handle timestamp==0 sentinel in FormatRelativeTime

Callers pass 0 to mean 'unknown' (e.g. ImageTasks when Created <= 0).
Previously this would produce '56 years ago'. Now returns empty string.

---------

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
2026-04-02 16:46:49 -07:00
Ben Hillis
bf7f2bb2fa Use THROW_HR_WITH_USER_ERROR for TTY console check (#40084)
Replace manual PrintMessage + THROW_HR(E_FAIL) with the standard
THROW_HR_WITH_USER_ERROR pattern used throughout the codebase. This
ensures the error message is properly captured by the ExecutionContext
error collection system rather than being printed directly to stderr.

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
2026-04-02 21:38:29 +00:00
Ben Hillis
26a8a0da82 devicehost: stop re-signing and rely on MSIRMSHUTDOWN for file-in-use handling (#40080)
* devicehost: stop re-signing and fix MSI installer failing to replace
wsldevicehost.dll

* pr feedback

* use MSIRMSHUTDOWN = 1 instead of custom action

---------

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
2.8.1
2026-04-02 13:25:54 -07:00
Blue
da5efafd45 Don't fail to start a WSLCSession if anonymous volumes are present (#40077)
* Don't fail to start a WSLCSession if anonymous volumes are present

* Typo

* Cleanup diff

* Cleanup diff
2026-04-02 12:24:48 -07:00
Ben Hillis
9ae92f2592 Suppress MSI-initiated reboots during Store updates (#40074)
When the WSL MSIX package is updated via the Microsoft Store, the
WslInstaller service automatically upgrades the MSI package by calling
MsiInstallProduct. This call was made with INSTALLUILEVEL_NONE (silent
install) but without setting the REBOOT=ReallySuppress property.

Per Windows Installer documentation, when a silent install encounters
files in use and REBOOT is not suppressed, the system reboots
automatically without any user prompt. This could cause unexpected
machine restarts after a Store update when WSL binaries (e.g.
wslservice.exe) were in use during the upgrade.

Every deployment script in the repo already passes /norestart to
msiexec (deploy-to-host.ps1, deploy-to-vm.ps1, install-latest-wsl.ps1,
test-setup.ps1), but the programmatic MsiInstallProduct path used by
the WslInstaller service lacked the equivalent property.

This change:
- Always appends REBOOT=ReallySuppress to MsiInstallProduct arguments
  in UpgradeViaMsi, preventing Windows Installer from ever initiating
  a system restart during install/upgrade.
- Switches UninstallViaMsi from MsiConfigureProduct to
  MsiConfigureProductEx so we can pass REBOOT=ReallySuppress during
  uninstall as well.
- Propagates ERROR_SUCCESS_REBOOT_REQUIRED (3010) to callers instead
  of swallowing it. User-facing paths (wsl --update, wsl --uninstall)
  print a reboot-needed message to stderr. The background WslInstaller
  service silently treats 3010 as success since it has no console.

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-02 12:23:53 -07:00
Blue
0c9f76c3a8 Fix race condition in ElevatedTokenCanOpenNonElevatedHandles test case (#40071) 2.8.0 2026-04-01 18:15:07 -07:00
Blue
fa859af9c7 Add a DllMain method to wslcsdk and configure tracelogging (#40070)
* Add a DllMain method to wslcsdk and configure tracelogging

* Explicitely initialize WIL
2026-04-01 18:04:15 -07:00
David Bennett
5d2391f96c Fix and improve interactive tests (#40069) 2026-04-01 17:03:51 -07:00
yao-msft
4fe7fc7d36 HostFileShareMode (#40068) 2026-04-01 16:42:33 -07:00
beena352
dee42d80cb Add port mappings to container list output (#14438) 2026-04-01 16:34:13 -07:00
beena352
801b145021 Add repository, tag, ID and created columns to image list output (#40043) 2026-04-01 16:19:22 -07:00
Blue
1cab9b06b8 Switch DmesgOutput to a WSLCHandle (#40063) 2026-04-01 13:51:09 -07:00
Blue
e330cbbde6 Keep track of handle types in the service (#40062)
* Keep track of handle types in the service

* Only duplicate on return

* Format
2026-04-01 13:51:06 -07:00
David Bennett
a188f0b828 CLI: Add table support to always show header, default true (#40061) 2026-04-01 19:18:35 +00:00
Kevin Vega
148545eae7 List and inspect named volumes (#14555) 2026-04-01 12:10:20 -07:00
David Bennett
a6746d1356 CLI: Add Terminate Session command (#40058) 2026-04-01 11:49:24 -07:00
JohnMcPMS
f0b9455bbe Implement SDK inspect and VHD management (#14545)
Implements `WslcInspectContainer` and `WslcCreateSessionVhd`; adds `WslcSetContainerSettingsNamedVolumes` so that the VHDs are useful.
2026-04-01 11:18:58 -07:00
Ben Hillis
e5eaeb2ca5 wslc: ensure dns tunneling is disabled with virtioproxy networking mode (#40057)
Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
2026-04-01 08:50:02 -07:00
Blue
c98558e9cc Use COM marshalling to exchange handles (#40056)
* Prototype

* Save state

* Save state

* Save state

* Save state

* Save state

* Save state

* Remove zeroing

* Apply PR feedback

* Add test coverage

* Format

* Add test coverage for null handles
2026-04-01 09:28:28 +00:00
David Bennett
51dc5f872e CLI: Table Output updates (#14534) 2026-04-01 07:35:01 +00:00
John Stephens
713fcda944 Add support for build logs (#40054) 2026-03-31 20:38:29 -07:00
Blue
40e57130df Fix race condition in ContainerLogs test case (#40052) 2026-03-31 17:57:51 -07:00
beena352
ff0abc2674 wslc Pretty-print JSON output for inspect and list commands (#40051) 2026-03-31 17:10:53 -07:00
David Bennett
e1d5a81b60 CLI: Create elevated and non-elevated sessions (#40047) 2026-03-31 23:55:37 +00:00
JohnMcPMS
fcf2973853 Implement SDK CanRun (#14539)
Implements `WslcCanRun` using existing primitives.  Updates the component flag names to help better describe their meaning and adds comments to further do so.

Also changes the error returned when we cannot create a `WSLASessionManager` and WSL is installed at a version below the minimum for WSLC support.
2026-03-31 15:51:21 -07:00
Kevin Vega
ab316dbb71 Change RegistryAuthenticationInformation to optional string (#40053) 2026-03-31 22:40:09 +00:00
AmirMS
103fd28126 [CLI] Add initial support for image saving feature (#14557)
* Initial support for image save

* Added e2e tests

* Added session option

* Clang format

* Clang format

* Addressed comments

* CLang format
2026-03-31 20:10:01 +00:00
Blue
fb98950eff Localization change from build: 143374899 (#40049)
Co-authored-by: WSL localization <noreply@microsoft.com>
2026-03-31 19:14:19 +00:00
Kevin Vega
42e97b63bf Fix a race in container start -a for short-lived containers. (#14558) 2026-03-31 12:12:40 -07:00
Blue
37a5a99d9d Implement WSLAContainer::Kill() (#14560)
* Implement WSLAContainer::Kill()

* Add test coverage

* Format

* Apply PR feedback
2026-03-31 12:06:55 -07:00
Blue
832b0f7b50 Update wslc build to look for Containerfile and Dockerfile (#40045)
* Save state

* Add test coverage

* Rename method

* Require input handle in the service

* Apply PR feedback

* Format

* Apply PR feedback + update tests

* Format
2026-03-31 11:40:11 -07:00
Ben Hillis
ae3563ff60 Validate empty host path in VolumeMount::Parse (#40031)
* Validate empty host path in VolumeMount::Parse

When parsing volume mount specs without a mode suffix (e.g. ':container'),
the host path validation was skipped, producing a VolumeMount with an empty
host path. This would propagate to MountWindowsFolder('') and produce a
confusing error.

Add validation after computing m_hostPath to reject empty host paths with
a clear error message in all cases.

* add test coverage

---------

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
2026-03-31 18:00:33 +00:00
Ben Hillis
90bb5c1538 wslc: fix TOCTOU race in cached COM wrapper getters (#40039)
GetState/GetInitProcess/GetId/GetName could race with DisconnectComWrapper:
the cache check saw empty, then disconnect populated the cache and nulled
the impl, so the forwarded call failed with RPC_E_DISCONNECTED even though
the cached value was now available.

Fix by removing the upfront cache check and instead calling through to the
impl first. If the call fails with RPC_E_DISCONNECTED, fall back to the
cache which DisconnectComWrapper guarantees is populated.

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
2026-03-31 10:29:19 -07:00
Ben Hillis
8c93f27bd4 wslc: enable virtiofs by default for wslc.exe and wslcsdk (#14559)
Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
2026-03-31 04:25:47 +00:00
John Stephens
dc7ec8f442 Add cancellation to image build (#14453) 2026-03-30 18:27:24 -07:00
AmirMS
6ae762d838 Remove options that are not yet implemented (#40044) 2026-03-31 00:03:13 +00:00
David Bennett
476c7666d7 CLI: Implement --session argument and session targeting (#14368) 2026-03-30 23:04:27 +00:00
Ben Hillis
b17dd02b86 Clean up Docker container on Create() failure (#40034)
* Clean up Docker container on Create() failure

If InspectContainer or the WSLCContainerImpl constructor throws after
CreateContainer succeeds, the Docker container is permanently orphaned
with no way to manage it through WSLC APIs.

Add a scope_exit to delete the Docker container on failure, released
on success.

* pr feedback (capture by value)

---------

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
2026-03-30 22:44:44 +00:00
Ben Hillis
8ed886b293 Fix deadlock between WatchForExitedProcesses and VMProcessControl destructor (#14567)
Use weak_ptr in m_trackedProcesses so WatchForExitedProcesses can safely
lock a reference and call OnExited() outside m_trackedProcessesLock.

weak_ptr avoids a circular reference: the vector no longer prevents
VMProcessControl destruction, so the destructor's OnProcessReleased
cleanup runs normally. Expired entries are also pruned in OnProcessReleased.

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
2026-03-30 15:32:19 -07:00
Ben Hillis
103d3dac3b Fix partial write data loss in TTY stdin relay (#40032)
When the TtyMaster fd is non-blocking, write() can return fewer bytes than
requested (partial write). The existing code only handled the EAGAIN/EWOULDBLOCK
case by buffering into pendingStdin, but silently dropped data on successful
partial writes.

Add handling for 0 < bytesWritten < bytesRead to buffer the unwritten bytes
into pendingStdin, matching the existing retry logic.

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
2026-03-30 14:20:09 -07:00
yao-msft
9c978e2b64 Add networking mode setting as fallback (#14564) 2026-03-30 13:13:06 -07:00
Ben Hillis
68055596ee Reject port mappings exceeding 63-port limit in relay (#40035)
WaitForMultipleObjects has a 64-handle limit. The accept thread uses
1 handle for the exit event, leaving room for 63 port mappings.

Reject new port mappings with ERROR_TOO_MANY_OPEN_FILES when the limit
is reached, rather than crashing the relay thread. Existing mappings
continue to work.

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
2026-03-30 13:00:35 -07:00
Ben Hillis
57194b0aa3 wslc: resolve ContainerRecoveryFromStorage test issue by storing timestamp from docker, not the host (#40038)
Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
2026-03-30 12:41:54 -07:00
Ben Hillis
ea7f824696 Fix Content-Length truncation for Docker responses >4GB (#40033)
std::stoul returns unsigned long (32-bit on Windows), truncating Content-Length
values >4GB. This corrupts the socket stream for large image save/export
operations.

Replace with std::stoull to parse as 64-bit unsigned.

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
2026-03-30 12:40:33 -07:00
Ben Hillis
ba98703ca2 Fix wrong enum type in DeleteExclusiveLockHeld (#40030)
WSLCDeleteImageFlagsForce (from WSLCDeleteImageFlags enum) was used instead
of WSLCDeleteFlagsForce (from WSLCDeleteFlags enum). Both values are currently
1, so no functional issue today, but this is a type confusion that will break
silently if either enum changes.

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
2026-03-30 12:40:24 -07:00