Move exec and checkpoint to process state

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2016-02-11 11:30:25 -08:00
parent cf28969328
commit d317f71ac2
5 changed files with 26 additions and 31 deletions

View file

@ -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")
}

View file

@ -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