diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-01-16 21:10:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-16 21:10:53 +0100 |
commit | 74b89da27c5da20ddcbff5ea3689795ad2b720f5 (patch) | |
tree | 0a4516323bc9dd5bedf4ef75595892dcf7a27b63 /libpod/util.go | |
parent | 79fbe7252e35b086e168c55c32b6c7b8e83496bc (diff) | |
parent | ac47e80b07ddc1e56e7c4fd6b0deca9f3bdc5f54 (diff) | |
download | podman-74b89da27c5da20ddcbff5ea3689795ad2b720f5.tar.gz podman-74b89da27c5da20ddcbff5ea3689795ad2b720f5.tar.bz2 podman-74b89da27c5da20ddcbff5ea3689795ad2b720f5.zip |
Merge pull request #4837 from mheon/rework_attach
Add an API for Attach over HTTP API
Diffstat (limited to 'libpod/util.go')
-rw-r--r-- | libpod/util.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/libpod/util.go b/libpod/util.go index 30e5cd4c3..f79d6c09b 100644 --- a/libpod/util.go +++ b/libpod/util.go @@ -1,7 +1,9 @@ package libpod import ( + "bufio" "fmt" + "io" "os" "os/exec" "path/filepath" @@ -16,6 +18,7 @@ import ( "github.com/fsnotify/fsnotify" spec "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) // Runtime API constants @@ -231,3 +234,20 @@ 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, httpCon io.Closer, httpBuf *bufio.ReadWriter) { + if toWrite != nil { + if _, err := httpBuf.Write([]byte(toWrite.Error())); err != nil { + logrus.Errorf("Error writing error %q to container %s HTTP attach connection: %v", toWrite, cid, err) + } else if err := httpBuf.Flush(); err != nil { + logrus.Errorf("Error flushing HTTP buffer for container %s HTTP attach connection: %v", cid, err) + } + } + + if err := httpCon.Close(); err != nil { + logrus.Errorf("Error closing container %s HTTP attach connection: %v", cid, err) + } +} |