diff --git a/msipackage/CMakeLists.txt b/msipackage/CMakeLists.txt index 6996387..cc011a9 100644 --- a/msipackage/CMakeLists.txt +++ b/msipackage/CMakeLists.txt @@ -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 diff --git a/src/windows/wsladiag/wsladiag.cpp b/src/windows/wsladiag/wsladiag.cpp index a386443..e09ad0d 100644 --- a/src/windows/wsladiag/wsladiag.cpp +++ b/src/windows/wsladiag/wsladiag.cpp @@ -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); } } diff --git a/src/windows/wslaservice/exe/WSLASession.cpp b/src/windows/wslaservice/exe/WSLASession.cpp index cf7192a..bf43226 100644 --- a/src/windows/wslaservice/exe/WSLASession.cpp +++ b/src/windows/wslaservice/exe/WSLASession.cpp @@ -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) { diff --git a/src/windows/wslaservice/exe/WSLASession.h b/src/windows/wslaservice/exe/WSLASession.h index 67325fa..f34faa4 100644 --- a/src/windows/wslaservice/exe/WSLASession.h +++ b/src/windows/wslaservice/exe/WSLASession.h @@ -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; diff --git a/src/windows/wslaservice/exe/WSLAUserSession.cpp b/src/windows/wslaservice/exe/WSLAUserSession.cpp index 079e1b2..093fd7f 100644 --- a/src/windows/wslaservice/exe/WSLAUserSession.cpp +++ b/src/windows/wslaservice/exe/WSLAUserSession.cpp @@ -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(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(m_sessions.size()); return S_OK; - } wsl::windows::service::wsla::WSLAUserSession::WSLAUserSession(std::weak_ptr&& Session) : @@ -138,7 +134,7 @@ try { return E_INVALIDARG; } - + auto session = m_session.lock(); RETURN_HR_IF(RPC_E_DISCONNECTED, !session); diff --git a/src/windows/wslaservice/exe/WSLAUserSession.h b/src/windows/wslaservice/exe/WSLAUserSession.h index 786e40f..ce9894a 100644 --- a/src/windows/wslaservice/exe/WSLAUserSession.h +++ b/src/windows/wslaservice/exe/WSLAUserSession.h @@ -17,6 +17,8 @@ Abstract: #include "WSLASession.h" #include #include +#include +#include namespace wsl::windows::service::wsla { @@ -42,7 +44,7 @@ private: std::atomic 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 m_sessions; };