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

Merge pull request #7812 from erikh/fix_top

docker top: fix command when multiple arguments are supplied
This commit is contained in:
Michael Crosby 2014-09-01 11:31:38 -07:00
commit 388ed88042
2 changed files with 20 additions and 1 deletions

View file

@ -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)
}

View file

@ -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)