Bladeren bron

Address review comments.

Docker-DCO-1.1-Signed-off-by: Vishnu Kannan <vishnuk@google.com> (github: vishh)
Vishnu Kannan 11 jaren geleden
bovenliggende
commit
669561c2aa

+ 2 - 2
api/client/hijack.go

@@ -25,14 +25,14 @@ func (cli *DockerCli) dial() (net.Conn, error) {
 	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() {
 		if started != nil {
 			close(started)
 		}
 	}()
 
-	params, err := cli.getUrlBody(body)
+	params, err := cli.encodeData(data)
 	if err != nil {
 		return err
 	}

+ 2 - 2
api/client/utils.go

@@ -40,7 +40,7 @@ func (cli *DockerCli) HTTPClient() *http.Client {
 	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)
 	if data != nil {
 		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) {
-	params, err := cli.getUrlBody(data)
+	params, err := cli.encodeData(data)
 	if err != nil {
 		return nil, -1, err
 	}

+ 3 - 3
daemon/attach.go

@@ -128,7 +128,7 @@ func (daemon *Daemon) Attach(streamConfig *StreamConfig, openStdin, stdinOnce, t
 
 	// Connect stdin of container to the http conn.
 	if stdin != nil && openStdin {
-		nJobs += 1
+		nJobs++
 		// Get the stdin pipe.
 		if cStdin, err := streamConfig.StdinPipe(); err != nil {
 			errors <- err
@@ -166,7 +166,7 @@ func (daemon *Daemon) Attach(streamConfig *StreamConfig, openStdin, stdinOnce, t
 		}
 	}
 	if stdout != nil {
-		nJobs += 1
+		nJobs++
 		// Get a reader end of a pipe that is attached as stdout to the container.
 		if p, err := streamConfig.StdoutPipe(); err != nil {
 			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
 		// 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)
 			if err := <-errors; err != nil {
 				log.Errorf("attach: job %d returned error %s, aborting all jobs", i+1, err)

+ 2 - 2
daemon/exec.go

@@ -24,7 +24,7 @@ type ExecConfig struct {
 
 func (d *Daemon) ContainerExec(job *engine.Job) engine.Status {
 	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 (
@@ -40,7 +40,7 @@ func (d *Daemon) ContainerExec(job *engine.Job) engine.Status {
 		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)
 	}
 

+ 3 - 2
daemon/execdriver/native/exec.go

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

+ 3 - 7
daemon/execdriver/native/utils.go

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

+ 1 - 1
docs/sources/reference/commandline/cli.md

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

+ 2 - 2
runconfig/exec.go

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