mirror of https://github.com/BOINC/boinc.git
Client: add some error reporting to WSL detection
This commit is contained in:
parent
e33ffbd637
commit
bc504f4f4d
|
@ -48,6 +48,7 @@ int get_all_distros(WSL_DISTROS& distros) {
|
|||
lxss_path.c_str(), 0, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, &hKey
|
||||
);
|
||||
if (lRet != ERROR_SUCCESS) {
|
||||
msg_printf(0, MSG_INFO, "WSL: registry open failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -59,6 +60,7 @@ int get_all_distros(WSL_DISTROS& distros) {
|
|||
(LPBYTE)default_wsl_guid, &default_wsl_guid_len
|
||||
);
|
||||
if ((lRet != ERROR_SUCCESS) || (default_wsl_guid_len > buf_len)) {
|
||||
msg_printf(0, MSG_INFO, "WSL: registry query failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -179,10 +181,12 @@ int get_wsl_information(WSL_DISTROS &distros) {
|
|||
WSL_DISTROS all_distros;
|
||||
int retval = get_all_distros(all_distros);
|
||||
if (retval) return retval;
|
||||
string err_msg;
|
||||
|
||||
WSL_CMD rs;
|
||||
|
||||
if (rs.setup()) {
|
||||
if (rs.setup(err_msg)) {
|
||||
msg_printf(0, MSG_INFO, "WSL setup error: %s", err_msg.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -199,7 +199,7 @@ typedef HRESULT(WINAPI *PWslLaunch)(
|
|||
static PWslLaunch pWslLaunch = NULL;
|
||||
static HINSTANCE wsl_lib = NULL;
|
||||
|
||||
int WSL_CMD::setup() {
|
||||
int WSL_CMD::setup(string &err_msg) {
|
||||
in_read = NULL;
|
||||
in_write = NULL;
|
||||
out_read = NULL;
|
||||
|
@ -207,9 +207,15 @@ int WSL_CMD::setup() {
|
|||
|
||||
if (!pWslLaunch) {
|
||||
wsl_lib = LoadLibraryA("wslapi.dll");
|
||||
if (!wsl_lib) return -1;
|
||||
if (!wsl_lib) {
|
||||
err_msg = "Can't load wslapi.dll");
|
||||
return -1;
|
||||
}
|
||||
pWslLaunch = (PWslLaunch)GetProcAddress(wsl_lib, "WslLaunch");
|
||||
if (!pWslLaunch) return -1;
|
||||
if (!pWslLaunch) {
|
||||
err_msg = "WslLaunch not in wslapi.dll");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
SECURITY_ATTRIBUTES sa;
|
||||
|
@ -217,10 +223,22 @@ int WSL_CMD::setup() {
|
|||
sa.bInheritHandle = TRUE;
|
||||
sa.lpSecurityDescriptor = NULL;
|
||||
|
||||
if (!CreatePipe(&out_read, &out_write, &sa, 0)) return -1;
|
||||
if (!SetHandleInformation(out_read, HANDLE_FLAG_INHERIT, 0)) return -1;
|
||||
if (!CreatePipe(&in_read, &in_write, &sa, 0)) return -1;
|
||||
if (!SetHandleInformation(in_write, HANDLE_FLAG_INHERIT, 0)) return -1;
|
||||
if (!CreatePipe(&out_read, &out_write, &sa, 0)) {
|
||||
err_msg = "Can't create out pipe");
|
||||
return -1;
|
||||
}
|
||||
if (!SetHandleInformation(out_read, HANDLE_FLAG_INHERIT, 0)) {
|
||||
err_msg = "Can't inherit out pipe");
|
||||
return -1;
|
||||
}
|
||||
if (!CreatePipe(&in_read, &in_write, &sa, 0)) {
|
||||
err_msg = "Can't create in pipe");
|
||||
return -1;
|
||||
}
|
||||
if (!SetHandleInformation(in_write, HANDLE_FLAG_INHERIT, 0)) {
|
||||
err_msg = "Can't inherit in pipe");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ struct WSL_CMD {
|
|||
// Use WslLaunch() to run a shell in the WSL container
|
||||
// The shell will run as the default user
|
||||
//
|
||||
int setup();
|
||||
int setup(std::string&);
|
||||
|
||||
// Use wsl.exe to run a shell as root in the WSL container
|
||||
//
|
||||
|
|
Loading…
Reference in New Issue