-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move cgroupsv1 out into package
- Loading branch information
Showing
2 changed files
with
48 additions
and
18 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,34 @@ | ||
package cgroups | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/containerd/cgroups/v3/cgroup1" | ||
"github.com/opencontainers/runtime-spec/specs-go" | ||
) | ||
|
||
func AddV1( | ||
path string, | ||
devices []specs.LinuxDeviceCgroup, | ||
pid int, | ||
) error { | ||
|
||
staticPath := cgroup1.StaticPath(path) | ||
|
||
cg, err := cgroup1.New( | ||
staticPath, | ||
&specs.LinuxResources{ | ||
Devices: devices, | ||
}, | ||
) | ||
if err != nil { | ||
return fmt.Errorf("create cgroups (path: %s): %w", path, err) | ||
} | ||
defer cg.Delete() | ||
|
||
if err := cg.Add(cgroup1.Process{Pid: pid}); err != nil { | ||
return fmt.Errorf("add cgroups (path: %s, pid: %d): %w", path, pid, err) | ||
} | ||
|
||
return nil | ||
} |
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