diff --git a/components/engine/daemon/top.go b/components/engine/daemon/top.go index ceaeea157e..f7b981d10a 100644 --- a/components/engine/daemon/top.go +++ b/components/engine/daemon/top.go @@ -29,7 +29,7 @@ func (daemon *Daemon) ContainerTop(job *engine.Job) engine.Status { if err != nil { return job.Error(err) } - output, err := exec.Command("ps", psArgs).Output() + output, err := exec.Command("ps", strings.Split(psArgs, " ")...).Output() if err != nil { return job.Errorf("Error running ps: %s", err) } diff --git a/components/engine/integration-cli/docker_cli_top_test.go b/components/engine/integration-cli/docker_cli_top_test.go index 1292930080..f3ff15bceb 100644 --- a/components/engine/integration-cli/docker_cli_top_test.go +++ b/components/engine/integration-cli/docker_cli_top_test.go @@ -7,6 +7,25 @@ import ( "testing" ) +func TestTopMultipleArgs(t *testing.T) { + runCmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox", "sleep", "20") + out, _, err := runCommandWithOutput(runCmd) + errorOut(err, t, fmt.Sprintf("failed to start the container: %v", err)) + + cleanedContainerID := stripTrailingCharacters(out) + defer deleteContainer(cleanedContainerID) + + topCmd := exec.Command(dockerBinary, "top", cleanedContainerID, "-o", "pid") + out, _, err = runCommandWithOutput(topCmd) + errorOut(err, t, fmt.Sprintf("failed to run top: %v %v", out, err)) + + if !strings.Contains(out, "PID") { + errorOut(nil, t, fmt.Sprintf("did not see PID after top -o pid")) + } + + logDone("top - multiple arguments") +} + func TestTopNonPrivileged(t *testing.T) { runCmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox", "sleep", "20") out, _, err := runCommandWithOutput(runCmd)