diff --git a/execution/executor.go b/execution/executor.go index 3af38e6e2..8ee68f489 100644 --- a/execution/executor.go +++ b/execution/executor.go @@ -16,6 +16,7 @@ type CreateOpts struct { } type StartProcessOpts struct { + ID string Spec specs.Process Console bool Stdin string diff --git a/execution/executors/oci/oci.go b/execution/executors/oci/oci.go index 685b9d5d6..c389034d8 100644 --- a/execution/executors/oci/oci.go +++ b/execution/executors/oci/oci.go @@ -12,6 +12,10 @@ import ( "github.com/docker/containerd/execution" ) +const ( + initProcessID = "init" +) + var ( ErrRootEmpty = errors.New("oci: runtime root cannot be an empty string") ) @@ -56,7 +60,7 @@ func (r *OCIRuntime) Create(ctx context.Context, id string, o execution.CreateOp } }(container) - initProcID, initStateDir, err := container.StateDir().NewProcess() + initStateDir, err := container.StateDir().NewProcess(initProcessID) if err != nil { return nil, err } @@ -80,7 +84,7 @@ func (r *OCIRuntime) Create(ctx context.Context, id string, o execution.CreateOp if err != nil { return nil, err } - process, err := newProcess(initProcID, pid) + process, err := newProcess(container, initProcessID, pid) if err != nil { return nil, err } @@ -126,7 +130,7 @@ func (r *OCIRuntime) load(runcC *runc.Container) (*execution.Container, error) { } return nil, err } - process, err := newProcess(filepath.Base(d), pid) + process, err := newProcess(container, filepath.Base(d), pid) if err != nil { return nil, err } @@ -198,13 +202,13 @@ func (r *OCIRuntime) StartProcess(ctx context.Context, c *execution.Container, o } }() - procID, procStateDir, err := c.StateDir().NewProcess() + procStateDir, err := c.StateDir().NewProcess(o.ID) if err != nil { return nil, err } defer func() { if err != nil { - c.StateDir().DeleteProcess(procID) + c.StateDir().DeleteProcess(o.ID) } }() @@ -223,7 +227,7 @@ func (r *OCIRuntime) StartProcess(ctx context.Context, c *execution.Container, o return nil, err } - process, err := newProcess(procID, pid) + process, err := newProcess(c, o.ID, pid) if err != nil { return nil, err } diff --git a/execution/executors/oci/process.go b/execution/executors/oci/process.go index d01b902ef..3ae61a7b5 100644 --- a/execution/executors/oci/process.go +++ b/execution/executors/oci/process.go @@ -7,22 +7,28 @@ import ( "github.com/docker/containerd/execution" ) -func newProcess(id string, pid int) (execution.Process, error) { +func newProcess(c *execution.Container, id string, pid int) (execution.Process, error) { proc, err := os.FindProcess(pid) if err != nil { return nil, err } return &process{ + c: c, id: id, proc: proc, }, nil } type process struct { + c *execution.Container id string proc *os.Process } +func (p *process) Container() *execution.Container { + return p.c +} + func (p *process) ID() string { return p.id } diff --git a/execution/process.go b/execution/process.go index 470560ff4..2f0b1f879 100644 --- a/execution/process.go +++ b/execution/process.go @@ -3,6 +3,7 @@ package execution import "os" type Process interface { + Container() *Container ID() string Pid() int64 //Spec() *specs.Process diff --git a/execution/service.go b/execution/service.go index 9a0837284..c9a6e1922 100644 --- a/execution/service.go +++ b/execution/service.go @@ -134,6 +134,7 @@ func (s *Service) StartProcess(ctx context.Context, r *api.StartProcessRequest) } process, err := s.executor.StartProcess(ctx, container, StartProcessOpts{ + ID: r.Process.ID, Spec: spec, Console: r.Console, Stdin: r.Stdin, diff --git a/execution/statedir.go b/execution/statedir.go index eb72fcb8a..985600848 100644 --- a/execution/statedir.go +++ b/execution/statedir.go @@ -26,13 +26,13 @@ func (s StateDir) Delete() error { return os.RemoveAll(string(s)) } -func (s StateDir) NewProcess() (id, dir string, err error) { - dir, err = ioutil.TempDir(s.processesDir(), "") - if err != nil { - return "", "", err +func (s StateDir) NewProcess(id string) (dir string, err error) { + dir = filepath.Join(s.processesDir(), id) + if err = os.Mkdir(dir, 0700); err != nil { + return "", err } - return filepath.Base(dir), dir, err + return dir, nil } func (s StateDir) ProcessDir(id string) string {