diff options
author | Lantao Liu <lantaol@google.com> | 2019-05-10 18:27:49 -0700 |
---|---|---|
committer | Ian Lewis <ianlewis@google.com> | 2019-05-11 10:27:49 +0900 |
commit | 97875daf63d03cda6ff3c4f393a004a8295a748e (patch) | |
tree | 30dce772c1d7bb9d77fab8b224675630e3c10b2d /pkg/v1 | |
parent | 14f1de4a45daa75ef016fabb56d86cbd9b902504 (diff) |
Port shim fix (#27)
Port shim fixes containerd/containerd#3264, containerd/containerd#3264
Update containerd to newest release/1.2 commit.
Diffstat (limited to 'pkg/v1')
-rw-r--r-- | pkg/v1/proc/deleted_state.go | 3 | ||||
-rw-r--r-- | pkg/v1/proc/io.go | 31 |
2 files changed, 30 insertions, 4 deletions
diff --git a/pkg/v1/proc/deleted_state.go b/pkg/v1/proc/deleted_state.go index c92a443a2..95b4406cd 100644 --- a/pkg/v1/proc/deleted_state.go +++ b/pkg/v1/proc/deleted_state.go @@ -21,6 +21,7 @@ import ( "context" "github.com/containerd/console" + "github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/runtime/proc" "github.com/pkg/errors" ) @@ -38,10 +39,12 @@ func (s *deletedState) Start(ctx context.Context) error { func (s *deletedState) Delete(ctx context.Context) error { return errors.Errorf("cannot delete a deleted process") + return errors.Wrap(errdefs.ErrNotFound, "cannot delete a deleted process") } func (s *deletedState) Kill(ctx context.Context, sig uint32, all bool) error { return errors.Errorf("cannot kill a deleted process") + return errors.Wrap(errdefs.ErrNotFound, "cannot kill a deleted process") } func (s *deletedState) SetExited(status int) { diff --git a/pkg/v1/proc/io.go b/pkg/v1/proc/io.go index 9079f6feb..4afa94cf2 100644 --- a/pkg/v1/proc/io.go +++ b/pkg/v1/proc/io.go @@ -23,8 +23,10 @@ import ( "io" "os" "sync" + "sync/atomic" "syscall" + "github.com/containerd/containerd/log" "github.com/containerd/fifo" runc "github.com/containerd/go-runc" ) @@ -39,7 +41,7 @@ var bufPool = sync.Pool{ } func copyPipes(ctx context.Context, rio runc.IO, stdin, stdout, stderr string, wg, cwg *sync.WaitGroup) error { - var sameFile io.WriteCloser + var sameFile *countingWriteCloser for _, i := range []struct { name string dest func(wc io.WriteCloser, rc io.Closer) @@ -53,7 +55,9 @@ func copyPipes(ctx context.Context, rio runc.IO, stdin, stdout, stderr string, w cwg.Done() p := bufPool.Get().(*[]byte) defer bufPool.Put(p) - io.CopyBuffer(wc, rio.Stdout(), *p) + if _, err := io.CopyBuffer(wc, rio.Stdout(), *p); err != nil { + log.G(ctx).Warn("error copying stdout") + } wg.Done() wc.Close() if rc != nil { @@ -70,7 +74,9 @@ func copyPipes(ctx context.Context, rio runc.IO, stdin, stdout, stderr string, w cwg.Done() p := bufPool.Get().(*[]byte) defer bufPool.Put(p) - io.CopyBuffer(wc, rio.Stderr(), *p) + if _, err := io.CopyBuffer(wc, rio.Stderr(), *p); err != nil { + log.G(ctx).Warn("error copying stderr") + } wg.Done() wc.Close() if rc != nil { @@ -97,6 +103,7 @@ func copyPipes(ctx context.Context, rio runc.IO, stdin, stdout, stderr string, w } } else { if sameFile != nil { + sameFile.count++ i.dest(sameFile, nil) continue } @@ -104,7 +111,10 @@ func copyPipes(ctx context.Context, rio runc.IO, stdin, stdout, stderr string, w return fmt.Errorf("gvisor-containerd-shim: opening %s failed: %s", i.name, err) } if stdout == stderr { - sameFile = fw + sameFile = &countingWriteCloser{ + WriteCloser: fw, + count: 1, + } } } i.dest(fw, fr) @@ -129,6 +139,19 @@ func copyPipes(ctx context.Context, rio runc.IO, stdin, stdout, stderr string, w return nil } +// countingWriteCloser masks io.Closer() until close has been invoked a certain number of times. +type countingWriteCloser struct { + io.WriteCloser + count int64 +} + +func (c *countingWriteCloser) Close() error { + if atomic.AddInt64(&c.count, -1) > 0 { + return nil + } + return c.WriteCloser.Close() +} + // isFifo checks if a file is a fifo // if the file does not exist then it returns false func isFifo(path string) (bool, error) { |