mirror of
https://github.com/k3s-io/k3s.git
synced 2026-02-03 20:39:49 -05:00
We are not making use of the stack traces that these functions capture, so we should avoid using them as unnecessary overhead. Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
24 lines
695 B
Go
24 lines
695 B
Go
//go:build linux && cgo
|
|
|
|
package cmds
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/moby/sys/userns"
|
|
pkgerrors "github.com/pkg/errors"
|
|
"github.com/rootless-containers/rootlesskit/pkg/parent/cgrouputil"
|
|
)
|
|
|
|
// EvacuateCgroup2 will handle evacuating the root cgroup in order to enable subtree_control,
|
|
// if running as pid 1 without rootless support.
|
|
func EvacuateCgroup2() error {
|
|
if os.Getpid() == 1 && !userns.RunningInUserNS() {
|
|
// The root cgroup has to be empty to enable subtree_control, so evacuate it by placing
|
|
// ourselves in the init cgroup.
|
|
if err := cgrouputil.EvacuateCgroup2("init"); err != nil {
|
|
return pkgerrors.WithMessage(err, "failed to evacuate root cgroup")
|
|
}
|
|
}
|
|
return nil
|
|
}
|