mirror of https://github.com/containers/podman.git
Return title fields as a list
Podman is attempting to split the headers returned by the ps command into a list of headers. Problem is that some headers are multi-word, and headers are not guaranteed to be split via a tab. This PR splits the headers bases on white space, and for the select group of CAPS headers which are multi-word, combines them back together. Fixes: https://github.com/containers/podman/issues/17524 Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
parent
c8eb15114b
commit
1fa4e45a95
|
@ -63,7 +63,7 @@ loop: // break out of for/select infinite` loop
|
||||||
case <-r.Context().Done():
|
case <-r.Context().Done():
|
||||||
break loop
|
break loop
|
||||||
default:
|
default:
|
||||||
output, err := c.Top([]string{query.PsArgs})
|
output, err := c.Top(strings.Split(query.PsArgs, ","))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Infof("Error from %s %q : %v", r.Method, r.URL, err)
|
logrus.Infof("Error from %s %q : %v", r.Method, r.URL, err)
|
||||||
break loop
|
break loop
|
||||||
|
@ -71,7 +71,8 @@ loop: // break out of for/select infinite` loop
|
||||||
|
|
||||||
if len(output) > 0 {
|
if len(output) > 0 {
|
||||||
body := handlers.ContainerTopOKBody{}
|
body := handlers.ContainerTopOKBody{}
|
||||||
body.Titles = strings.Split(output[0], "\t")
|
body.Titles = utils.PSTitles(output[0])
|
||||||
|
|
||||||
for i := range body.Titles {
|
for i := range body.Titles {
|
||||||
body.Titles[i] = strings.TrimSpace(body.Titles[i])
|
body.Titles[i] = strings.TrimSpace(body.Titles[i])
|
||||||
}
|
}
|
||||||
|
|
|
@ -413,7 +413,7 @@ loop: // break out of for/select infinite` loop
|
||||||
|
|
||||||
if len(output) > 0 {
|
if len(output) > 0 {
|
||||||
body := handlers.PodTopOKBody{}
|
body := handlers.PodTopOKBody{}
|
||||||
body.Titles = strings.Split(output[0], "\t")
|
body.Titles = utils.PSTitles(output[0])
|
||||||
for i := range body.Titles {
|
for i := range body.Titles {
|
||||||
body.Titles[i] = strings.TrimSpace(body.Titles[i])
|
body.Titles[i] = strings.TrimSpace(body.Titles[i])
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containers/podman/v4/libpod/events"
|
"github.com/containers/podman/v4/libpod/events"
|
||||||
|
@ -238,3 +239,23 @@ func containerExists(ctx context.Context, name string) (bool, error) {
|
||||||
}
|
}
|
||||||
return ctrExistRep.Value, nil
|
return ctrExistRep.Value, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PSTitles merges CAPS headers from ps output. All PS headers are single words, except for
|
||||||
|
// CAPS. Function compines CAP Headers into single field separated by a space.
|
||||||
|
func PSTitles(output string) []string {
|
||||||
|
var titles []string
|
||||||
|
|
||||||
|
for _, title := range strings.Fields(output) {
|
||||||
|
switch title {
|
||||||
|
case "AMBIENT", "INHERITED", "PERMITTED", "EFFECTIVE", "BOUNDING":
|
||||||
|
{
|
||||||
|
titles = append(titles, title+" CAPS")
|
||||||
|
}
|
||||||
|
case "CAPS":
|
||||||
|
continue
|
||||||
|
default:
|
||||||
|
titles = append(titles, title)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return titles
|
||||||
|
}
|
||||||
|
|
|
@ -121,6 +121,14 @@ if root; then
|
||||||
.memory_stats.limit=536870912 \
|
.memory_stats.limit=536870912 \
|
||||||
.id~[0-9a-f]\\{64\\}
|
.id~[0-9a-f]\\{64\\}
|
||||||
|
|
||||||
|
t GET containers/$CTRNAME/top?stream=false 200 \
|
||||||
|
.Titles='[
|
||||||
|
"PID",
|
||||||
|
"USER",
|
||||||
|
"TIME",
|
||||||
|
"COMMAND"
|
||||||
|
]'
|
||||||
|
|
||||||
podman rm -f $CTRNAME
|
podman rm -f $CTRNAME
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue