Fix formatting and whitespace issues in WSLA and wsladiag sources

This commit is contained in:
Beena352 2025-12-03 18:54:48 -08:00
parent 650e460d4a
commit 4d0492ae58
6 changed files with 33 additions and 31 deletions

View File

@ -47,7 +47,7 @@ endif()
set_source_files_properties(${OUTPUT_PACKAGE} PROPERTIES GENERATED TRUE)
if (DEFINED WSL_POST_BUILD_COMMAND)
if (DEFINED WSL_POST_BUILD_COMMAND AND NOT "${WSL_POST_BUILD_COMMAND}" STREQUAL "")
add_custom_command(
TARGET msipackage
POST_BUILD

View File

@ -1,9 +1,15 @@
/*++
/*++
Copyright (c) Microsoft. All rights reserved.
Module Name:
main.cpp
wsladiag.cpp
Abstract:
Entry point for the wsladiag tool, performs WSL runtime initialization and parses --list/--help.
TODO
--*/
#include "precomp.h"
@ -89,10 +95,10 @@ int wsladiag_main(std::wstring_view commandLine)
wslutil::PrintMessage(L"ID\tCreator PID\tDisplay Name\n", stdout);
wslutil::PrintMessage(L"--\t-----------\t------------\n", stdout);
for (const auto& session : sessions)
for (const auto& session : sessions)
{
const auto* displayName = session.DisplayName;
wslutil::PrintMessage(std::format(L"{}\t{}\t\t{}\n", session.SessionId, session.CreatorPid, displayName), stdout);
}
}

View File

@ -20,11 +20,7 @@ Abstract:
using wsl::windows::service::wsla::WSLASession;
WSLASession::WSLASession(
ULONG id,
const WSLA_SESSION_SETTINGS& Settings,
WSLAUserSessionImpl& userSessionImpl,
const VIRTUAL_MACHINE_SETTINGS& VmSettings) :
WSLASession::WSLASession(ULONG id, const WSLA_SESSION_SETTINGS& Settings, WSLAUserSessionImpl& userSessionImpl, const VIRTUAL_MACHINE_SETTINGS& VmSettings) :
m_id(id),
m_sessionSettings(Settings),
@ -60,18 +56,16 @@ WSLASession::~WSLASession()
}
}
void WSLASession::CopyDisplayName(
_Out_writes_z_(bufferLength) PWSTR buffer,
size_t bufferLength) const
void WSLASession::CopyDisplayName(_Out_writes_z_(bufferLength) PWSTR buffer, size_t bufferLength) const
{
THROW_HR_IF(E_BOUNDS, m_displayName.size() + 1 > bufferLength);
wcscpy_s(buffer, bufferLength, m_displayName.c_str());
}
const std::wstring& WSLASession::DisplayName() const
/** const std::wstring& WSLASession::DisplayName() const
{
return m_displayName;
}
return m_displayName;
}*/
HRESULT WSLASession::PullImage(LPCWSTR Image, const WSLA_REGISTRY_AUTHENTICATION_INFORMATION* RegistryInformation, IProgressCallback* ProgressCallback)
{

View File

@ -30,9 +30,13 @@ public:
{
return m_id;
}
void CopyDisplayName(
_Out_writes_z_(bufferLength) PWSTR buffer,
size_t bufferLength) const;
const std::wstring& GetDisplayName() const noexcept
{
return m_displayName;
}
void CopyDisplayName(_Out_writes_z_(bufferLength) PWSTR buffer, size_t bufferLength) const;
// Image management.
IFACEMETHOD(PullImage)(_In_ LPCWSTR Image, _In_ const WSLA_REGISTRY_AUTHENTICATION_INFORMATION* RegistryInformation, _In_ IProgressCallback* ProgressCallback) override;

View File

@ -54,7 +54,6 @@ HRESULT WSLAUserSessionImpl::CreateSession(const WSLA_SESSION_SETTINGS* Settings
{
std::lock_guard lock(m_lock);
m_sessions.emplace(session.Get());
}
// Client now owns the session.
@ -73,7 +72,7 @@ HRESULT WSLAUserSessionImpl::OpenSessionByName(LPCWSTR DisplayName, IWSLASession
// TODO: Check for duplicate on session creation.
for (auto& e : m_sessions)
{
if (e->DisplayName() == DisplayName)
if (e->GetDisplayName() == DisplayName)
{
THROW_IF_FAILED(e->QueryInterface(__uuidof(IWSLASession), (void**)Session));
return S_OK;
@ -81,9 +80,9 @@ HRESULT WSLAUserSessionImpl::OpenSessionByName(LPCWSTR DisplayName, IWSLASession
}
return HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
}
HRESULT wsl::windows::service::wsla::WSLAUserSessionImpl::ListSessions(
_Out_ WSLA_SESSION_INFORMATION** Sessions, _Out_ ULONG* SessionsCount)
HRESULT wsl::windows::service::wsla::WSLAUserSessionImpl::ListSessions(_Out_ WSLA_SESSION_INFORMATION** Sessions, _Out_ ULONG* SessionsCount)
{
std::lock_guard lock(m_lock);
auto output = wil::make_unique_cotaskmem<WSLA_SESSION_INFORMATION[]>(m_sessions.size());
@ -94,16 +93,13 @@ HRESULT wsl::windows::service::wsla::WSLAUserSessionImpl::ListSessions(
output[index].SessionId = session->GetId();
output[index].CreatorPid = 0; // placeholder until we populate this later
session->CopyDisplayName(
output[index].DisplayName,
_countof(output[index].DisplayName));
session->CopyDisplayName(output[index].DisplayName, _countof(output[index].DisplayName));
++index;
}
*Sessions = output.release();
*SessionsCount = static_cast<ULONG>(m_sessions.size());
return S_OK;
}
wsl::windows::service::wsla::WSLAUserSession::WSLAUserSession(std::weak_ptr<WSLAUserSessionImpl>&& Session) :
@ -138,7 +134,7 @@ try
{
return E_INVALIDARG;
}
auto session = m_session.lock();
RETURN_HR_IF(RPC_E_DISCONNECTED, !session);

View File

@ -17,6 +17,8 @@ Abstract:
#include "WSLASession.h"
#include <atomic>
#include <vector>
#include <mutex>
#include <unordered_set>
namespace wsl::windows::service::wsla {
@ -42,7 +44,7 @@ private:
std::atomic<ULONG> m_nextSessionId{1};
std::recursive_mutex m_lock;
// TODO-WSLA: Consider using a weak_ptr to easily destroy when the last client reference is released.
std::unordered_set<WSLASession*> m_sessions;
};