File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 5
5
require (
6
6
github.com/sirupsen/logrus v1.5.0
7
7
github.com/spf13/cobra v0.0.6
8
+ golang.org/x/sys v0.0.0-20190422165155-953cdadca894
8
9
)
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import (
25
25
26
26
"github.com/containers/toolbox/pkg/shell"
27
27
"github.com/sirupsen/logrus"
28
+ "golang.org/x/sys/unix"
28
29
)
29
30
30
31
var (
@@ -83,6 +84,25 @@ func ForwardToHost() (int, error) {
83
84
return exitCode , nil
84
85
}
85
86
87
+ // GetCgroupsVersion returns the cgroups version of the host
88
+ //
89
+ // Based on the IsCgroup2UnifiedMode function in:
90
+ // https://github.com/containers/libpod/tree/master/pkg/cgroups
91
+ func GetCgroupsVersion () (int , error ) {
92
+ var st syscall.Statfs_t
93
+
94
+ if err := syscall .Statfs ("/sys/fs/cgroup" , & st ); err != nil {
95
+ return - 1 , err
96
+ }
97
+
98
+ version := 1
99
+ if st .Type == unix .CGROUP2_SUPER_MAGIC {
100
+ version = 2
101
+ }
102
+
103
+ return version , nil
104
+ }
105
+
86
106
func GetEnvOptionsForPreservedVariables () []string {
87
107
logrus .Debug ("Creating list of environment variables to forward" )
88
108
You can’t perform that action at this time.
0 commit comments