1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Address review comments.

Docker-DCO-1.1-Signed-off-by: Vishnu Kannan <vishnuk@google.com> (github: vishh)
This commit is contained in:
Vishnu Kannan 2014-09-11 00:06:59 +00:00
parent d980589de6
commit 669561c2aa
8 changed files with 18 additions and 21 deletions

View file

@ -25,14 +25,14 @@ func (cli *DockerCli) dial() (net.Conn, error) {
return net.Dial(cli.proto, cli.addr) return net.Dial(cli.proto, cli.addr)
} }
func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in io.ReadCloser, stdout, stderr io.Writer, started chan io.Closer, body interface{}) error { func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in io.ReadCloser, stdout, stderr io.Writer, started chan io.Closer, data interface{}) error {
defer func() { defer func() {
if started != nil { if started != nil {
close(started) close(started)
} }
}() }()
params, err := cli.getUrlBody(body) params, err := cli.encodeData(data)
if err != nil { if err != nil {
return err return err
} }

View file

@ -40,7 +40,7 @@ func (cli *DockerCli) HTTPClient() *http.Client {
return &http.Client{Transport: tr} return &http.Client{Transport: tr}
} }
func (cli *DockerCli) getUrlBody(data interface{}) (*bytes.Buffer, error) { func (cli *DockerCli) encodeData(data interface{}) (*bytes.Buffer, error) {
params := bytes.NewBuffer(nil) params := bytes.NewBuffer(nil)
if data != nil { if data != nil {
if env, ok := data.(engine.Env); ok { if env, ok := data.(engine.Env); ok {
@ -61,7 +61,7 @@ func (cli *DockerCli) getUrlBody(data interface{}) (*bytes.Buffer, error) {
} }
func (cli *DockerCli) call(method, path string, data interface{}, passAuthInfo bool) (io.ReadCloser, int, error) { func (cli *DockerCli) call(method, path string, data interface{}, passAuthInfo bool) (io.ReadCloser, int, error) {
params, err := cli.getUrlBody(data) params, err := cli.encodeData(data)
if err != nil { if err != nil {
return nil, -1, err return nil, -1, err
} }

View file

@ -128,7 +128,7 @@ func (daemon *Daemon) Attach(streamConfig *StreamConfig, openStdin, stdinOnce, t
// Connect stdin of container to the http conn. // Connect stdin of container to the http conn.
if stdin != nil && openStdin { if stdin != nil && openStdin {
nJobs += 1 nJobs++
// Get the stdin pipe. // Get the stdin pipe.
if cStdin, err := streamConfig.StdinPipe(); err != nil { if cStdin, err := streamConfig.StdinPipe(); err != nil {
errors <- err errors <- err
@ -166,7 +166,7 @@ func (daemon *Daemon) Attach(streamConfig *StreamConfig, openStdin, stdinOnce, t
} }
} }
if stdout != nil { if stdout != nil {
nJobs += 1 nJobs++
// Get a reader end of a pipe that is attached as stdout to the container. // Get a reader end of a pipe that is attached as stdout to the container.
if p, err := streamConfig.StdoutPipe(); err != nil { if p, err := streamConfig.StdoutPipe(); err != nil {
errors <- err errors <- err
@ -260,7 +260,7 @@ func (daemon *Daemon) Attach(streamConfig *StreamConfig, openStdin, stdinOnce, t
// FIXME: how to clean up the stdin goroutine without the unwanted side effect // FIXME: how to clean up the stdin goroutine without the unwanted side effect
// of closing the passed stdin? Add an intermediary io.Pipe? // of closing the passed stdin? Add an intermediary io.Pipe?
for i := 0; i < nJobs; i += 1 { for i := 0; i < nJobs; i++ {
log.Debugf("attach: waiting for job %d/%d", i+1, nJobs) log.Debugf("attach: waiting for job %d/%d", i+1, nJobs)
if err := <-errors; err != nil { if err := <-errors; err != nil {
log.Errorf("attach: job %d returned error %s, aborting all jobs", i+1, err) log.Errorf("attach: job %d returned error %s, aborting all jobs", i+1, err)

View file

@ -24,7 +24,7 @@ type ExecConfig struct {
func (d *Daemon) ContainerExec(job *engine.Job) engine.Status { func (d *Daemon) ContainerExec(job *engine.Job) engine.Status {
if len(job.Args) != 1 { if len(job.Args) != 1 {
return job.Errorf("Usage: %s container_id command", job.Name) return job.Errorf("Usage: %s [options] container command [args]", job.Name)
} }
var ( var (
@ -40,7 +40,7 @@ func (d *Daemon) ContainerExec(job *engine.Job) engine.Status {
return job.Errorf("No such container: %s", name) return job.Errorf("No such container: %s", name)
} }
if !container.State.IsRunning() { if !container.IsRunning() {
return job.Errorf("Container %s is not not running", name) return job.Errorf("Container %s is not not running", name)
} }

View file

@ -16,15 +16,16 @@ import (
"github.com/docker/libcontainer/namespaces" "github.com/docker/libcontainer/namespaces"
) )
const commandName = "nsenter-exec" const execCommandName = "nsenter-exec"
func init() { func init() {
reexec.Register(commandName, nsenterExec) reexec.Register(execCommandName, nsenterExec)
} }
func nsenterExec() { func nsenterExec() {
runtime.LockOSThread() runtime.LockOSThread()
// User args are passed after '--' in the command line.
userArgs := findUserArgs() userArgs := findUserArgs()
config, err := loadConfigFromFd() config, err := loadConfigFromFd()

View file

@ -10,16 +10,12 @@ import (
) )
func findUserArgs() []string { func findUserArgs() []string {
i := 0 for i, a := range os.Args {
for _, a := range os.Args {
i++
if a == "--" { if a == "--" {
break return os.Args[i+1:]
} }
} }
return []string{}
return os.Args[i:]
} }
// loadConfigFromFd loads a container's config from the sync pipe that is provided by // loadConfigFromFd loads a container's config from the sync pipe that is provided by

View file

@ -1297,7 +1297,7 @@ It is even useful to cherry-pick particular tags of an image repository
## exec ## exec
Usage: docker exec CONTAINER COMMAND [ARG...] Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
Run a command in an existing container Run a command in an existing container

View file

@ -27,8 +27,8 @@ func ExecConfigFromJob(job *engine.Job) *ExecConfig {
AttachStderr: job.GetenvBool("AttachStderr"), AttachStderr: job.GetenvBool("AttachStderr"),
AttachStdout: job.GetenvBool("AttachStdout"), AttachStdout: job.GetenvBool("AttachStdout"),
} }
if Cmd := job.GetenvList("Cmd"); Cmd != nil { if cmd := job.GetenvList("Cmd"); cmd != nil {
execConfig.Cmd = Cmd execConfig.Cmd = cmd
} }
return execConfig return execConfig