mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-24 04:36:38 +00:00
57dc742c76
Bumps [github.com/KimMachineGun/automemlimit](https://github.com/KimMachineGun/automemlimit) from 0.2.4 to 0.2.5. - [Release notes](https://github.com/KimMachineGun/automemlimit/releases) - [Commits](https://github.com/KimMachineGun/automemlimit/compare/v0.2.4...v0.2.5) --- updated-dependencies: - dependency-name: github.com/KimMachineGun/automemlimit dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
61 lines
1.8 KiB
Go
61 lines
1.8 KiB
Go
/*
|
|
Copyright The containerd 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 cgroup2
|
|
|
|
import (
|
|
"fmt"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
// NestedGroupPath will nest the cgroups based on the calling processes cgroup
|
|
// placing its child processes inside its own path
|
|
func NestedGroupPath(suffix string) (string, error) {
|
|
path, err := parseCgroupFile("/proc/self/cgroup")
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return filepath.Join(path, suffix), nil
|
|
}
|
|
|
|
// PidGroupPath will return the correct cgroup paths for an existing process running inside a cgroup
|
|
// This is commonly used for the Load function to restore an existing container
|
|
func PidGroupPath(pid int) (string, error) {
|
|
p := fmt.Sprintf("/proc/%d/cgroup", pid)
|
|
return parseCgroupFile(p)
|
|
}
|
|
|
|
// VerifyGroupPath verifies the format of group path string g.
|
|
// The format is same as the third field in /proc/PID/cgroup.
|
|
// e.g. "/user.slice/user-1001.slice/session-1.scope"
|
|
//
|
|
// g must be a "clean" absolute path starts with "/", and must not contain "/sys/fs/cgroup" prefix.
|
|
//
|
|
// VerifyGroupPath doesn't verify whether g actually exists on the system.
|
|
func VerifyGroupPath(g string) error {
|
|
if !strings.HasPrefix(g, "/") {
|
|
return ErrInvalidGroupPath
|
|
}
|
|
if filepath.Clean(g) != g {
|
|
return ErrInvalidGroupPath
|
|
}
|
|
if strings.HasPrefix(g, "/sys/fs/cgroup") {
|
|
return ErrInvalidGroupPath
|
|
}
|
|
return nil
|
|
}
|