-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To extract the PIDs in the container, we're looking at procs controller of the cgroup. Add an on-demand check for the cgroups mode and a pids extractor for v2. Fixes: containers/podman/issues/4192 Signed-off-by: Valentin Rothberg <[email protected]>
- Loading branch information
Showing
2 changed files
with
111 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
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