From 0cd0aa1270ffcf8ff88c875a5d99fc7edd4d829c Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Tue, 24 Aug 2021 12:39:15 -0400 Subject: [PATCH] Bug 575159: Consider return code of wsl.exe If the return code is non-zero wsl may have failed in someway, with recent changes in Windows, wsl.exe is present even when wsl is not installed. In that case wsl.exe is a dummy that can be used to install wsl. Change-Id: I83af60623084e1364d16c3a1739bc4f6a25ac3a9 --- .../view/ui/local/showin/detectors/DetectWSL.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/local/showin/detectors/DetectWSL.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/local/showin/detectors/DetectWSL.java index 0f1300b1c95..8d98d53f786 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/local/showin/detectors/DetectWSL.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/local/showin/detectors/DetectWSL.java @@ -144,6 +144,18 @@ public class DetectWSL implements IDetectExternalExecutable { } } + try { + // lets get the return code to make sure that the process did not produce anything unexpected. As the streams + // are closed, the waitFor shouldn't block. + if (process.waitFor() != 0) { + // WSL can send errors to stdout, so discard results if the exit value ends up being non-zero + result.clear(); + } + } catch (InterruptedException e) { + // we've been interrupted, give up on the output we have (probably unreachable in practice) + result.clear(); + } + } catch (IOException e) { } }