Merge pull request #702 from crosbymichael/attach

Expose Pty resize and CloseStdin RPCs
This commit is contained in:
Phil Estes 2017-04-10 14:38:30 -04:00 committed by GitHub
commit 4f33aa2b5c
15 changed files with 1031 additions and 231 deletions

View file

@ -24,6 +24,13 @@ func (s State) Status() containerd.Status {
return s.status
}
func newContainer(id string, shim shim.ShimClient) *Container {
return &Container{
id: id,
shim: shim,
}
}
type Container struct {
id string
@ -103,6 +110,21 @@ func (c *Container) Exec(ctx context.Context, opts containerd.ExecOpts) (contain
c: c,
}, nil
}
func (c *Container) Pty(ctx context.Context, pid uint32, size containerd.ConsoleSize) error {
_, err := c.shim.Pty(ctx, &shim.PtyRequest{
Pid: pid,
Width: size.Width,
Height: size.Height,
})
return err
}
func (c *Container) CloseStdin(ctx context.Context, pid uint32) error {
_, err := c.shim.CloseStdin(ctx, &shim.CloseStdinRequest{
Pid: pid,
})
return err
}
type Process struct {
pid int

View file

@ -112,10 +112,7 @@ func (r *Runtime) Create(ctx context.Context, id string, opts containerd.CreateO
os.RemoveAll(path)
return nil, err
}
c := &Container{
id: id,
shim: s,
}
c := newContainer(id, s)
// after the container is create add it to the monitor
if err := r.monitor.Monitor(c); err != nil {
return nil, err

View file

@ -74,6 +74,10 @@ func (c *client) Exit(ctx context.Context, in *shimapi.ExitRequest, opts ...grpc
return empty, nil
}
func (c *client) CloseStdin(ctx context.Context, in *shimapi.CloseStdinRequest, opts ...grpc.CallOption) (*google_protobuf.Empty, error) {
return c.s.CloseStdin(ctx, in)
}
type events struct {
c chan *container.Event
ctx context.Context

View file

@ -28,6 +28,7 @@ type execProcess struct {
status int
pid int
closers []io.Closer
stdin io.Closer
parent *initProcess
}
@ -78,6 +79,7 @@ func newExecProcess(context context.Context, path string, r *shimapi.ExecRequest
return nil, err
}
e.closers = append(e.closers, sc)
e.stdin = sc
}
if socket != nil {
console, err := socket.ReceiveMaster()
@ -145,3 +147,7 @@ func (e *execProcess) Resize(ws console.WinSize) error {
func (e *execProcess) Signal(sig int) error {
return syscall.Kill(e.pid, syscall.Signal(sig))
}
func (e *execProcess) Stdin() io.Closer {
return e.stdin
}

View file

@ -28,6 +28,7 @@ type initProcess struct {
status int
pid int
closers []io.Closer
stdin io.Closer
}
func newInitProcess(context context.Context, path string, r *shimapi.CreateRequest) (*initProcess, error) {
@ -83,6 +84,7 @@ func newInitProcess(context context.Context, path string, r *shimapi.CreateReque
if err != nil {
return nil, err
}
p.stdin = sc
p.closers = append(p.closers, sc)
}
if socket != nil {
@ -175,3 +177,7 @@ func (p *initProcess) killAll(context context.Context) error {
func (p *initProcess) Signal(sig int) error {
return syscall.Kill(p.pid, syscall.Signal(sig))
}
func (p *initProcess) Stdin() io.Closer {
return p.stdin
}

View file

@ -4,6 +4,7 @@ package shim
import (
"context"
"io"
"github.com/crosbymichael/console"
)
@ -21,4 +22,6 @@ type process interface {
Delete(context.Context) error
// Signal directly signals the process
Signal(int) error
// Stdin returns the process STDIN
Stdin() io.Closer
}

View file

@ -233,6 +233,17 @@ func (s *Service) Kill(ctx context.Context, r *shimapi.KillRequest) (*google_pro
return empty, nil
}
func (s *Service) CloseStdin(ctx context.Context, r *shimapi.CloseStdinRequest) (*google_protobuf.Empty, error) {
p, ok := s.processes[int(r.Pid)]
if !ok {
return nil, fmt.Errorf("process does not exist %d", r.Pid)
}
if err := p.Stdin().Close(); err != nil {
return nil, err
}
return empty, nil
}
func (s *Service) waitExit(p process, pid int, cmd *reaper.Cmd) {
status := <-cmd.ExitCh
p.Exited(status)