You've already forked runc
mirror of
https://github.com/opencontainers/runc.git
synced 2025-07-30 17:43:06 +03:00
Revert to non-recursive GetPids, add recursive GetAllPids
Signed-off-by: Jimmi Dyson <jimmidyson@gmail.com>
This commit is contained in:
@ -15,6 +15,9 @@ type Manager interface {
|
|||||||
// Returns the PIDs inside the cgroup set
|
// Returns the PIDs inside the cgroup set
|
||||||
GetPids() ([]int, error)
|
GetPids() ([]int, error)
|
||||||
|
|
||||||
|
// Returns the PIDs inside the cgroup set & all sub-cgroups
|
||||||
|
GetAllPids() ([]int, error)
|
||||||
|
|
||||||
// Returns statistics for the cgroup set
|
// Returns statistics for the cgroup set
|
||||||
GetStats() (*Stats, error)
|
GetStats() (*Stats, error)
|
||||||
|
|
||||||
|
@ -217,19 +217,30 @@ func (m *Manager) Freeze(state configs.FreezerState) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) GetPids() ([]int, error) {
|
func (m *Manager) GetPids() ([]int, error) {
|
||||||
d, err := getCgroupData(m.Cgroups, 0)
|
dir, err := getCgroupPath(m.Cgroups)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
dir, err := d.path("devices")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return cgroups.GetPids(dir)
|
return cgroups.GetPids(dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Manager) GetAllPids() ([]int, error) {
|
||||||
|
dir, err := getCgroupPath(m.Cgroups)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return cgroups.GetAllPids(dir)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getCgroupPath(c *configs.Cgroup) (string, error) {
|
||||||
|
d, err := getCgroupData(c, 0)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return d.path("devices")
|
||||||
|
}
|
||||||
|
|
||||||
func getCgroupData(c *configs.Cgroup, pid int) (*cgroupData, error) {
|
func getCgroupData(c *configs.Cgroup, pid int) (*cgroupData, error) {
|
||||||
root, err := getCgroupRoot()
|
root, err := getCgroupRoot()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -26,6 +26,10 @@ func (m *Manager) GetPids() ([]int, error) {
|
|||||||
return nil, fmt.Errorf("Systemd not supported")
|
return nil, fmt.Errorf("Systemd not supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Manager) GetAllPids() ([]int, error) {
|
||||||
|
return nil, fmt.Errorf("Systemd not supported")
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Manager) Destroy() error {
|
func (m *Manager) Destroy() error {
|
||||||
return fmt.Errorf("Systemd not supported")
|
return fmt.Errorf("Systemd not supported")
|
||||||
}
|
}
|
||||||
|
@ -440,6 +440,14 @@ func (m *Manager) GetPids() ([]int, error) {
|
|||||||
return cgroups.GetPids(path)
|
return cgroups.GetPids(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Manager) GetAllPids() ([]int, error) {
|
||||||
|
path, err := getSubsystemPath(m.Cgroups, "devices")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return cgroups.GetAllPids(path)
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Manager) GetStats() (*cgroups.Stats, error) {
|
func (m *Manager) GetStats() (*cgroups.Stats, error) {
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
defer m.mu.Unlock()
|
defer m.mu.Unlock()
|
||||||
|
@ -323,9 +323,14 @@ func GetHugePageSize() ([]string, error) {
|
|||||||
return pageSizes, nil
|
return pageSizes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPids returns all pids, that were added to cgroup at path and to all its
|
// GetPids returns all pids, that were added to cgroup at path.
|
||||||
// subcgroups.
|
|
||||||
func GetPids(path string) ([]int, error) {
|
func GetPids(path string) ([]int, error) {
|
||||||
|
return readProcsFile(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAllPids returns all pids, that were added to cgroup at path and to all its
|
||||||
|
// subcgroups.
|
||||||
|
func GetAllPids(path string) ([]int, error) {
|
||||||
var pids []int
|
var pids []int
|
||||||
// collect pids from all sub-cgroups
|
// collect pids from all sub-cgroups
|
||||||
err := filepath.Walk(path, func(p string, info os.FileInfo, iErr error) error {
|
err := filepath.Walk(path, func(p string, info os.FileInfo, iErr error) error {
|
||||||
|
@ -129,7 +129,7 @@ func (c *linuxContainer) State() (*State, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *linuxContainer) Processes() ([]int, error) {
|
func (c *linuxContainer) Processes() ([]int, error) {
|
||||||
pids, err := c.cgroupManager.GetPids()
|
pids, err := c.cgroupManager.GetAllPids()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, newSystemError(err)
|
return nil, newSystemError(err)
|
||||||
}
|
}
|
||||||
|
@ -12,15 +12,20 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type mockCgroupManager struct {
|
type mockCgroupManager struct {
|
||||||
pids []int
|
pids []int
|
||||||
stats *cgroups.Stats
|
allPids []int
|
||||||
paths map[string]string
|
stats *cgroups.Stats
|
||||||
|
paths map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockCgroupManager) GetPids() ([]int, error) {
|
func (m *mockCgroupManager) GetPids() ([]int, error) {
|
||||||
return m.pids, nil
|
return m.pids, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *mockCgroupManager) GetAllPids() ([]int, error) {
|
||||||
|
return m.allPids, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (m *mockCgroupManager) GetStats() (*cgroups.Stats, error) {
|
func (m *mockCgroupManager) GetStats() (*cgroups.Stats, error) {
|
||||||
return m.stats, nil
|
return m.stats, nil
|
||||||
}
|
}
|
||||||
@ -85,7 +90,7 @@ func TestGetContainerPids(t *testing.T) {
|
|||||||
container := &linuxContainer{
|
container := &linuxContainer{
|
||||||
id: "myid",
|
id: "myid",
|
||||||
config: &configs.Config{},
|
config: &configs.Config{},
|
||||||
cgroupManager: &mockCgroupManager{pids: []int{1, 2, 3}},
|
cgroupManager: &mockCgroupManager{allPids: []int{1, 2, 3}},
|
||||||
}
|
}
|
||||||
pids, err := container.Processes()
|
pids, err := container.Processes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -309,7 +309,7 @@ func killCgroupProcesses(m cgroups.Manager) error {
|
|||||||
if err := m.Freeze(configs.Frozen); err != nil {
|
if err := m.Freeze(configs.Frozen); err != nil {
|
||||||
logrus.Warn(err)
|
logrus.Warn(err)
|
||||||
}
|
}
|
||||||
pids, err := m.GetPids()
|
pids, err := m.GetAllPids()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.Freeze(configs.Thawed)
|
m.Freeze(configs.Thawed)
|
||||||
return err
|
return err
|
||||||
|
Reference in New Issue
Block a user