Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 4 additions & 39 deletions src/windows/wslcsession/WSLCContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,41 +306,8 @@ WSLCContainerNetworkType DockerNetworkModeToWSLCNetworkType(const std::string& m
std::uint64_t ParseDockerTimestamp(const std::string& timestamp)
{
// Docker timestamps are UTC ISO 8601, e.g. "2026-03-05T10:30:00.123456789Z".
// This function returns epoch seconds, so strip optional fractional seconds before parsing.
std::string normalizedTimestamp = timestamp;

const auto timeSeparator = normalizedTimestamp.find('T');
if (timeSeparator != std::string::npos)
{
const auto fractionalSeparator = normalizedTimestamp.find('.', timeSeparator + 1);
const auto zuluPos = normalizedTimestamp.find('Z', timeSeparator + 1);
const auto plusOffsetPos = normalizedTimestamp.find('+', timeSeparator + 1);
const auto minusOffsetPos = normalizedTimestamp.find('-', timeSeparator + 1);

auto timezonePos = std::string::npos;
if (zuluPos != std::string::npos)
{
timezonePos = zuluPos;
}
if (plusOffsetPos != std::string::npos && (timezonePos == std::string::npos || plusOffsetPos < timezonePos))
{
timezonePos = plusOffsetPos;
}
if (minusOffsetPos != std::string::npos && (timezonePos == std::string::npos || minusOffsetPos < timezonePos))
{
timezonePos = minusOffsetPos;
}

if (fractionalSeparator != std::string::npos && (timezonePos == std::string::npos || fractionalSeparator < timezonePos))
{
normalizedTimestamp.erase(
fractionalSeparator,
(timezonePos == std::string::npos) ? std::string::npos : (timezonePos - fractionalSeparator));
}
}

std::chrono::sys_seconds utcSeconds;
std::istringstream stream(normalizedTimestamp);
std::istringstream stream(timestamp);
stream >> std::chrono::parse("%FT%H:%M:%S%Z", utcSeconds);
THROW_HR_IF_MSG(E_INVALIDARG, stream.fail(), "Failed to parse timestamp '%hs'", timestamp.c_str());

Expand Down Expand Up @@ -858,9 +825,7 @@ void WSLCContainerImpl::Stop(WSLCSignal Signal, LONG TimeoutSeconds, bool Kill)

// Don't wait for the container to stop if we're not sending SIGKILL, since it may not stop the container.
// N.B. If the signal was SIGTERM for instance, we'll receive the stop notification via OnEvent().
// When Kill is true but the requested signal is not SIGKILL, do not wait synchronously for stop.
const bool isKillSignal = (SignalArg.value_or(WSLCSignalSIGKILL) == WSLCSignalSIGKILL);
const bool waitForStop = !Kill || isKillSignal;
bool waitForStop = !Kill || (SignalArg.value_or(WSLCSignalSIGKILL) == WSLCSignalSIGKILL);

try
{
Expand Down Expand Up @@ -1013,7 +978,7 @@ void WSLCContainerImpl::Export(WSLCHandle OutHandle) const
}

// Release the lock so the container can still be interacted with while the export is in progress.
// Past this point, no member variables can be accessed.
// Passed this point, no member variables can be accessed.
lock.reset();

io.Run({});
Expand Down Expand Up @@ -1830,7 +1795,7 @@ void WSLCContainerImpl::MapPorts()
if (!e.VmMapping.VmPort)
{
// Reuse existing vm port allocation when possible.
// This is required because the same container can bind the port number for different families or protocols.
// This is required because the same container can be bind the port number for different families or protocols.
auto existing = allocatedPorts.find(e.ContainerPort);
if (existing != allocatedPorts.end())
{
Expand Down
17 changes: 8 additions & 9 deletions src/windows/wslcsession/WSLCSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ using wsl::windows::service::wslc::WSLCVirtualMachine;

constexpr auto c_containerdStorage = "/var/lib/docker";
constexpr auto c_containerdSocket = "/run/containerd/containerd.sock";
constexpr auto c_dockerdReadyLogLine = "API listen on /var/run/docker.sock";
constexpr DWORD c_processTerminateTimeoutMs = 30 * 1000;
constexpr DWORD c_processKillTimeoutMs = 10 * 1000;

Expand All @@ -43,14 +42,12 @@ std::string IndentLines(const std::string& input, const std::string& prefix)
}

std::string result = prefix;
for (auto it = input.begin(); it != input.end(); ++it)
for (size_t i = 0; i < input.size(); i++)
{
result.push_back(*it);

const auto next = std::next(it);
if (next != input.end())
result.push_back(input[i]);
if (i + 1 < input.size())
{
if (*it == '\n' || (*it == '\r' && *next != '\n'))
if (input[i] == '\n' || (input[i] == '\r' && input[i + 1] != '\n'))
{
result.append(prefix);
}
Expand Down Expand Up @@ -426,6 +423,8 @@ try
return;
}

constexpr auto c_dockerdReadyLogLine = "API listen on /var/run/docker.sock";

std::string entry = {Buffer.begin(), Buffer.end()};
WSL_LOG(
"ContainerdLog",
Expand Down Expand Up @@ -766,7 +765,7 @@ try
}
};

constexpr auto c_logId = "log";
static constexpr char c_logId[] = "log";

auto flushLine = [&]() {
if (needsNewline)
Expand Down Expand Up @@ -1224,7 +1223,7 @@ try
CATCH_AND_THROW_DOCKER_USER_ERROR("Failed to list images");

// Compute the number of entries - one entry per tag, or one per image if no tags
auto entries = std::accumulate(images.begin(), images.end(), size_t{0}, [](auto sum, const auto& e) {
auto entries = std::accumulate<decltype(images.begin()), size_t>(images.begin(), images.end(), 0, [](auto sum, const auto& e) {
return sum + (e.RepoTags.empty() ? 1 : e.RepoTags.size());
});

Expand Down
12 changes: 4 additions & 8 deletions test/linux/unit_tests/lxtfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void LxtFsUtimeRoundToNt(struct timespec* Timespec);

//
// All real timestamps are offset from the year 2000 because FAT can only
// accept timestamps after 1980.
// accept timestamps afer 1980.

BASIC_TEST_CASE BasicTestCases[] = {
{{{FS_UNIX_TIME_2000 + 1111111, 2222222}, {FS_UNIX_TIME_2000 + 3333333, 4444444}},
Expand Down Expand Up @@ -231,7 +231,7 @@ Return Value:
}

snprintf(ExpectedOptions, sizeof(ExpectedOptions), "rw,%s", Options);
snprintf(ExpectedCombinedOptions, sizeof(ExpectedCombinedOptions), "rw,noatime,%s", Options);
snprintf(ExpectedCombinedOptions, sizeof(ExpectedOptions), "rw,noatime,%s", Options);

LxtCheckResult(MountCheckIsMount(Target, ParentId, Source, "drvfs", MountRoot, "rw,noatime", ExpectedOptions, ExpectedCombinedOptions, 0));
}
Expand Down Expand Up @@ -2056,7 +2056,7 @@ int LxtFsTestSetup(PLXT_ARGS Args, const char* TestDir, const char* DrvFsDir, bo
DrvFsDir - Supplies the DrvFs directory to use for testing. This must
start with a slash, and be relative from the root of the DrvFs mount.

UseDrvFs - Supplies a value indicating whether DrvFs is being used.
UseDrvFs - Supplies a pa value indicating whether DrvFs is being used.

Return Value:

Expand Down Expand Up @@ -2231,11 +2231,7 @@ Return Value:

if (LxtFsTimestampDiff(Timestamp1, Timestamp2) <= 0)
{
LxtLogError("Time %lld.%.9ld not greater than time %lld.%.9ld",
(long long)Timestamp1->tv_sec,
(long)Timestamp1->tv_nsec,
(long long)Timestamp2->tv_sec,
(long)Timestamp2->tv_nsec);
LxtLogError("Time %lld.%.9ld not greater than time %lld.%.9ld", Timestamp1, Timestamp2);

Result = LXT_RESULT_FAILURE;
goto ErrorExit;
Expand Down
8 changes: 1 addition & 7 deletions tools/setup-dev-env.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ else
}

$configPath = Join-Path $configDir $configFile
if (-not (Test-Path -LiteralPath $configPath -PathType Leaf))
{
Write-Host "Configuration file not found: $configPath" -ForegroundColor Red
Write-Host "Ensure the repository is fully checked out and the .config folder contains $configFile." -ForegroundColor Yellow
exit 1
}

# ── Run WinGet Configuration ────────────────────────────────────────
Write-Host ""
Expand All @@ -78,7 +72,7 @@ if ($LASTEXITCODE -ne 0)
winget configure -f "$configPath" --accept-configuration-agreements
if ($LASTEXITCODE -ne 0)
{
Write-Host "Failed to apply WinGet configuration file: $configPath" -ForegroundColor Red
Write-Host "Failed to apply WinGet configuration file: $configFile" -ForegroundColor Red
exit 1
}

Expand Down
6 changes: 3 additions & 3 deletions tools/test/run-tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
.PARAMETER TestDataPath
Path to test data folder. Defaults to ".\test_data".
.PARAMETER Package
Path to the wsl.msix package to install. Defaults to ".\installer.msix".
Path to the wsl.msix package to install. Defaults to ".\wsl.msix".
.PARAMETER UnitTestsPath
Path to the linux/unit_tests directory to copy and install the unit tests.
.PARAMETER PullRequest
Expand Down Expand Up @@ -103,9 +103,9 @@ if ($AttachDebugger)
else
{
te.exe $teArgList
if ($LASTEXITCODE -ne 0)
if (!$?)
{
exit $LASTEXITCODE
exit 1
}
}