@@ -19,8 +19,6 @@ Module Name:
1919#include " Distribution.h"
2020#include " CommandLine.h"
2121#include < conio.h>
22- #include " wslc.h"
23- #include " WSLCProcessLauncher.h"
2422#include " WslCoreFilesystem.h"
2523
2624#define BASH_PATH L" /bin/bash"
@@ -30,7 +28,6 @@ using winrt::Windows::Management::Deployment::DeploymentOptions;
3028using wsl::shared::Localization;
3129using wsl::windows::common::ClientExecutionContext;
3230using wsl::windows::common::Context;
33- using wsl::windows::common::WSLCProcessLauncher;
3431using namespace wsl ::windows::common;
3532using namespace wsl ::shared;
3633using namespace wsl ::windows::common::distribution;
@@ -1521,191 +1518,6 @@ int RunDebugShell()
15211518 THROW_HR (HCS_E_CONNECTION_CLOSED);
15221519}
15231520
1524- DEFINE_ENUM_FLAG_OPERATORS (WSLCFeatureFlags);
1525-
1526- // Temporary debugging tool for WSLC
1527- int WslcShell (_In_ std::wstring_view commandLine)
1528- {
1529- WSLCSessionSettings sessionSettings{};
1530- sessionSettings.DisplayName = L" WSLCShell" ;
1531- sessionSettings.CpuCount = 4 ;
1532- sessionSettings.MemoryMb = 4096 ;
1533- sessionSettings.NetworkingMode = WSLCNetworkingModeVirtioProxy;
1534- sessionSettings.BootTimeoutMs = 30 * 1000 ;
1535- sessionSettings.MaximumStorageSizeMb = 4096 ;
1536-
1537- std::string shell = " /bin/bash" ;
1538- std::string cmd;
1539-
1540- bool help = false ;
1541- bool noTty = false ;
1542- std::wstring debugShell;
1543-
1544- std::wstring storagePath;
1545- std::wstring rootVhdOverride;
1546- std::string rootVhdTypeOverride;
1547- ArgumentParser parser (std::wstring{commandLine}, WSL_BINARY_NAME);
1548- parser.AddArgument (rootVhdOverride, L" --vhd" );
1549- parser.AddArgument (Utf8String (shell), L" --shell" );
1550- parser.AddArgument (SetFlag<WslcFeatureFlagsDnsTunneling>(sessionSettings.FeatureFlags ), L" --dns-tunneling" );
1551- parser.AddArgument (SetFlag<WslcFeatureFlagsVirtioFs>(sessionSettings.FeatureFlags ), L" --virtiofs" );
1552- parser.AddArgument (Integer (sessionSettings.MemoryMb ), L" --memory" );
1553- parser.AddArgument (Integer (sessionSettings.CpuCount ), L" --cpu" );
1554- parser.AddArgument (Utf8String (rootVhdTypeOverride), L" --fstype" );
1555- parser.AddArgument (storagePath, L" --storage" );
1556- parser.AddArgument (Integer (reinterpret_cast <int &>(sessionSettings.NetworkingMode )), L" --networking-mode" );
1557- parser.AddArgument (debugShell, L" --debug-shell" );
1558- parser.AddArgument (noTty, L" --no-tty" );
1559- parser.AddArgument (help, L" --help" );
1560- parser.Parse ();
1561-
1562- if (help)
1563- {
1564- const auto usage = std::format (
1565- LR"( {} --wslc [--vhd </path/to/vhd>] [--shell </path/to/shell>] [--memory <memory-mb>] [--cpu <cpus>] [--dns-tunneling] [--virtiofs] [--networking-mode <mode>] [--fstype <fstype>] [--container-vhd </path/to/vhd>] [--help])" ,
1566- WSL_BINARY_NAME);
1567-
1568- wprintf (L" %ls\n " , usage.c_str ());
1569- return 1 ;
1570- }
1571-
1572- switch (sessionSettings.NetworkingMode )
1573- {
1574- case WSLCNetworkingMode::WSLCNetworkingModeNone:
1575- case WSLCNetworkingMode::WSLCNetworkingModeNAT:
1576- case WSLCNetworkingMode::WSLCNetworkingModeVirtioProxy:
1577- break ;
1578- default :
1579- THROW_HR (E_INVALIDARG);
1580- }
1581-
1582- wil::com_ptr<IWSLCSessionManager> sessionManager;
1583- THROW_IF_FAILED (CoCreateInstance (__uuidof (WSLCSessionManager), nullptr , CLSCTX_LOCAL_SERVER, IID_PPV_ARGS (&sessionManager)));
1584- wsl::windows::common::security::ConfigureForCOMImpersonation (sessionManager.get ());
1585-
1586- wil::com_ptr<IWSLCSession> session;
1587-
1588- if (!rootVhdOverride.empty ())
1589- {
1590- if (rootVhdTypeOverride.empty ())
1591- {
1592- wprintf (L" --fstype required when --vhd is passed\n " );
1593- return 1 ;
1594- }
1595-
1596- sessionSettings.RootVhdOverride = rootVhdOverride.c_str ();
1597- sessionSettings.RootVhdTypeOverride = rootVhdTypeOverride.c_str ();
1598- }
1599-
1600- if (!storagePath.empty ())
1601- {
1602- storagePath = std::filesystem::weakly_canonical (storagePath).wstring ();
1603- sessionSettings.StoragePath = storagePath.c_str ();
1604- }
1605-
1606- if (!debugShell.empty ())
1607- {
1608- THROW_IF_FAILED (sessionManager->OpenSessionByName (debugShell.c_str (), &session));
1609- }
1610- else
1611- {
1612- THROW_IF_FAILED (sessionManager->CreateSession (&sessionSettings, WSLCSessionFlagsNone, &session));
1613- }
1614-
1615- wsl::windows::common::security::ConfigureForCOMImpersonation (session.get ());
1616-
1617- std::optional<wil::com_ptr<IWSLCContainer>> container;
1618- std::optional<wsl::windows::common::ClientRunningWSLCProcess> process;
1619- // Get the terminal size.
1620- HANDLE Stdout = GetStdHandle (STD_OUTPUT_HANDLE);
1621- HANDLE Stdin = GetStdHandle (STD_INPUT_HANDLE);
1622-
1623- CONSOLE_SCREEN_BUFFER_INFOEX Info{};
1624- Info.cbSize = sizeof (Info);
1625- THROW_IF_WIN32_BOOL_FALSE (::GetConsoleScreenBufferInfoEx (Stdout, &Info));
1626-
1627- wsl::windows::common::WSLCProcessLauncher launcher{shell, {shell, " --login" }, {" TERM=xterm-256color" }, WSLCProcessFlagsTty};
1628- launcher.SetTtySize (Info.srWindow .Bottom - Info.srWindow .Top + 1 , Info.srWindow .Right - Info.srWindow .Left + 1 );
1629-
1630- process = launcher.Launch (*session);
1631-
1632- if (noTty)
1633- {
1634- using namespace wsl ::windows::common::relay;
1635- wsl::windows::common::relay::MultiHandleWait io;
1636-
1637- // Create a thread to relay stdin to the pipe.
1638-
1639- std::thread inputThread;
1640- wil::unique_event exitEvent{wil::EventOptions::ManualReset};
1641-
1642- auto joinThread = wil::scope_exit_log (WI_DIAGNOSTICS_INFO, [&]() {
1643- if (inputThread.joinable ())
1644- {
1645- exitEvent.SetEvent ();
1646- inputThread.join ();
1647- }
1648- });
1649-
1650- // Required because ReadFile() blocks if stdin is a tty.
1651- if (wsl::windows::common::wslutil::IsInteractiveConsole ())
1652- {
1653- inputThread = std::thread{[&]() {
1654- wsl::windows::common::relay::StandardInputRelay (Stdin, process->GetStdHandle (0 ).get (), []() {}, exitEvent.get ());
1655- }};
1656- }
1657- else
1658- {
1659- io.AddHandle (std::make_unique<RelayHandle<ReadHandle>>(GetStdHandle (STD_INPUT_HANDLE), process->GetStdHandle (0 )));
1660- }
1661-
1662- io.AddHandle (std::make_unique<RelayHandle<ReadHandle>>(process->GetStdHandle (1 ), GetStdHandle (STD_OUTPUT_HANDLE)));
1663- io.AddHandle (std::make_unique<RelayHandle<ReadHandle>>(process->GetStdHandle (2 ), GetStdHandle (STD_ERROR_HANDLE)));
1664-
1665- io.Run ({});
1666- }
1667- else
1668- {
1669- // Configure console for interactive usage.
1670- wsl::windows::common::ConsoleState console;
1671- auto exitEvent = wil::unique_event (wil::EventOptions::ManualReset);
1672-
1673- std::vector<wil::unique_handle> handleStorage;
1674- HANDLE ttyInput = nullptr ;
1675- HANDLE ttyOutput = nullptr ;
1676- auto & it = handleStorage.emplace_back (process->GetStdHandle (WSLCFDTty));
1677- ttyInput = it.get ();
1678- ttyOutput = it.get ();
1679-
1680- {
1681- // Create a thread to relay stdin to the pipe.
1682- std::thread inputThread ([&]() {
1683- auto updateTerminal = [&console, &process]() {
1684- const auto windowSize = console.GetWindowSize ();
1685- LOG_IF_FAILED (process->Get ().ResizeTty (windowSize.Y , windowSize.X ));
1686- };
1687-
1688- wsl::windows::common::relay::StandardInputRelay (Stdin, ttyInput, updateTerminal, exitEvent.get ());
1689- });
1690-
1691- auto joinThread = wil::scope_exit_log (WI_DIAGNOSTICS_INFO, [&]() {
1692- exitEvent.SetEvent ();
1693- inputThread.join ();
1694- });
1695-
1696- // Relay the contents of the pipe to stdout.
1697- wsl::windows::common::relay::InterruptableRelay (ttyOutput, Stdout);
1698- }
1699- }
1700-
1701- process->GetExitEvent ().wait ();
1702-
1703- auto exitCode = process->GetExitCode ();
1704- wprintf (L" %hs exited with: %i" , shell.c_str (), exitCode);
1705-
1706- return exitCode;
1707- }
1708-
17091521int WslMain (_In_ std::wstring_view commandLine)
17101522{
17111523 // Call the MSI package if we're in an MSIX context
@@ -1948,10 +1760,6 @@ int WslMain(_In_ std::wstring_view commandLine)
19481760
19491761 return Uninstall ();
19501762 }
1951- else if (argument == L" --wslc" )
1952- {
1953- return WslcShell (commandLine);
1954- }
19551763 else
19561764 {
19571765 if ((argument.size () > 0 ) && (argument[0 ] == L' -' ))
0 commit comments