vendor c/psgo@v1.3.2

Now supports cgroupsv2.

Fixes: #4192
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
Valentin Rothberg
2019-10-04 17:16:35 +02:00
parent 589261f275
commit 6e0ca9e46c
9 changed files with 150 additions and 25 deletions

View File

@@ -0,0 +1,44 @@
// Copyright 2019 psgo authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cgroups
import (
"sync"
"syscall"
)
const (
CgroupRoot = "/sys/fs/cgroup"
cgroup2SuperMagic = 0x63677270
)
var (
isUnifiedOnce sync.Once
isUnified bool
isUnifiedErr error
)
// IsCgroup2UnifiedMode returns whether we are running in cgroup or cgroupv2 mode.
func IsCgroup2UnifiedMode() (bool, error) {
isUnifiedOnce.Do(func() {
var st syscall.Statfs_t
if err := syscall.Statfs(CgroupRoot, &st); err != nil {
isUnified, isUnifiedErr = false, err
} else {
isUnified, isUnifiedErr = st.Type == cgroup2SuperMagic, nil
}
})
return isUnified, isUnifiedErr
}