1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-27 10:55:33 +02:00

[399231] Race conditions occur when trying to read from local processes

using LocalShellOutputReader
This commit is contained in:
David McKnight 2013-05-21 10:38:21 -04:00
parent fb2bddc219
commit 8bc840702f
2 changed files with 34 additions and 3 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2007 IBM Corporation and others.
* Copyright (c) 2005, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -13,10 +13,13 @@
*
* Contributors:
* Martin Oberhuber (Wind River) - [161838] local shell reports isActive() wrong
* Ioana Grigoropol (Intel) - [399231] Race conditions occur when trying to read from local processes using LocalShellOutputReader
*******************************************************************************/
package org.eclipse.rse.internal.services.local.shells;
import java.io.BufferedReader;
import java.util.concurrent.locks.Lock;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.rse.internal.services.local.shells.LocalShellOutputReader;
import org.eclipse.rse.internal.services.local.shells.LocalShellThread;
@ -38,7 +41,7 @@ public class LocalHostShell extends AbstractHostShell implements IHostShell
{
_shellThread = new LocalShellThread(initialWorkingDirectory, invocation, encoding, environment);
_stdoutHandler = new LocalShellOutputReader(this, _shellThread.getOutputStream(), false);
_stderrHandler = new LocalShellOutputReader(this, _shellThread.getErrorStream(),true);
_stderrHandler = new LocalShellOutputReader(this, _shellThread.getErrorStream(), true);
}
protected void run(IProgressMonitor monitor)
@ -84,5 +87,15 @@ public class LocalHostShell extends AbstractHostShell implements IHostShell
writeToShell("exit"); //$NON-NLS-1$
}
public Lock getLock() {
return _shellThread.getLock();
}
public BufferedReader getReader(boolean isErrorReader) {
if (isErrorReader)
return _shellThread.getErrorStream();
else
return _shellThread.getOutputStream();
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2002, 2008 IBM Corporation and others.
* Copyright (c) 2002, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -17,6 +17,7 @@
* David McKnight (IBM) - [189387] Use specified encoding for shell output
* Martin Oberhuber (Wind River) - [161838] local shell reports isActive() wrong
* Anna Dushistova (MontaVsita) - [249354] Incorrect behaviour of local shells subsystem runCommand method
* Ioana Grigoropol (Intel) - [399231] Race conditions occur when trying to read from local processes using LocalShellOutputReader
*******************************************************************************/
package org.eclipse.rse.internal.services.local.shells;
@ -29,6 +30,8 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.eclipse.core.runtime.FileLocator;
@ -62,6 +65,7 @@ public class LocalShellThread extends Thread
private BufferedReader _stdInput;
private BufferedReader _stdError;
private Lock _lock;
/**
* constructor for local command shell monitor
*
@ -260,6 +264,7 @@ public class LocalShellThread extends Thread
_stdError = new BufferedReader(new InputStreamReader(_theProcess.getErrorStream()));
_lock = new ReentrantLock();
}
catch (IOException e)
{
@ -438,9 +443,14 @@ public class LocalShellThread extends Thread
_isDone = true;
try
{
_lock.lock();
_stdInput.close();
_stdError.close();
_stdInput = null;
_stdError = null;
_lock.unlock();
if (_theProcess != null)
{
@ -511,4 +521,12 @@ public class LocalShellThread extends Thread
}
public Lock getLock() {
return _lock;
}
public void setLock(Lock _lock) {
this._lock = _lock;
}
}