podman

Форк
0
/
pod_top_freebsd.go 
78 строк · 1.9 Кб
1
//go:build !remote
2

3
package libpod
4

5
import (
6
	"fmt"
7
	"strings"
8

9
	"github.com/containers/podman/v5/libpod/define"
10
)
11

12
// GetPodPidInformation returns process-related data of all processes in
13
// the pod.  The output data can be controlled via the `descriptors`
14
// argument which expects format descriptors and supports all AIXformat
15
// descriptors of ps (1) plus some additional ones to for instance inspect the
16
// set of effective capabilities.  Each element in the returned string slice
17
// is a tab-separated string.
18
//
19
// For more details, please refer to github.com/containers/psgo.
20
func (p *Pod) GetPodPidInformation(descriptors []string) ([]string, error) {
21
	// Default to 'ps -ef' compatible descriptors
22
	if len(strings.Join(descriptors, "")) == 0 {
23
		descriptors = []string{"user", "pid", "ppid", "pcpu", "etime", "tty", "time", "args"}
24
	}
25

26
	jailNames := make([]string, 0)
27
	ctrsInPod, err := p.AllContainers()
28
	if err != nil {
29
		return nil, err
30
	}
31
	for _, c := range ctrsInPod {
32
		c.lock.Lock()
33
		err := c.syncContainer()
34
		c.lock.Unlock()
35
		if err != nil {
36
			return nil, err
37
		}
38

39
		if c.state.State == define.ContainerStateRunning {
40
			jailName, err := c.jailName()
41
			if err != nil {
42
				return nil, fmt.Errorf("getting jail name: %w", err)
43
			}
44
			jailNames = append(jailNames, jailName)
45
		}
46
	}
47

48
	// Also support comma-separated input.
49
	psDescriptors := []string{}
50
	for _, d := range descriptors {
51
		for _, s := range strings.Split(d, ",") {
52
			if s != "" {
53
				psDescriptors = append(psDescriptors, s)
54
			}
55
		}
56
	}
57

58
	// For consistency with pod_top_linux.go, only allow descriptor names
59
	for _, d := range psDescriptors {
60
		if _, ok := isDescriptor[d]; !ok {
61
			return nil, fmt.Errorf("unknown descriptor: %s", d)
62
		}
63
	}
64

65
	args := []string{
66
		"-J",
67
		strings.Join(jailNames, ","),
68
		"-ao",
69
		strings.Join(psDescriptors, ","),
70
	}
71

72
	output, err := execPS(args)
73
	if err != nil {
74
		return nil, fmt.Errorf("executing ps(1): %w", err)
75
	}
76

77
	return output, nil
78
}
79

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.