-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
37 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,24 @@ | ||
//go:build linux && cgo | ||
// +build linux,cgo | ||
|
||
package cmds | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/containerd/containerd/sys" | ||
"github.com/containerd/containerd/pkg/userns" | ||
"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 && !sys.RunningInUserNS() { | ||
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 errors.Wrap(err, "failed to evacuate root cgroup") | ||
} | ||
} | ||
return nil | ||
} | ||
} |