diff --git a/containerd-shim/main.go b/containerd-shim/main.go index 9328991f3..a7dcbe3c8 100644 --- a/containerd-shim/main.go +++ b/containerd-shim/main.go @@ -12,17 +12,6 @@ import ( "github.com/docker/docker/pkg/term" ) -var ( - fexec bool - fcheckpoint string -) - -func init() { - flag.BoolVar(&fexec, "exec", false, "exec a process instead of starting the init") - flag.StringVar(&fcheckpoint, "checkpoint", "", "start container from an existing checkpoint") - flag.Parse() -} - func setupLogger() { f, err := os.OpenFile("/tmp/shim.log", os.O_CREATE|os.O_RDWR|os.O_APPEND, 0755) if err != nil { @@ -37,6 +26,7 @@ func setupLogger() { // the cwd of the shim should be the bundle for the container. Arg1 should be the path // to the state directory where the shim can locate fifos and other information. func main() { + flag.Parse() // start handling signals as soon as possible so that things are properly reaped // or if runc exits before we hit the handler signals := make(chan os.Signal, 2048) @@ -56,7 +46,7 @@ func main() { logrus.WithField("error", err).Fatal("shim: open control pipe") } defer control.Close() - p, err := newProcess(flag.Arg(0), flag.Arg(1), fexec, fcheckpoint) + p, err := newProcess(flag.Arg(0), flag.Arg(1)) if err != nil { logrus.WithField("error", err).Fatal("shim: create new process") } diff --git a/containerd-shim/process.go b/containerd-shim/process.go index d670d3df8..c7a3e3747 100644 --- a/containerd-shim/process.go +++ b/containerd-shim/process.go @@ -27,19 +27,18 @@ type process struct { state *runtime.ProcessState } -func newProcess(id, bundle string, exec bool, checkpoint string) (*process, error) { +func newProcess(id, bundle string) (*process, error) { p := &process{ id: id, bundle: bundle, - exec: exec, } s, err := loadProcess() if err != nil { return nil, err } p.state = s - if checkpoint != "" { - cpt, err := loadCheckpoint(bundle, checkpoint) + if s.Checkpoint != "" { + cpt, err := loadCheckpoint(bundle, s.Checkpoint) if err != nil { return nil, err } @@ -83,7 +82,7 @@ func (p *process) start() error { return err } args := []string{} - if p.exec { + if p.state.Exec { args = append(args, "exec", "--process", filepath.Join(cwd, "process.json"), "--console", p.consolePath, @@ -146,7 +145,7 @@ func (p *process) pid() int { } func (p *process) delete() error { - if !p.exec { + if !p.state.Exec { return exec.Command("runc", "delete", p.id).Run() } return nil diff --git a/runtime/container.go b/runtime/container.go index 36bbb3241..081fe2221 100644 --- a/runtime/container.go +++ b/runtime/container.go @@ -150,7 +150,6 @@ func (c *container) Start(checkpoint string, s Stdio) (Process, error) { return nil, err } cmd := exec.Command("containerd-shim", - "-checkpoint", checkpoint, c.id, c.bundle, ) cmd.Dir = processRoot @@ -162,6 +161,7 @@ func (c *container) Start(checkpoint string, s Stdio) (Process, error) { return nil, err } config := &processConfig{ + checkpoint: checkpoint, root: processRoot, id: InitProcessID, c: c, @@ -189,7 +189,6 @@ func (c *container) Exec(pid string, spec specs.Process, s Stdio) (Process, erro return nil, err } cmd := exec.Command("containerd-shim", - "-exec", c.id, c.bundle, ) cmd.Dir = processRoot @@ -197,6 +196,7 @@ func (c *container) Exec(pid string, spec specs.Process, s Stdio) (Process, erro Setpgid: true, } config := &processConfig{ + exec: true, id: pid, root: processRoot, c: c, diff --git a/runtime/process.go b/runtime/process.go index c131ef796..3aa5654e5 100644 --- a/runtime/process.go +++ b/runtime/process.go @@ -47,6 +47,8 @@ type processConfig struct { spec *specs.LinuxSpec c *container stdio Stdio + exec bool + checkpoint string } func newProcess(config *processConfig) (*process, error) { @@ -67,12 +69,14 @@ func newProcess(config *processConfig) (*process, error) { } defer f.Close() if err := json.NewEncoder(f).Encode(ProcessState{ - Process: config.processSpec, - RootUID: uid, - RootGID: gid, - Stdin: config.stdio.Stdin, - Stdout: config.stdio.Stdout, - Stderr: config.stdio.Stderr, + Process: config.processSpec, + Exec: config.exec, + Checkpoint: config.checkpoint, + RootUID: uid, + RootGID: gid, + Stdin: config.stdio.Stdin, + Stdout: config.stdio.Stdout, + Stderr: config.stdio.Stderr, }); err != nil { return nil, err } diff --git a/runtime/runtime.go b/runtime/runtime.go index 095b1b52b..0d8b1993a 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -44,11 +44,13 @@ type state struct { type ProcessState struct { specs.Process - RootUID int `json:"rootUID"` - RootGID int `json:"rootGID"` - Stdin string `json:"containerdStdin"` - Stdout string `json:"containerdStdout"` - Stderr string `json:"containerdStderr"` + Exec bool `json:"exec"` + Checkpoint string `json:"checkpoint"` + RootUID int `json:"rootUID"` + RootGID int `json:"rootGID"` + Stdin string `json:"containerdStdin"` + Stdout string `json:"containerdStdout"` + Stderr string `json:"containerdStderr"` } type Stat struct {