Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2018-05-15 10:55:10 -0400
committerJeff Johnston2018-05-22 12:17:01 -0400
commitb5a32d280cecff0245d2a988d43a0cda43ce03d0 (patch)
tree66f7311845ff2b5078a7d2602195b94368924cab
parentba0709f8e2af13ed68ec802e5669ba776c118347 (diff)
downloadorg.eclipse.linuxtools-b5a32d280cecff0245d2a988d43a0cda43ce03d0.tar.gz
org.eclipse.linuxtools-b5a32d280cecff0245d2a988d43a0cda43ce03d0.tar.xz
org.eclipse.linuxtools-b5a32d280cecff0245d2a988d43a0cda43ce03d0.zip
Bug 534683 - Docker Run Image ignores stdin in regular console input
Change-Id: I464c99d3844d3834e5ade764a390bc4186e53d06 Signed-off-by: Mickael Istria <mistria@redhat.com> Reviewed-on: https://git.eclipse.org/r/122684 Tested-by: CI Bot Reviewed-by: Jeff Johnston <jjohnstn@redhat.com>
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/ContainerCommandProcess.java49
1 files changed, 46 insertions, 3 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/ContainerCommandProcess.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/ContainerCommandProcess.java
index 8c96982510..6a395457f8 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/ContainerCommandProcess.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/ContainerCommandProcess.java
@@ -21,7 +21,9 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
@@ -51,6 +53,9 @@ public class ContainerCommandProcess extends Process {
private String imageName;
private PipedInputStream stdout;
private PipedInputStream stderr;
+ private OutputStream stdin;
+ private PipedInputStream pipedStdinIn;
+ final private Set<Closeable> toClose = new HashSet<>();
private Map<String, String> remoteVolumes;
private boolean keepContainer;
private Thread thread;
@@ -72,6 +77,25 @@ public class ContainerCommandProcess extends Process {
this.stdout = new PipedInputStream();
this.stderr = new PipedInputStream();
this.keepContainer = keepContainer;
+ final IDockerContainerInfo info = connection.getContainerInfo(containerId);
+ if (info.config().openStdin()) {
+ try {
+ PipedOutputStream pipedStdinOut = new PipedOutputStream();
+ toClose.add(pipedStdinOut);
+ pipedStdinIn = new PipedInputStream(pipedStdinOut);
+ toClose.add(pipedStdinIn);
+ this.stdin = new OutputStream() {
+ @Override
+ public void write(int b) throws IOException {
+ pipedStdinOut.write(b);
+ }
+ };
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ } else {
+ this.stdin = new ByteArrayOutputStream();
+ }
// Lambda Runnable
Runnable logContainer = () -> {
PipedOutputStream pipedOut = null;
@@ -85,8 +109,23 @@ public class ContainerCommandProcess extends Process {
pipedErr = pipedStderr;
connection.startContainer(containerId, outputStream);
threadStarted = true;
- ((DockerConnection) connection).attachLog(token, containerId,
- pipedStdout, pipedStderr);
+ if (info.config().openStdin()) {
+ IDockerContainerState state = connection.getContainerInfo(containerId).state();
+ do {
+ if (!state.running()
+ && (state.finishDate() == null || state.finishDate().before(state.startDate()))) {
+ Thread.sleep(50);
+ }
+ state = info.state();
+ } while (!state.running()
+ && (state.finishDate() == null || state.finishDate().before(state.startDate())));
+ Thread.sleep(50);
+ state = connection.getContainerInfo(containerId).state();
+ if (state.running()) {
+ ((DockerConnection) connection).attachCommand(containerId, pipedStdinIn, null);
+ }
+ }
+ ((DockerConnection) connection).attachLog(token, containerId, pipedStdout, pipedStderr);
pipedStdout.flush();
pipedStderr.flush();
} catch (DockerException | InterruptedException | IOException e) {
@@ -146,6 +185,10 @@ public class ContainerCommandProcess extends Process {
}
this.stdout.close();
this.stderr.close();
+ this.stdin.close();
+ for (Closeable close : toClose) {
+ close.close();
+ }
} catch (IOException e) {
// ignore
}
@@ -242,7 +285,7 @@ public class ContainerCommandProcess extends Process {
@Override
public OutputStream getOutputStream() {
- return new ByteArrayOutputStream();
+ return this.stdin;
}
/**

Back to the top