fix(deps): update module github.com/opencontainers/cgroups to v0.0.5

Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This commit is contained in:
renovate[bot]
2025-09-05 21:46:04 +00:00
committed by GitHub
parent c8183c50a0
commit 50a3e3cf8a
6 changed files with 51 additions and 4 deletions

View File

@ -29,6 +29,11 @@ type Manager interface {
// can be used to merely create a cgroup.
Apply(pid int) error
// AddPid adds a process with a given pid to an existing cgroup.
// The subcgroup argument is either empty, or a path relative to
// a cgroup under under the manager's cgroup.
AddPid(subcgroup string, pid int) error
// GetPids returns the PIDs of all processes inside the cgroup.
GetPids() ([]int, error)

View File

@ -4,6 +4,8 @@ import (
"errors"
"fmt"
"os"
"path"
"strings"
"sync"
"golang.org/x/sys/unix"
@ -139,6 +141,33 @@ func (m *Manager) Apply(pid int) (retErr error) {
return retErr
}
// AddPid adds a process with a given pid to an existing cgroup.
// The subcgroup argument is either empty, or a path relative to
// a cgroup under under the manager's cgroup.
func (m *Manager) AddPid(subcgroup string, pid int) (retErr error) {
m.mu.Lock()
defer m.mu.Unlock()
c := m.cgroups
for _, dir := range m.paths {
path := path.Join(dir, subcgroup)
if !strings.HasPrefix(path, dir) {
return fmt.Errorf("bad sub cgroup path: %s", subcgroup)
}
if err := cgroups.WriteCgroupProc(path, pid); err != nil {
if isIgnorableError(c.Rootless, err) && c.Path == "" {
retErr = cgroups.ErrRootless
continue
}
return err
}
}
return retErr
}
func (m *Manager) Destroy() error {
m.mu.Lock()
defer m.mu.Unlock()

View File

@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/opencontainers/cgroups"
@ -83,6 +84,18 @@ func (m *Manager) Apply(pid int) error {
return nil
}
// AddPid adds a process with a given pid to an existing cgroup.
// The subcgroup argument is either empty, or a path relative to
// a cgroup under under the manager's cgroup.
func (m *Manager) AddPid(subcgroup string, pid int) error {
path := filepath.Join(m.dirPath, subcgroup)
if !strings.HasPrefix(path, m.dirPath) {
return fmt.Errorf("bad sub cgroup path: %s", subcgroup)
}
return cgroups.WriteCgroupProc(path, pid)
}
func (m *Manager) GetPids() ([]int, error) {
return cgroups.GetPids(m.dirPath)
}