@@ -199,28 +199,46 @@ typedef HRESULT(WINAPI *PWslLaunch)(
199199static PWslLaunch pWslLaunch = NULL ;
200200static 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
0 commit comments