mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-03 22:35:43 +02:00
Bug 574131: Make the graceful exit time configurable
Contributed by STMicroelectronics Change-Id: I8ca32b2440ef1cc81bf5b9ddd70b6b4222a29261 Signed-off-by: Torbjörn Svensson <torbjorn.svensson@st.com>
This commit is contained in:
parent
8db32cb918
commit
994ea12856
2 changed files with 92 additions and 2 deletions
|
@ -76,6 +76,16 @@ public class ProcessFactory {
|
|||
return runtime.exec(cmdarray);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 6.2
|
||||
*/
|
||||
public Process exec(String[] cmdarray, int gracefulExitTimeMs) throws IOException {
|
||||
cmdarray = modifyCmdArrayIfFlatpak(cmdarray);
|
||||
if (hasSpawner)
|
||||
return new Spawner(cmdarray, gracefulExitTimeMs);
|
||||
return runtime.exec(cmdarray);
|
||||
}
|
||||
|
||||
public Process exec(String[] cmdarray, String[] envp) throws IOException {
|
||||
cmdarray = modifyCmdArrayIfFlatpak(cmdarray);
|
||||
if (hasSpawner)
|
||||
|
@ -83,6 +93,16 @@ public class ProcessFactory {
|
|||
return runtime.exec(cmdarray, envp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 6.2
|
||||
*/
|
||||
public Process exec(String[] cmdarray, String[] envp, int gracefulExitTimeMs) throws IOException {
|
||||
cmdarray = modifyCmdArrayIfFlatpak(cmdarray);
|
||||
if (hasSpawner)
|
||||
return new Spawner(cmdarray, envp, gracefulExitTimeMs);
|
||||
return runtime.exec(cmdarray, envp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Do not use this method it splits command line arguments on whitespace with no regard to quoting rules. See Bug 573677
|
||||
*/
|
||||
|
@ -112,6 +132,16 @@ public class ProcessFactory {
|
|||
return runtime.exec(cmdarray, envp, dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 6.2
|
||||
*/
|
||||
public Process exec(String cmdarray[], String[] envp, File dir, int gracefulExitTimeMs) throws IOException {
|
||||
cmdarray = modifyCmdArrayIfFlatpak(cmdarray);
|
||||
if (hasSpawner)
|
||||
return new Spawner(cmdarray, envp, dir, gracefulExitTimeMs);
|
||||
return runtime.exec(cmdarray, envp, dir);
|
||||
}
|
||||
|
||||
public Process exec(String cmdarray[], String[] envp, File dir, PTY pty) throws IOException {
|
||||
cmdarray = modifyCmdArrayIfFlatpak(cmdarray);
|
||||
if (hasSpawner)
|
||||
|
@ -119,6 +149,17 @@ public class ProcessFactory {
|
|||
throw new UnsupportedOperationException(Messages.Util_exception_cannotCreatePty);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 6.2
|
||||
*/
|
||||
public Process exec(String cmdarray[], String[] envp, File dir, PTY pty, int gracefulExitTimeMs)
|
||||
throws IOException {
|
||||
cmdarray = modifyCmdArrayIfFlatpak(cmdarray);
|
||||
if (hasSpawner)
|
||||
return new Spawner(cmdarray, envp, dir, pty, gracefulExitTimeMs);
|
||||
throw new UnsupportedOperationException(Messages.Util_exception_cannotCreatePty);
|
||||
}
|
||||
|
||||
private String modifyCmdIfFlatpak(String cmd) {
|
||||
if (System.getenv("FLATPAK_SANDBOX_DIR") != null) { //$NON-NLS-1$
|
||||
cmd = FLATPAK_CMD + cmd;
|
||||
|
|
|
@ -81,6 +81,23 @@ public class Spawner extends Process {
|
|||
*/
|
||||
private final static int SIG_CTRLC = 1000; // arbitrary high number to avoid collision
|
||||
|
||||
private final static int DEFAULT_GRACEFUL_EXIT_TIME_MS;
|
||||
|
||||
static {
|
||||
String timeStr = System.getProperty("org.eclipse.cdt.core.graceful_exit_time_ms"); //$NON-NLS-1$
|
||||
int time = 1000;
|
||||
if (timeStr != null) {
|
||||
try {
|
||||
time = Integer.parseInt(timeStr);
|
||||
} catch (NumberFormatException e) {
|
||||
CNativePlugin.log(
|
||||
"Failed to parse system property. Falling back to " + time + " ms graceful exit time.", //$NON-NLS-1$ //$NON-NLS-2$
|
||||
e);
|
||||
}
|
||||
}
|
||||
DEFAULT_GRACEFUL_EXIT_TIME_MS = time;
|
||||
}
|
||||
|
||||
int pid = 0;
|
||||
int status;
|
||||
final IChannel[] fChannels = { null, null, null };
|
||||
|
@ -89,6 +106,8 @@ public class Spawner extends Process {
|
|||
InputStream err;
|
||||
private PTY fPty;
|
||||
|
||||
private final int fGracefulExitTimeMs;
|
||||
|
||||
private static enum State {
|
||||
RUNNING, DESTROYING, DONE
|
||||
}
|
||||
|
@ -100,6 +119,7 @@ public class Spawner extends Process {
|
|||
*/
|
||||
@Deprecated
|
||||
public Spawner(String command, boolean bNoRedirect) throws IOException {
|
||||
fGracefulExitTimeMs = DEFAULT_GRACEFUL_EXIT_TIME_MS;
|
||||
StringTokenizer tokenizer = new StringTokenizer(command);
|
||||
String[] cmdarray = new String[tokenizer.countTokens()];
|
||||
for (int n = 0; tokenizer.hasMoreTokens(); n++)
|
||||
|
@ -110,11 +130,17 @@ public class Spawner extends Process {
|
|||
exec(cmdarray, new String[0], "."); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
protected Spawner(String[] cmdarray, String[] envp, File dir) throws IOException {
|
||||
this(cmdarray, envp, dir, DEFAULT_GRACEFUL_EXIT_TIME_MS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the specified command and arguments in a separate process with the
|
||||
* specified environment and working directory.
|
||||
* @since 6.2
|
||||
**/
|
||||
protected Spawner(String[] cmdarray, String[] envp, File dir) throws IOException {
|
||||
protected Spawner(String[] cmdarray, String[] envp, File dir, int gracefulExitTimeMs) throws IOException {
|
||||
fGracefulExitTimeMs = gracefulExitTimeMs;
|
||||
String dirpath = "."; //$NON-NLS-1$
|
||||
if (dir != null)
|
||||
dirpath = dir.getAbsolutePath();
|
||||
|
@ -122,6 +148,14 @@ public class Spawner extends Process {
|
|||
}
|
||||
|
||||
protected Spawner(String[] cmdarray, String[] envp, File dir, PTY pty) throws IOException {
|
||||
this(cmdarray, envp, dir, pty, DEFAULT_GRACEFUL_EXIT_TIME_MS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 6.2
|
||||
*/
|
||||
protected Spawner(String[] cmdarray, String[] envp, File dir, PTY pty, int gracefulExitTimeMs) throws IOException {
|
||||
fGracefulExitTimeMs = gracefulExitTimeMs;
|
||||
String dirpath = "."; //$NON-NLS-1$
|
||||
if (dir != null)
|
||||
dirpath = dir.getAbsolutePath();
|
||||
|
@ -145,6 +179,13 @@ public class Spawner extends Process {
|
|||
this(cmdarray, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 6.2
|
||||
*/
|
||||
protected Spawner(String[] cmdarray, int gracefulExitTimeMs) throws IOException {
|
||||
this(cmdarray, null, gracefulExitTimeMs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the specified command and arguments in a separate process with the
|
||||
* specified environment.
|
||||
|
@ -153,6 +194,13 @@ public class Spawner extends Process {
|
|||
this(cmdarray, envp, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 6.2
|
||||
*/
|
||||
protected Spawner(String[] cmdarray, String[] envp, int gracefulExitTimeMs) throws IOException {
|
||||
this(cmdarray, envp, null, gracefulExitTimeMs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the specified string command in a separate process with the specified
|
||||
* environment.
|
||||
|
@ -170,6 +218,7 @@ public class Spawner extends Process {
|
|||
*/
|
||||
@Deprecated
|
||||
protected Spawner(String command, String[] envp, File dir) throws IOException {
|
||||
fGracefulExitTimeMs = DEFAULT_GRACEFUL_EXIT_TIME_MS;
|
||||
StringTokenizer tokenizer = new StringTokenizer(command);
|
||||
String[] cmdarray = new String[tokenizer.countTokens()];
|
||||
for (int n = 0; tokenizer.hasMoreTokens(); n++)
|
||||
|
@ -314,7 +363,7 @@ public class Spawner extends Process {
|
|||
// Grace before using the heavy gun.
|
||||
if (fState != State.DONE) {
|
||||
try {
|
||||
wait(1000);
|
||||
wait(fGracefulExitTimeMs);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue