From 47bc4d7548f33bae3f700c24b66757ab0f0be322 Mon Sep 17 00:00:00 2001 From: Martin Oberhuber < martin.oberhuber@windriver.com> Date: Fri, 20 Oct 2006 20:08:32 +0000 Subject: [PATCH] Apply patch for bug 158786 - remote shell doesnt close after launch --- .../rse/remotecdt/HostShellAdapter.java | 30 +++++++++++++++++-- .../remotecdt/RemoteRunLaunchDelegate.java | 9 +++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/rse/examples/org.eclipse.rse.remotecdt/src/org/eclipse/rse/remotecdt/HostShellAdapter.java b/rse/examples/org.eclipse.rse.remotecdt/src/org/eclipse/rse/remotecdt/HostShellAdapter.java index e29d29ca331..8b5e7648396 100644 --- a/rse/examples/org.eclipse.rse.remotecdt/src/org/eclipse/rse/remotecdt/HostShellAdapter.java +++ b/rse/examples/org.eclipse.rse.remotecdt/src/org/eclipse/rse/remotecdt/HostShellAdapter.java @@ -48,6 +48,8 @@ IHostShellOutputListener { hostShell.exit(); notifyAll(); try { + hostShellInput.close(); + hostShellError.close(); inputStream.close(); errorStream.close(); outputStream.close(); @@ -56,7 +58,7 @@ IHostShellOutputListener { } } - public int exitValue() { + public synchronized int exitValue() { if(hostShell.isActive()) throw new IllegalThreadStateException(); // No way to tell what the exit value was. @@ -76,8 +78,30 @@ IHostShellOutputListener { } public synchronized int waitFor() throws InterruptedException { - while(hostShell.isActive()) - wait(); + + while(hostShell.isActive()) { + try { + wait(1000); + } catch (InterruptedException e) { + // ignore because we're polling to see if shell is still active. + } + } + + try { + // Wait a second to try to get some more output from the target shell before closing. + wait(1000); + // Allow for the data from the stream to be read if it's available + if (inputStream.available() != 0 || errorStream.available() != 0) + throw new InterruptedException(); + + hostShellInput.close(); + hostShellError.close(); + inputStream.close(); + errorStream.close(); + outputStream.close(); + } catch (IOException e) { + // Ignore + } return 0; } diff --git a/rse/examples/org.eclipse.rse.remotecdt/src/org/eclipse/rse/remotecdt/RemoteRunLaunchDelegate.java b/rse/examples/org.eclipse.rse.remotecdt/src/org/eclipse/rse/remotecdt/RemoteRunLaunchDelegate.java index db5784e31bd..7f780a4e963 100644 --- a/rse/examples/org.eclipse.rse.remotecdt/src/org/eclipse/rse/remotecdt/RemoteRunLaunchDelegate.java +++ b/rse/examples/org.eclipse.rse.remotecdt/src/org/eclipse/rse/remotecdt/RemoteRunLaunchDelegate.java @@ -55,6 +55,8 @@ public class RemoteRunLaunchDelegate extends AbstractCLaunchDelegate { private final static String SHELL_SERVICE = "shell.service"; //$NON-NLS-1$ private final static String FILE_SERVICE = "file.service"; //$NON-NLS-1$ + private final static String EXIT_CMD = "exit"; //$NON-NLS-1$ + private final static String CMD_DELIMITER = ";"; //$NON-NLS-1$ /* * (non-Javadoc) @@ -259,8 +261,13 @@ public class RemoteRunLaunchDelegate extends AbstractCLaunchDelegate { protected Process remoteShellExec(ILaunchConfiguration config, String remoteCommandPath, String arguments) throws CoreException { - String remote_command = arguments == null ? spaceEscapify(remoteCommandPath) : + // The exit command is called to force the remote shell to close after our command + // is executed. This is to prevent a running process at the end of the debug session. + // See Bug 158786. + String real_remote_command = arguments == null ? spaceEscapify(remoteCommandPath) : spaceEscapify(remoteCommandPath) + " " + arguments; //$NON-NLS-1$ + String remote_command = real_remote_command + CMD_DELIMITER + EXIT_CMD; + IShellService shellService = (IShellService) getConnectedRemoteService(config, SHELL_SERVICE); // This is necessary because runCommand does not actually run the command right now.