Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ add_subdirectory(src/windows/wslhost)
add_subdirectory(src/windows/wslrelay)
add_subdirectory(src/windows/wslinstall)
add_subdirectory(src/windows/wslaclient)
add_subdirectory(src/windows/wsladiag)

if (WSL_BUILD_WSL_SETTINGS)
add_subdirectory(src/windows/libwsl)
Expand Down
4 changes: 2 additions & 2 deletions msipackage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(OUTPUT_PACKAGE ${BIN}/wsl.msi)
set(PACKAGE_WIX_IN ${CMAKE_CURRENT_LIST_DIR}/package.wix.in)
set(PACKAGE_WIX ${BIN}/package.wix)
set(CAB_CACHE ${BIN}/cab)
set(BINARIES wsl.exe;wslg.exe;wslhost.exe;wslrelay.exe;wslservice.exe;wslserviceproxystub.dll;init;initrd.img;wslinstall.dll;wslaserviceproxystub.dll;wslaservice.exe)
set(BINARIES wsl.exe;wslg.exe;wslhost.exe;wslrelay.exe;wslservice.exe;wslserviceproxystub.dll;init;initrd.img;wslinstall.dll;wslaserviceproxystub.dll;wslaservice.exe;wsladiag.exe)

if (WSL_BUILD_WSL_SETTINGS)
list(APPEND BINARIES_DEPENDENCIES "wslsettings/wslsettings.dll;wslsettings/wslsettings.exe;libwsl.dll")
Expand Down Expand Up @@ -39,7 +39,7 @@ add_custom_command(

add_custom_target(msipackage DEPENDS ${OUTPUT_PACKAGE})
set_target_properties(msipackage PROPERTIES EXCLUDE_FROM_ALL FALSE SOURCES ${PACKAGE_WIX_IN})
add_dependencies(msipackage wsl wslg wslservice wslhost wslrelay wslserviceproxystub init initramfs wslinstall msixgluepackage wslaservice wslaserviceproxystub)
add_dependencies(msipackage wsl wslg wslservice wslhost wslrelay wslserviceproxystub init initramfs wslinstall msixgluepackage wslaservice wslaserviceproxystub wsladiag)

if (WSL_BUILD_WSL_SETTINGS)
add_dependencies(msipackage wslsettings libwsl)
Expand Down
1 change: 1 addition & 0 deletions msipackage/package.wix.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
</File>

<File Id="wslg.exe" Name="wslg.exe" Source="${BIN}/wslg.exe" />
<File Id="wsladiag.exe" Name="wsladiag.exe" Source="${BIN}/wsladiag.exe" />
<File Id="wslhost.exe" Name="wslhost.exe" Source="${BIN}/wslhost.exe" />
<File Id="wslrelay.exe" Name="wslrelay.exe" Source="${BIN}/wslrelay.exe" />
<File Id="wslserviceproxystub.dll" Name="wslserviceproxystub.dll" Source="${BIN}/wslserviceproxystub.dll" />
Expand Down
14 changes: 14 additions & 0 deletions src/windows/wsladiag/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
set(SOURCES
main.cpp
)

add_executable(wsladiag ${SOURCES})

target_link_libraries(wsladiag
${COMMON_LINK_LIBRARIES}
common
)

target_precompile_headers(wsladiag REUSE_FROM common)

set_target_properties(wsladiag PROPERTIES FOLDER windows)
101 changes: 101 additions & 0 deletions src/windows/wsladiag/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*++

Copyright (c) Microsoft. All rights reserved.

Module Name:

main.cpp

Abstract:

Entry point for the wsladiag tool, performs WSL runtime initialization and parses --list/--help.

--*/

#include "precomp.h"
#include "CommandLine.h"
#include "wslutil.h"

using namespace wsl::shared;
namespace wslutil = wsl::windows::common::wslutil;

int wsladiag_main(std::wstring_view commandLine)
{
//
// Standard process initialization (matches other WSL tools)
//
wslutil::ConfigureCrt();
wslutil::InitializeWil();

WslTraceLoggingInitialize(LxssTelemetryProvider, !wsl::shared::OfficialBuild);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OneBlue this seems like a strange provider to use here. Is there a more appropriate one?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good call.

The closest match we have is WslaServiceTelemetryProvider, (although the same isn't a great match). We could either rename that provider to WslaTelemetryProvider and use it here as well as in the service, or create another one specifically for wsladiag.exe.

I'd be OK with both, but I have a preference for the first option, since one telemetry provider just for wsldiag feels overkill

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I think we can just use a single provider for all of WSLA.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification! I agree using a single provider makes more sense. I went with the first option and renamed the existing WslaServiceTelemetryProvider to WslaTelemetryProvider, and updated both the service and wsladiag.exe to use it. Let me know if you'd like this split out differently.

auto cleanupTelemetry = wil::scope_exit_log(WI_DIAGNOSTICS_INFO, []()
{
WslTraceLoggingUninitialize();
});

wslutil::SetCrtEncoding(_O_U8TEXT);

auto coInit = wil::CoInitializeEx(COINIT_MULTITHREADED);
wslutil::CoInitializeSecurity();

WSADATA data{};
THROW_IF_WIN32_ERROR(WSAStartup(MAKEWORD(2, 2), &data));
auto wsaCleanup = wil::scope_exit_log(WI_DIAGNOSTICS_INFO, []()
{
WSACleanup();
});

//
// Command-line parsing using ArgumentParser
//
ArgumentParser parser(std::wstring{commandLine}, L"wsladiag");

bool help = false;
bool list = false;

parser.AddArgument(list, L"--list");
parser.AddArgument(help, L"--help", L'h'); // short option is a single wide char
parser.Parse();

auto printUsage = []()
{
wslutil::PrintMessage(
L"wsladiag - WSLA diagnostics tool\n"
L"Usage:\n"
L" wsladiag --list List WSLA sessions\n"
L" wsladiag --help Show this help",
stdout);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Other WSL processes currently write help messages to stdout, but since this is a new executable I think we should do the right thing and write message like this on stderr instead

};

// Slightly clearer help logic
if (help)
{
printUsage();
return 0;
}

if (!list)
{
// No recognized command → show usage
printUsage();
return 0;
}

// --list
wslutil::PrintMessage(
L"[wsladiag] --list: placeholder.\n"
L"Next step: call WSLA service ListSessions and display sessions.",
stdout);
// TODO: call WSLA service COM interface to retrieve and display sessions.
return 0;
}

int wmain(int /*argc*/, wchar_t** /*argv*/)
{
try
{
// Use the full command line so ArgumentParser sees the raw string
return wsladiag_main(GetCommandLineW());
}
CATCH_RETURN();
}
12 changes: 11 additions & 1 deletion src/windows/wslaservice/exe/WSLAUserSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,18 @@ CATCH_RETURN();

HRESULT wsl::windows::service::wsla::WSLAUserSession::ListSessions(WSLA_SESSION_INFORMATION** Sessions, ULONG* SessionsCount)
{
return E_NOTIMPL;
if (!Sessions || !SessionsCount)
{
return E_INVALIDARG;
}

// For now, return an empty list. We'll populate this from m_sessions later.
*Sessions = nullptr;
*SessionsCount = 0;

return S_OK;
}

HRESULT wsl::windows::service::wsla::WSLAUserSession::OpenSession(ULONG Id, IWSLASession** Session)
{
return E_NOTIMPL;
Expand Down
Loading