Browse code

Address review comments.

Docker-DCO-1.1-Signed-off-by: Vishnu Kannan <vishnuk@google.com> (github: vishh)

Vishnu Kannan authored on 2014/09/11 09:06:59
Showing 8 changed files
... ...
@@ -25,14 +25,14 @@ func (cli *DockerCli) dial() (net.Conn, error) {
25 25
 	return net.Dial(cli.proto, cli.addr)
26 26
 }
27 27
 
28
-func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in io.ReadCloser, stdout, stderr io.Writer, started chan io.Closer, body interface{}) error {
28
+func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in io.ReadCloser, stdout, stderr io.Writer, started chan io.Closer, data interface{}) error {
29 29
 	defer func() {
30 30
 		if started != nil {
31 31
 			close(started)
32 32
 		}
33 33
 	}()
34 34
 
35
-	params, err := cli.getUrlBody(body)
35
+	params, err := cli.encodeData(data)
36 36
 	if err != nil {
37 37
 		return err
38 38
 	}
... ...
@@ -40,7 +40,7 @@ func (cli *DockerCli) HTTPClient() *http.Client {
40 40
 	return &http.Client{Transport: tr}
41 41
 }
42 42
 
43
-func (cli *DockerCli) getUrlBody(data interface{}) (*bytes.Buffer, error) {
43
+func (cli *DockerCli) encodeData(data interface{}) (*bytes.Buffer, error) {
44 44
 	params := bytes.NewBuffer(nil)
45 45
 	if data != nil {
46 46
 		if env, ok := data.(engine.Env); ok {
... ...
@@ -61,7 +61,7 @@ func (cli *DockerCli) getUrlBody(data interface{}) (*bytes.Buffer, error) {
61 61
 }
62 62
 
63 63
 func (cli *DockerCli) call(method, path string, data interface{}, passAuthInfo bool) (io.ReadCloser, int, error) {
64
-	params, err := cli.getUrlBody(data)
64
+	params, err := cli.encodeData(data)
65 65
 	if err != nil {
66 66
 		return nil, -1, err
67 67
 	}
... ...
@@ -128,7 +128,7 @@ func (daemon *Daemon) Attach(streamConfig *StreamConfig, openStdin, stdinOnce, t
128 128
 
129 129
 	// Connect stdin of container to the http conn.
130 130
 	if stdin != nil && openStdin {
131
-		nJobs += 1
131
+		nJobs++
132 132
 		// Get the stdin pipe.
133 133
 		if cStdin, err := streamConfig.StdinPipe(); err != nil {
134 134
 			errors <- err
... ...
@@ -166,7 +166,7 @@ func (daemon *Daemon) Attach(streamConfig *StreamConfig, openStdin, stdinOnce, t
166 166
 		}
167 167
 	}
168 168
 	if stdout != nil {
169
-		nJobs += 1
169
+		nJobs++
170 170
 		// Get a reader end of a pipe that is attached as stdout to the container.
171 171
 		if p, err := streamConfig.StdoutPipe(); err != nil {
172 172
 			errors <- err
... ...
@@ -260,7 +260,7 @@ func (daemon *Daemon) Attach(streamConfig *StreamConfig, openStdin, stdinOnce, t
260 260
 
261 261
 		// FIXME: how to clean up the stdin goroutine without the unwanted side effect
262 262
 		// of closing the passed stdin? Add an intermediary io.Pipe?
263
-		for i := 0; i < nJobs; i += 1 {
263
+		for i := 0; i < nJobs; i++ {
264 264
 			log.Debugf("attach: waiting for job %d/%d", i+1, nJobs)
265 265
 			if err := <-errors; err != nil {
266 266
 				log.Errorf("attach: job %d returned error %s, aborting all jobs", i+1, err)
... ...
@@ -24,7 +24,7 @@ type ExecConfig struct {
24 24
 
25 25
 func (d *Daemon) ContainerExec(job *engine.Job) engine.Status {
26 26
 	if len(job.Args) != 1 {
27
-		return job.Errorf("Usage: %s container_id command", job.Name)
27
+		return job.Errorf("Usage: %s [options] container command [args]", job.Name)
28 28
 	}
29 29
 
30 30
 	var (
... ...
@@ -40,7 +40,7 @@ func (d *Daemon) ContainerExec(job *engine.Job) engine.Status {
40 40
 		return job.Errorf("No such container: %s", name)
41 41
 	}
42 42
 
43
-	if !container.State.IsRunning() {
43
+	if !container.IsRunning() {
44 44
 		return job.Errorf("Container %s is not not running", name)
45 45
 	}
46 46
 
... ...
@@ -16,15 +16,16 @@ import (
16 16
 	"github.com/docker/libcontainer/namespaces"
17 17
 )
18 18
 
19
-const commandName = "nsenter-exec"
19
+const execCommandName = "nsenter-exec"
20 20
 
21 21
 func init() {
22
-	reexec.Register(commandName, nsenterExec)
22
+	reexec.Register(execCommandName, nsenterExec)
23 23
 }
24 24
 
25 25
 func nsenterExec() {
26 26
 	runtime.LockOSThread()
27 27
 
28
+	// User args are passed after '--' in the command line.
28 29
 	userArgs := findUserArgs()
29 30
 
30 31
 	config, err := loadConfigFromFd()
... ...
@@ -10,16 +10,12 @@ import (
10 10
 )
11 11
 
12 12
 func findUserArgs() []string {
13
-	i := 0
14
-	for _, a := range os.Args {
15
-		i++
16
-
13
+	for i, a := range os.Args {
17 14
 		if a == "--" {
18
-			break
15
+			return os.Args[i+1:]
19 16
 		}
20 17
 	}
21
-
22
-	return os.Args[i:]
18
+	return []string{}
23 19
 }
24 20
 
25 21
 // loadConfigFromFd loads a container's config from the sync pipe that is provided by
... ...
@@ -1297,7 +1297,7 @@ It is even useful to cherry-pick particular tags of an image repository
1297 1297
 
1298 1298
 ## exec
1299 1299
 
1300
-    Usage: docker exec CONTAINER COMMAND [ARG...]
1300
+    Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
1301 1301
 
1302 1302
     Run a command in an existing container
1303 1303
 
... ...
@@ -27,8 +27,8 @@ func ExecConfigFromJob(job *engine.Job) *ExecConfig {
27 27
 		AttachStderr: job.GetenvBool("AttachStderr"),
28 28
 		AttachStdout: job.GetenvBool("AttachStdout"),
29 29
 	}
30
-	if Cmd := job.GetenvList("Cmd"); Cmd != nil {
31
-		execConfig.Cmd = Cmd
30
+	if cmd := job.GetenvList("Cmd"); cmd != nil {
31
+		execConfig.Cmd = cmd
32 32
 	}
33 33
 
34 34
 	return execConfig