From 29fbe077e05f4044bdd245f981920920222c4f0f Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Thu, 30 Apr 2015 17:40:30 -0400 Subject: Systemtap: terminate parser processes on stop. When a Parser job is cancelled, terminate the underlying stap process whether it is a local or remote process. Consequently, cause any process run remotely by means of execRemote to be terminated when its Jsch session is closed. Change-Id: Ibd4d3a04069cf30086a78985f02dad72e8782c60 Signed-off-by: Andrew Ferrazzutti Reviewed-on: https://git.eclipse.org/r/46940 Tested-by: Hudson CI Reviewed-by: Alexander Kurtakov --- .../META-INF/MANIFEST.MF | 2 +- .../pom.xml | 2 +- .../core/factory/LinuxtoolsProcessFactory.java | 21 +++++++++++++++++++++ .../ui/ide/structures/tparsers/ProbeParser.java | 6 ++---- .../ui/ide/structures/tparsers/TapsetParser.java | 11 +++++++---- 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/profiling/org.eclipse.linuxtools.tools.launch.core/META-INF/MANIFEST.MF b/profiling/org.eclipse.linuxtools.tools.launch.core/META-INF/MANIFEST.MF index 09cbf124d4..691777286b 100644 --- a/profiling/org.eclipse.linuxtools.tools.launch.core/META-INF/MANIFEST.MF +++ b/profiling/org.eclipse.linuxtools.tools.launch.core/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %bundleName Bundle-SymbolicName: org.eclipse.linuxtools.tools.launch.core;singleton:=true -Bundle-Version: 3.1.0.qualifier +Bundle-Version: 3.2.0.qualifier Bundle-Vendor: %provider Bundle-Localization: plugin Require-Bundle: org.eclipse.core.runtime, diff --git a/profiling/org.eclipse.linuxtools.tools.launch.core/pom.xml b/profiling/org.eclipse.linuxtools.tools.launch.core/pom.xml index eec5f853c3..a03823601c 100644 --- a/profiling/org.eclipse.linuxtools.tools.launch.core/pom.xml +++ b/profiling/org.eclipse.linuxtools.tools.launch.core/pom.xml @@ -18,7 +18,7 @@ org.eclipse.linuxtools.tools.launch.core - 3.1.0-SNAPSHOT + 3.2.0-SNAPSHOT eclipse-plugin Linux Tools Tools Launcher Core Plug-in diff --git a/profiling/org.eclipse.linuxtools.tools.launch.core/src/org/eclipse/linuxtools/tools/launch/core/factory/LinuxtoolsProcessFactory.java b/profiling/org.eclipse.linuxtools.tools.launch.core/src/org/eclipse/linuxtools/tools/launch/core/factory/LinuxtoolsProcessFactory.java index f1c47037c9..caa834b986 100644 --- a/profiling/org.eclipse.linuxtools.tools.launch.core/src/org/eclipse/linuxtools/tools/launch/core/factory/LinuxtoolsProcessFactory.java +++ b/profiling/org.eclipse.linuxtools.tools.launch.core/src/org/eclipse/linuxtools/tools/launch/core/factory/LinuxtoolsProcessFactory.java @@ -186,6 +186,7 @@ public abstract class LinuxtoolsProcessFactory { } ChannelExec channel = (ChannelExec) session.openChannel("exec"); //$NON-NLS-1$ + channel.setPty(true); channel.setCommand(command.toString()); channel.setInputStream(null, true); channel.setOutputStream(out, true); @@ -250,4 +251,24 @@ public abstract class LinuxtoolsProcessFactory { return channel; } + + /** + * Convenience method: asks the channel to attempt termination of the + * currently-running process on the channel's session. + * @param channel The channel whose session process should be terminated. + * @return true on a successul attempt of terminating the process, + * false otherwise. + * @since 3.2 + */ + public static boolean terminateProcess(Channel channel) { + try { + OutputStream out = channel.getOutputStream(); + out.write(3); + out.flush(); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } } diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/tparsers/ProbeParser.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/tparsers/ProbeParser.java index 0fc35ae0bb..9ea1c09ab9 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/tparsers/ProbeParser.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/tparsers/ProbeParser.java @@ -179,11 +179,9 @@ public final class ProbeParser extends TreeTapsetParser { return false; } // Check just the first probe printed - int end = probeDump.indexOf('\n'); - if (end != -1) { - probeDump = probeDump.substring(0, end); + try (Scanner scanner = new Scanner(probeDump)) { + return Pattern.matches(PROBE_FORM_CHECK_REGEX, scanner.nextLine()); } - return Pattern.matches(PROBE_FORM_CHECK_REGEX, probeDump); } /** diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/tparsers/TapsetParser.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/tparsers/TapsetParser.java index f0727afef6..dca42d4fc2 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/tparsers/TapsetParser.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/tparsers/TapsetParser.java @@ -149,8 +149,6 @@ public abstract class TapsetParser extends Job { if (!remote) { try { return runLocalStap(args, getErrors); - } catch (InterruptedException e) { - return ""; //$NON-NLS-1$ } catch (IOException e) { return null; } @@ -173,7 +171,7 @@ public abstract class TapsetParser extends Job { return IStatus.OK; } - private String runLocalStap(String[] args, boolean getErrors) throws IOException, InterruptedException { + private String runLocalStap(String[] args, boolean getErrors) throws IOException { Process process = RuntimeProcessFactory.getFactory().exec( args, EnvironmentVariablesPreferencePage.getEnvironmentVariables(), null); // An IOException should be thrown if there's a problem with exec, but to cover possible error @@ -189,7 +187,11 @@ public abstract class TapsetParser extends Job { egobbler = new StringStreamGobbler(process.getErrorStream()); egobbler.start(); } - process.waitFor(); + try { + process.waitFor(); + } catch (InterruptedException e) { + process.destroy(); + } gobbler.stop(); if (egobbler == null) { return gobbler.getOutput().toString(); @@ -234,6 +236,7 @@ public abstract class TapsetParser extends Job { return null; } channel.getSession().disconnect(); + channel.disconnect(); return (!getErrors ? str : strErr).toString(); } -- cgit v1.2.3