Merge pull request #661 from crosbymichael/stdin-closer

Open stdin write side in shim
This commit is contained in:
Phil Estes 2017-04-03 12:25:43 -04:00 committed by GitHub
commit efb16dad44
4 changed files with 32 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import (
gocontext "context"
"encoding/json"
"fmt"
"os"
"path/filepath"
"runtime"
"strconv"
@ -260,6 +261,7 @@ var runCommand = cli.Command{
if err != nil {
return err
}
defer os.RemoveAll(tmpDir)
events, err := containers.Events(ctx, &execution.EventsRequest{})
if err != nil {
return err

View File

@ -4,14 +4,17 @@ import (
"context"
"encoding/json"
"fmt"
"io"
"os"
"path/filepath"
"sync"
"syscall"
"github.com/crosbymichael/console"
runc "github.com/crosbymichael/go-runc"
shimapi "github.com/docker/containerd/api/services/shim"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/tonistiigi/fifo"
)
type execProcess struct {
@ -22,6 +25,7 @@ type execProcess struct {
io runc.IO
status int
pid int
closers []io.Closer
parent *initProcess
}
@ -66,6 +70,13 @@ func newExecProcess(context context.Context, path string, r *shimapi.ExecRequest
if err := parent.runc.Exec(context, parent.id, spec, opts); err != nil {
return nil, err
}
if r.Stdin != "" {
sc, err := fifo.OpenFifo(context, r.Stdin, syscall.O_WRONLY|syscall.O_NONBLOCK, 0)
if err != nil {
return nil, err
}
e.closers = append(e.closers, sc)
}
if socket != nil {
console, err := socket.ReceiveMaster()
if err != nil {
@ -111,6 +122,9 @@ func (e *execProcess) Exited(status int) {
e.status = status
e.Wait()
if e.io != nil {
for _, c := range e.closers {
c.Close()
}
e.io.Close()
}
}

View File

@ -2,6 +2,7 @@ package shim
import (
"context"
"io"
"os"
"path/filepath"
"sync"
@ -11,6 +12,7 @@ import (
runc "github.com/crosbymichael/go-runc"
"github.com/docker/containerd"
shimapi "github.com/docker/containerd/api/services/shim"
"github.com/tonistiigi/fifo"
)
type initProcess struct {
@ -23,6 +25,7 @@ type initProcess struct {
runc *runc.Runc
status int
pid int
closers []io.Closer
}
func newInitProcess(context context.Context, path string, r *shimapi.CreateRequest) (*initProcess, error) {
@ -73,6 +76,13 @@ func newInitProcess(context context.Context, path string, r *shimapi.CreateReque
if err := p.runc.Create(context, r.ID, r.Bundle, opts); err != nil {
return nil, err
}
if r.Stdin != "" {
sc, err := fifo.OpenFifo(context, r.Stdin, syscall.O_WRONLY|syscall.O_NONBLOCK, 0)
if err != nil {
return nil, err
}
p.closers = append(p.closers, sc)
}
if socket != nil {
console, err := socket.ReceiveMaster()
if err != nil {
@ -125,6 +135,9 @@ func (p *initProcess) Delete(context context.Context) error {
p.Wait()
err := p.runc.Delete(context, p.id)
if p.io != nil {
for _, c := range p.closers {
c.Close()
}
p.io.Close()
}
return err

View File

@ -68,6 +68,9 @@ func copyPipes(ctx context.Context, rio runc.IO, stdin, stdout, stderr string, w
}
dest(fw, fr)
}
if stdin == "" {
return nil
}
f, err := fifo.OpenFifo(ctx, stdin, syscall.O_RDONLY, 0)
if err != nil {
return fmt.Errorf("containerd-shim: opening %s failed: %s", stdin, err)