open-nomad/client/lib/cgutil/editor.go
Seth Hoenig 5d5c8af930 cgroups: refactor v2 kill path to use cgroups.kill interface file
This PR refactors the cgroups v2 group kill code path to use the
cgroups.kill interface file for destroying the cgroup. Previously
we copied the freeze + sigkill + unfreeze pattern from the v1 code,
but v2 provides a more efficient and more race-free way to handle
this.

Closes #14371
2022-08-29 14:55:13 -05:00

28 lines
545 B
Go

//go:build linux
package cgutil
import (
"os"
"path/filepath"
"strings"
)
// editor provides a simple mechanism for reading and writing cgroup files.
type editor struct {
fromRoot string
}
func (e *editor) path(file string) string {
return filepath.Join(CgroupRoot, e.fromRoot, file)
}
func (e *editor) write(file, content string) error {
return os.WriteFile(e.path(file), []byte(content), 0o644)
}
func (e *editor) read(file string) (string, error) {
b, err := os.ReadFile(e.path(file))
return strings.TrimSpace(string(b)), err
}