Skip to content

Commit

Permalink
ContainerTop: disallow --no-headers
Browse files Browse the repository at this point in the history
[v2: add --no-header, found by accident]
[v3: add --no-heading, found in ps man page]
[v4: add other 5 forms, found in procps sources]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Sep 20, 2018
1 parent be09512 commit b4bb386
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions daemon/top_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,22 @@ func (daemon *Daemon) ContainerTop(name string, psArgs string) (*container.Conta

args := strings.Split(psArgs, " ")

// can't work without headers
for _, arg := range args {
switch arg {
case
"--no-header",
"--no-headers",
"--no-heading",
"--no-headings",
"--noheader",
"--noheaders",
"--noheading",
"--noheadings":
return nil, errdefs.System(errors.New("option " + arg + " is not allowed"))
}
}

var extraPidColumn bool
if customArgs && customFields(args) {
// make sure the PID field is shown in the first column
Expand Down
4 changes: 4 additions & 0 deletions integration/container/top_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ func TestContainerTop(t *testing.T) {
opts: []string{"-o", "sasha"},
expectErr: true,
},
{
opts: []string{"--no-headers"},
expectErr: true,
},
}

for _, c := range cases {
Expand Down

0 comments on commit b4bb386

Please sign in to comment.