From b2d9d996108210d24ad675be892aafe1ce528c8b Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Mon, 29 Jun 2015 11:21:05 -0700 Subject: [PATCH] Only define a single process This removes the Processes slice and only allows for one process of the container. It also renames TTY to Terminal for a cross platform meaning. Signed-off-by: Michael Crosby --- README.md | 32 ++++++++++++++++---------------- restore.go | 2 +- run.go | 7 ++----- spec.go | 42 ++++++++++++++++++++---------------------- utils.go | 2 +- 5 files changed, 40 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index fa4f23795..47a190dba 100644 --- a/README.md +++ b/README.md @@ -43,22 +43,22 @@ user named `daemon` defined within that file-system. ```json { "version": "0.1", - "os": "linux", - "arch": "amd64", - "processes": [ - { - "tty": true, - "user": "daemon", - "args": [ - "sh" - ], - "env": [ - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", - "TERM=xterm" - ], - "cwd": "" - } - ], + "platform": { + "os": "linux", + "arch": "amd64" + }, + "process": { + "tty": true, + "user": "daemon", + "args": [ + "sh" + ], + "env": [ + "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", + "TERM=xterm" + ], + "cwd": "" + }, "root": { "path": "rootfs", "readonly": true diff --git a/restore.go b/restore.go index ff3acd0ad..511588b73 100644 --- a/restore.go +++ b/restore.go @@ -82,7 +82,7 @@ func restoreContainer(context *cli.Context, spec *Spec, config *configs.Config, Stdout: os.Stdout, Stderr: os.Stderr, } - tty, err := newTty(spec.Processes[0].TTY, process, rootuid) + tty, err := newTty(spec.Process.Terminal, process, rootuid) if err != nil { return -1, err } diff --git a/run.go b/run.go index 14ffc606c..7645d4c3c 100644 --- a/run.go +++ b/run.go @@ -10,9 +10,6 @@ import ( ) func execContainer(context *cli.Context, spec *Spec) (int, error) { - if len(spec.Processes) != 1 { - return -1, fmt.Errorf("runc only supports one(1) process for the container") - } config, err := createLibcontainerConfig(spec) if err != nil { return -1, err @@ -38,8 +35,8 @@ func execContainer(context *cli.Context, spec *Spec) (int, error) { // ensure that the container is always removed if we were the process // that created it. defer destroy(container) - process := newProcess(spec.Processes[0]) - tty, err := newTty(spec.Processes[0].TTY, process, rootuid) + process := newProcess(spec.Process) + tty, err := newTty(spec.Process.Terminal, process, rootuid) if err != nil { return -1, err } diff --git a/spec.go b/spec.go index c84ef84b5..7cf9de2c7 100644 --- a/spec.go +++ b/spec.go @@ -18,11 +18,11 @@ type Mount struct { } type Process struct { - TTY bool `json:"tty"` - User string `json:"user"` - Args []string `json:"args"` - Env []string `json:"env"` - Cwd string `json:"cwd"` + Terminal bool `json:"tty"` + User string `json:"user"` + Args []string `json:"args"` + Env []string `json:"env"` + Cwd string `json:"cwd"` } type Root struct { @@ -41,12 +41,12 @@ type Platform struct { } type PortableSpec struct { - Version string `json:"version"` - Platform Platform `json:"platform"` - Processes []*Process `json:"processes"` - Root Root `json:"root"` - Hostname string `json:"hostname"` - Mounts []Mount `json:"mounts"` + Version string `json:"version"` + Platform Platform `json:"platform"` + Process Process `json:"process"` + Root Root `json:"root"` + Hostname string `json:"hostname"` + Mounts []Mount `json:"mounts"` } var specCommand = cli.Command{ @@ -63,17 +63,15 @@ var specCommand = cli.Command{ Path: "rootfs", Readonly: true, }, - Processes: []*Process{ - { - TTY: true, - User: "daemon", - Args: []string{ - "sh", - }, - Env: []string{ - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", - "TERM=xterm", - }, + Process: Process{ + Terminal: true, + User: "daemon", + Args: []string{ + "sh", + }, + Env: []string{ + "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", + "TERM=xterm", }, }, Hostname: "shell", diff --git a/utils.go b/utils.go index 0ce699b26..43da7fa5b 100644 --- a/utils.go +++ b/utils.go @@ -160,7 +160,7 @@ func getDefaultImagePath(context *cli.Context) string { // newProcess returns a new libcontainer Process with the arguments from the // spec and stdio from the current process. -func newProcess(p *Process) *libcontainer.Process { +func newProcess(p Process) *libcontainer.Process { return &libcontainer.Process{ Args: p.Args, Env: p.Env,