4c4c1b
From 776eb64ab2cc07e0bd2879791780fa9b9fcd7ea1 Mon Sep 17 00:00:00 2001
4c4c1b
From: Peter Hunt <pehunt@redhat.com>
4c4c1b
Date: Wed, 8 Jan 2020 11:09:07 -0500
4c4c1b
Subject: [PATCH] exec: fix pipes
4c4c1b
4c4c1b
In a largely anticlimatic solution to the saga of piped input from conmon, we come to this solution.
4c4c1b
4c4c1b
When we pass the Stdin stream to the exec.Command structure, it's immediately consumed and lost, instead of being consumed through CopyDetachable().
4c4c1b
4c4c1b
When we don't pass -i in, conmon is not told to create a masterfd_stdin, and won't pass anything to the container.
4c4c1b
4c4c1b
With both, we can do
4c4c1b
4c4c1b
echo hi | podman exec -til cat
4c4c1b
4c4c1b
and get the expected hi
4c4c1b
4c4c1b
Signed-off-by: Peter Hunt <pehunt@redhat.com>
4c4c1b
---
4c4c1b
 libpod/oci_conmon_linux.go | 9 ++++++---
4c4c1b
 1 file changed, 6 insertions(+), 3 deletions(-)
4c4c1b
4c4c1b
diff --git a/libpod/oci_conmon_linux.go b/libpod/oci_conmon_linux.go
4c4c1b
index 37aa71cbba..78c8f41260 100644
4c4c1b
--- a/libpod/oci_conmon_linux.go
4c4c1b
+++ b/libpod/oci_conmon_linux.go
4c4c1b
@@ -546,6 +546,10 @@ func (r *ConmonOCIRuntime) ExecContainer(c *Container, sessionID string, options
4c4c1b
 		args = append(args, "-t")
4c4c1b
 	}
4c4c1b
 
4c4c1b
+	if options.Streams.AttachInput {
4c4c1b
+		args = append(args, "-i")
4c4c1b
+	}
4c4c1b
+
4c4c1b
 	// Append container ID and command
4c4c1b
 	args = append(args, "-e")
4c4c1b
 	// TODO make this optional when we can detach
4c4c1b
@@ -558,9 +562,8 @@ func (r *ConmonOCIRuntime) ExecContainer(c *Container, sessionID string, options
4c4c1b
 	execCmd := exec.Command(r.conmonPath, args...)
4c4c1b
 
4c4c1b
 	if options.Streams != nil {
4c4c1b
-		if options.Streams.AttachInput {
4c4c1b
-			execCmd.Stdin = options.Streams.InputStream
4c4c1b
-		}
4c4c1b
+		// Don't add the InputStream to the execCmd. Instead, the data should be passed
4c4c1b
+		// through CopyDetachable
4c4c1b
 		if options.Streams.AttachOutput {
4c4c1b
 			execCmd.Stdout = options.Streams.OutputStream
4c4c1b
 		}