From 4a1e0f467be79a904d36745e59a5a3bef232cc02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B6rn=20Svensson?= Date: Fri, 3 Jun 2022 07:14:55 +0200 Subject: [PATCH] Bug 580113: Expose concurrent invocations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The class CommandLauncher holds an internal state of the process and it's command line. To avoid corrupting the internal state, only allow executing new commands if the previous command is finished. Contributed by STMicroelectronics Change-Id: If41816f6b642953776a4fea3df9f341a17712222 Signed-off-by: Torbjörn Svensson --- .../src/org/eclipse/cdt/core/CommandLauncher.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java index ed4c45059d7..f8d0a66c074 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java @@ -16,6 +16,8 @@ package org.eclipse.cdt.core; import java.io.File; import java.io.IOException; import java.io.OutputStream; +import java.util.Arrays; +import java.util.ConcurrentModificationException; import java.util.Properties; import org.eclipse.cdt.internal.core.Cygwin; @@ -161,6 +163,17 @@ public class CommandLauncher implements ICommandLauncher { @Override public Process execute(IPath commandPath, String[] args, String[] env, IPath workingDirectory, IProgressMonitor monitor) throws CoreException { + + // Ensure that previous command has finished before launching next. + if (fProcess != null && fProcess.isAlive()) { + String command = "(unknown)"; //$NON-NLS-1$ + if (fCommandArgs != null) { + command = Arrays.asList(fCommandArgs).toString(); + } + throw new ConcurrentModificationException( + NLS.bind("Process for command \"{0}\" is still executing.", command)); //$NON-NLS-1$ + } + parseEnvironment(env); String envPathValue = getEnvironmentProperty(PATH_ENV);