Skip to content

Commit a97c1af

Browse files
authored
Merge pull request #5973 from BOINC/dpa_wsl7
Client: add some error reporting to WSL detection
2 parents b4284da + 104e3be commit a97c1af

5 files changed

Lines changed: 38 additions & 14 deletions

File tree

‎client/hostinfo_wsl.cpp‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ int get_all_distros(WSL_DISTROS& distros) {
4848
lxss_path.c_str(), 0, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, &hKey
4949
);
5050
if (lRet != ERROR_SUCCESS) {
51+
msg_printf(0, MSG_INFO, "WSL: registry open failed");
5152
return -1;
5253
}
5354

@@ -59,6 +60,7 @@ int get_all_distros(WSL_DISTROS& distros) {
5960
(LPBYTE)default_wsl_guid, &default_wsl_guid_len
6061
);
6162
if ((lRet != ERROR_SUCCESS) || (default_wsl_guid_len > buf_len)) {
63+
msg_printf(0, MSG_INFO, "WSL: registry query failed");
6264
return -1;
6365
}
6466

@@ -179,10 +181,12 @@ int get_wsl_information(WSL_DISTROS &distros) {
179181
WSL_DISTROS all_distros;
180182
int retval = get_all_distros(all_distros);
181183
if (retval) return retval;
184+
string err_msg;
182185

183186
WSL_CMD rs;
184187

185-
if (rs.setup()) {
188+
if (rs.setup(err_msg)) {
189+
msg_printf(0, MSG_INFO, "WSL setup error: %s", err_msg.c_str());
186190
return -1;
187191
}
188192

‎lib/util.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,9 +704,10 @@ string parse_ldd_libc(const char* input) {
704704

705705
#ifdef _WIN32
706706
int DOCKER_CONN::init(DOCKER_TYPE docker_type, string distro_name, bool _verbose) {
707+
string err_msg;
707708
cli_prog = docker_cli_prog(docker_type);
708709
if (docker_type == DOCKER) {
709-
int retval = ctl_wc.setup();
710+
int retval = ctl_wc.setup(err_msg);
710711
if (retval) return retval;
711712
retval = ctl_wc.run_program_in_wsl(distro_name, "", true);
712713
if (retval) return retval;

‎lib/win_util.cpp‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,28 +199,46 @@ typedef HRESULT(WINAPI *PWslLaunch)(
199199
static PWslLaunch pWslLaunch = NULL;
200200
static HINSTANCE wsl_lib = NULL;
201201

202-
int WSL_CMD::setup() {
202+
int WSL_CMD::setup(string &err_msg) {
203203
in_read = NULL;
204204
in_write = NULL;
205205
out_read = NULL;
206206
out_write = NULL;
207207

208208
if (!pWslLaunch) {
209209
wsl_lib = LoadLibraryA("wslapi.dll");
210-
if (!wsl_lib) return -1;
210+
if (!wsl_lib) {
211+
err_msg = "Can't load wslapi.dll";
212+
return -1;
213+
}
211214
pWslLaunch = (PWslLaunch)GetProcAddress(wsl_lib, "WslLaunch");
212-
if (!pWslLaunch) return -1;
215+
if (!pWslLaunch) {
216+
err_msg = "WslLaunch not in wslapi.dll";
217+
return -1;
218+
}
213219
}
214220

215221
SECURITY_ATTRIBUTES sa;
216222
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
217223
sa.bInheritHandle = TRUE;
218224
sa.lpSecurityDescriptor = NULL;
219225

220-
if (!CreatePipe(&out_read, &out_write, &sa, 0)) return -1;
221-
if (!SetHandleInformation(out_read, HANDLE_FLAG_INHERIT, 0)) return -1;
222-
if (!CreatePipe(&in_read, &in_write, &sa, 0)) return -1;
223-
if (!SetHandleInformation(in_write, HANDLE_FLAG_INHERIT, 0)) return -1;
226+
if (!CreatePipe(&out_read, &out_write, &sa, 0)) {
227+
err_msg = "Can't create out pipe";
228+
return -1;
229+
}
230+
if (!SetHandleInformation(out_read, HANDLE_FLAG_INHERIT, 0)) {
231+
err_msg = "Can't inherit out pipe";
232+
return -1;
233+
}
234+
if (!CreatePipe(&in_read, &in_write, &sa, 0)) {
235+
err_msg = "Can't create in pipe";
236+
return -1;
237+
}
238+
if (!SetHandleInformation(in_write, HANDLE_FLAG_INHERIT, 0)) {
239+
err_msg = "Can't inherit in pipe";
240+
return -1;
241+
}
224242
return 0;
225243
}
226244

‎lib/win_util.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct WSL_CMD {
5353
// Use WslLaunch() to run a shell in the WSL container
5454
// The shell will run as the default user
5555
//
56-
int setup();
56+
int setup(std::string&);
5757

5858
// Use wsl.exe to run a shell as root in the WSL container
5959
//

‎samples/wsl_wrapper/wsl_wrapper.cpp‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,10 @@ int error(const char* where, int retval) {
9797
//
9898
int launch(const char* distro, const char* cmd) {
9999
char launch_cmd[256];
100+
string err_msg;
100101
sprintf(launch_cmd, "echo $$; %s; touch boinc_job_done\n", cmd);
101-
int retval = app_wc.setup();
102-
if (retval) return error("app setup", retval);
102+
int retval = app_wc.setup(err_msg);
103+
if (retval) return error(err_msg.c_str(), retval);
103104
retval = app_wc.run_program_in_wsl(distro, launch_cmd, true);
104105
if (retval) return error("app run_program_in_wsl", retval);
105106

@@ -117,8 +118,8 @@ int launch(const char* distro, const char* cmd) {
117118

118119
// set up control channel
119120
//
120-
retval = ctl_wc.setup();
121-
if (retval) return error("ctl setup", retval);
121+
retval = ctl_wc.setup(err_msg);
122+
if (retval) return error(err_msg.c_str(), retval);
122123
retval = ctl_wc.run_program_in_wsl(distro, "", true);
123124
// empty string means run shell
124125
if (retval) return error("ctl run_program_in_wsl", retval);

0 commit comments

Comments
 (0)