diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-01-27 14:25:06 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-27 14:25:06 -0500 |
commit | 1814fa2d21494a543881d7dc5bacffbb04d85d18 (patch) | |
tree | 55d70e9a08327743c74c7cb54f5e3d42da22a317 /libpod/util.go | |
parent | 2ff4da9b59df27584e436ff59a9d12b2c5e5e410 (diff) | |
parent | c63599d361396c8bd02cc4bfccff0e7d97653146 (diff) | |
download | podman-1814fa2d21494a543881d7dc5bacffbb04d85d18.tar.gz podman-1814fa2d21494a543881d7dc5bacffbb04d85d18.tar.bz2 podman-1814fa2d21494a543881d7dc5bacffbb04d85d18.zip |
Merge pull request #9105 from vrothberg/fix-8281
remote exec: write conmon error on hijacked connection
Diffstat (limited to 'libpod/util.go')
-rw-r--r-- | libpod/util.go | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/libpod/util.go b/libpod/util.go index bf9bf2542..391208fb9 100644 --- a/libpod/util.go +++ b/libpod/util.go @@ -235,20 +235,16 @@ func checkDependencyContainer(depCtr, ctr *Container) error { return nil } -// hijackWriteErrorAndClose writes an error to a hijacked HTTP session and -// closes it. Intended to HTTPAttach function. -// If error is nil, it will not be written; we'll only close the connection. -func hijackWriteErrorAndClose(toWrite error, cid string, terminal bool, httpCon io.Closer, httpBuf *bufio.ReadWriter) { +// hijackWriteError writes an error to a hijacked HTTP session. +func hijackWriteError(toWrite error, cid string, terminal bool, httpBuf *bufio.ReadWriter) { if toWrite != nil { - errString := []byte(fmt.Sprintf("%v\n", toWrite)) + errString := []byte(fmt.Sprintf("Error: %v\n", toWrite)) if !terminal { // We need a header. header := makeHTTPAttachHeader(2, uint32(len(errString))) if _, err := httpBuf.Write(header); err != nil { logrus.Errorf("Error writing header for container %s attach connection error: %v", cid, err) } - // TODO: May want to return immediately here to avoid - // writing garbage to the socket? } if _, err := httpBuf.Write(errString); err != nil { logrus.Errorf("Error writing error to container %s HTTP attach connection: %v", cid, err) @@ -257,6 +253,13 @@ func hijackWriteErrorAndClose(toWrite error, cid string, terminal bool, httpCon logrus.Errorf("Error flushing HTTP buffer for container %s HTTP attach connection: %v", cid, err) } } +} + +// hijackWriteErrorAndClose writes an error to a hijacked HTTP session and +// closes it. Intended to HTTPAttach function. +// If error is nil, it will not be written; we'll only close the connection. +func hijackWriteErrorAndClose(toWrite error, cid string, terminal bool, httpCon io.Closer, httpBuf *bufio.ReadWriter) { + hijackWriteError(toWrite, cid, terminal, httpBuf) if err := httpCon.Close(); err != nil { logrus.Errorf("Error closing container %s HTTP attach connection: %v", cid, err) |