mirror of
https://github.com/containers/podman.git
synced 2025-05-17 23:26:08 +08:00
podman: move MaybeMoveToSubCgroup to utils/
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@ -11,7 +11,6 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/containers/common/pkg/cgroups"
|
||||
"github.com/containers/podman/v4/cmd/podman/registry"
|
||||
api "github.com/containers/podman/v4/pkg/api/server"
|
||||
"github.com/containers/podman/v4/pkg/domain/entities"
|
||||
@ -24,26 +23,6 @@ import (
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// maybeMoveToSubCgroup moves the current process in a sub cgroup when
|
||||
// it is running in the root cgroup on a system that uses cgroupv2.
|
||||
func maybeMoveToSubCgroup() error {
|
||||
unifiedMode, err := cgroups.IsCgroup2UnifiedMode()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !unifiedMode {
|
||||
return nil
|
||||
}
|
||||
cgroup, err := utils.GetOwnCgroup()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if cgroup == "/" {
|
||||
return utils.MoveUnderCgroupSubtree("init")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func restService(flags *pflag.FlagSet, cfg *entities.PodmanConfig, opts entities.ServiceOptions) error {
|
||||
var (
|
||||
listener net.Listener
|
||||
@ -125,7 +104,7 @@ func restService(flags *pflag.FlagSet, cfg *entities.PodmanConfig, opts entities
|
||||
return err
|
||||
}
|
||||
|
||||
if err := maybeMoveToSubCgroup(); err != nil {
|
||||
if err := utils.MaybeMoveToSubCgroup(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -190,3 +190,23 @@ func MovePauseProcessToScope(pausePidPath string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MaybeMoveToSubCgroup moves the current process in a sub cgroup when
|
||||
// it is running in the root cgroup on a system that uses cgroupv2.
|
||||
func MaybeMoveToSubCgroup() error {
|
||||
unifiedMode, err := cgroups.IsCgroup2UnifiedMode()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !unifiedMode {
|
||||
return nil
|
||||
}
|
||||
cgroup, err := GetOwnCgroup()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if cgroup == "/" {
|
||||
return MoveUnderCgroupSubtree("init")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user