Browse code

Merge pull request #7812 from erikh/fix_top

docker top: fix command when multiple arguments are supplied

Michael Crosby authored on 2014/09/02 03:31:38
Showing 2 changed files
... ...
@@ -29,7 +29,7 @@ func (daemon *Daemon) ContainerTop(job *engine.Job) engine.Status {
29 29
 		if err != nil {
30 30
 			return job.Error(err)
31 31
 		}
32
-		output, err := exec.Command("ps", psArgs).Output()
32
+		output, err := exec.Command("ps", strings.Split(psArgs, " ")...).Output()
33 33
 		if err != nil {
34 34
 			return job.Errorf("Error running ps: %s", err)
35 35
 		}
... ...
@@ -7,6 +7,25 @@ import (
7 7
 	"testing"
8 8
 )
9 9
 
10
+func TestTopMultipleArgs(t *testing.T) {
11
+	runCmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox", "sleep", "20")
12
+	out, _, err := runCommandWithOutput(runCmd)
13
+	errorOut(err, t, fmt.Sprintf("failed to start the container: %v", err))
14
+
15
+	cleanedContainerID := stripTrailingCharacters(out)
16
+	defer deleteContainer(cleanedContainerID)
17
+
18
+	topCmd := exec.Command(dockerBinary, "top", cleanedContainerID, "-o", "pid")
19
+	out, _, err = runCommandWithOutput(topCmd)
20
+	errorOut(err, t, fmt.Sprintf("failed to run top: %v %v", out, err))
21
+
22
+	if !strings.Contains(out, "PID") {
23
+		errorOut(nil, t, fmt.Sprintf("did not see PID after top -o pid"))
24
+	}
25
+
26
+	logDone("top - multiple arguments")
27
+}
28
+
10 29
 func TestTopNonPrivileged(t *testing.T) {
11 30
 	runCmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox", "sleep", "20")
12 31
 	out, _, err := runCommandWithOutput(runCmd)