Skip to content

Commit 81802e5

Browse files
hideyukn88Hideyuki Nagase
andauthored
add msrdc.exe path (#447)
* add msrdc.exe path * fix variable naming style Co-authored-by: Hideyuki Nagase <[email protected]>
1 parent e01ae4a commit 81802e5

File tree

1 file changed

+42
-28
lines changed

1 file changed

+42
-28
lines changed

WSLGd/main.cpp

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#define CONFIG_FILE ".wslgconfig"
88
#define SHARE_PATH "/mnt/wslg"
9+
#define MSRDC_EXE "msrdc.exe"
910

1011
constexpr auto c_serviceIdTemplate = "%08X-FACB-11E6-BD58-64006A7986D3";
1112
constexpr auto c_userName = "wslg";
@@ -34,6 +35,8 @@ constexpr auto c_installPathEnv = "WSL2_INSTALL_PATH";
3435
constexpr auto c_userProfileEnv = "WSL2_USER_PROFILE";
3536
constexpr auto c_systemDistroEnvSection = "system-distro-env";
3637

38+
constexpr auto c_mstsc_fullpath = "/mnt/c/Windows/System32/mstsc.exe";
39+
3740
constexpr auto c_westonShellOverrideEnv = "WSL2_WESTON_SHELL_OVERRIDE";
3841
constexpr auto c_westonRdprailShell = "rdprail-shell";
3942

@@ -140,9 +143,11 @@ try {
140143
}
141144

142145
// Query the WSL install path.
146+
bool isWslInstallPathEnvPresent = false;
143147
std::string wslInstallPath = "C:\\ProgramData\\Microsoft\\WSL";
144148
auto installPath = getenv(c_installPathEnv);
145149
if (installPath) {
150+
isWslInstallPathEnvPresent = true;
146151
wslInstallPath = installPath;
147152
}
148153

@@ -174,15 +179,15 @@ try {
174179
THROW_LAST_ERROR_IF(chown(c_xdgRuntimeDir, passwordEntry->pw_uid, passwordEntry->pw_gid) < 0);
175180

176181
// Attempt to mount the virtiofs share for shared memory.
177-
bool is_shared_memory_mounted = false;
182+
bool isSharedMemoryMounted = false;
178183
auto sharedMemoryObDirectoryPath = getenv(c_sharedMemoryObDirectoryPathEnv);
179184
if (sharedMemoryObDirectoryPath) {
180185
std::filesystem::create_directories(c_sharedMemoryMountPoint);
181186
if (mount("wslg", c_sharedMemoryMountPoint, "virtiofs", 0, "dax") < 0) {
182187
LOG_ERROR("Failed to mount wslg shared memory %s.", strerror(errno));
183188
} else {
184189
THROW_LAST_ERROR_IF(chmod(c_sharedMemoryMountPoint, 0777) < 0);
185-
is_shared_memory_mounted = true;
190+
isSharedMemoryMounted = true;
186191
}
187192
} else {
188193
LOG_ERROR("shared memory ob directory path is not set.");
@@ -260,38 +265,38 @@ try {
260265
}
261266

262267
// Set shared memory mount point to env when available.
263-
if (!is_shared_memory_mounted ||
268+
if (!isSharedMemoryMounted ||
264269
(setenv(c_sharedMemoryMountPointEnv, c_sharedMemoryMountPoint, true) < 0)) {
265270
// shared memory is not available, env must be cleared if it's set.
266271
THROW_LAST_ERROR_IF(unsetenv(c_sharedMemoryMountPointEnv) < 0);
267-
is_shared_memory_mounted = false;
272+
isSharedMemoryMounted = false;
268273
}
269274

270275
// Check if weston shell override is specified.
271276
// Otherwise, default shell is 'rdprail-shell'.
272-
bool is_rdprail_shell;
273-
std::string weston_shell_name;
274-
auto weston_shell_env = getenv(c_westonShellOverrideEnv);
275-
if (!weston_shell_env) {
276-
weston_shell_name = c_westonRdprailShell;
277-
is_rdprail_shell = true;
277+
bool isRdprailShell;
278+
std::string westonShellName;
279+
auto westonShellEnv = getenv(c_westonShellOverrideEnv);
280+
if (!westonShellEnv) {
281+
westonShellName = c_westonRdprailShell;
282+
isRdprailShell = true;
278283
} else {
279-
weston_shell_name = weston_shell_env;
280-
is_rdprail_shell = (weston_shell_name.compare(c_westonRdprailShell) == 0);
284+
westonShellName = westonShellEnv;
285+
isRdprailShell = (westonShellName.compare(c_westonRdprailShell) == 0);
281286
}
282287

283288
// Construct shell option string.
284-
std::string weston_shell_option("--shell=");
285-
weston_shell_option += weston_shell_name;
286-
weston_shell_option += ".so";
289+
std::string westonShellOption("--shell=");
290+
westonShellOption += westonShellName;
291+
westonShellOption += ".so";
287292

288293
// Construct logger option string.
289294
// By default, enable standard log and rdp-backend.
290-
std::string weston_logger_option("--logger-scopes=log,rdp-backend");
295+
std::string westonLoggerOption("--logger-scopes=log,rdp-backend");
291296
// If rdprail-shell is used, enable logger for that.
292-
if (is_rdprail_shell) {
293-
weston_logger_option += ",";
294-
weston_logger_option += c_westonRdprailShell;
297+
if (isRdprailShell) {
298+
westonLoggerOption += ",";
299+
westonLoggerOption += c_westonRdprailShell;
295300
}
296301

297302
// Launch weston.
@@ -300,33 +305,42 @@ try {
300305
"/usr/bin/weston",
301306
"--backend=rdp-backend.so",
302307
"--xwayland",
303-
std::move(weston_shell_option),
304-
std::move(weston_logger_option),
308+
std::move(westonShellOption),
309+
std::move(westonLoggerOption),
305310
"--log=" SHARE_PATH "/weston.log"
306311
},
307312
std::vector<cap_value_t>{CAP_SYS_ADMIN, CAP_SYS_CHROOT, CAP_SYS_PTRACE}
308313
);
309314

310-
// Launch the mstsc client.
315+
// Launch the mstsc/msrdc client.
311316
std::string remote("/v:");
312317
remote += vmId;
313318
std::string serviceId("/hvsocketserviceid:");
314319
serviceId += ToServiceId(address.svm_port);
315-
std::string shared_memory_ob_path("");
316-
if (is_shared_memory_mounted) {
317-
shared_memory_ob_path += "/wslgsharedmemorypath:";
318-
shared_memory_ob_path += sharedMemoryObDirectoryPath;
320+
std::string sharedMemoryObPath("");
321+
if (isSharedMemoryMounted) {
322+
sharedMemoryObPath += "/wslgsharedmemorypath:";
323+
sharedMemoryObPath += sharedMemoryObDirectoryPath;
319324
}
320325

326+
std::string rdpClientExePath = c_mstsc_fullpath;
327+
if (isWslInstallPathEnvPresent) {
328+
struct stat buffer;
329+
std::string msrdcExePath = TranslateWindowsPath(wslInstallPath.c_str());
330+
msrdcExePath += "/" MSRDC_EXE;
331+
if (stat(msrdcExePath.c_str(), &buffer) == 0) {
332+
rdpClientExePath = msrdcExePath;
333+
}
334+
}
321335
std::string rdpFilePath = wslInstallPath + "\\wslg.rdp";
322336
monitor.LaunchProcess(std::vector<std::string>{
323-
"/mnt/c/Windows/System32/mstsc.exe",
337+
std::move(rdpClientExePath),
324338
std::move(remote),
325339
std::move(serviceId),
326340
"/silent",
327341
"/wslg",
328342
"/plugin:WSLDVC",
329-
std::move(shared_memory_ob_path),
343+
std::move(sharedMemoryObPath),
330344
std::move(rdpFilePath)
331345
});
332346

0 commit comments

Comments
 (0)