Merge pull request #5738 from thaJeztah/simplify_cgroup_add

Use cgroups.AddProc() for cgroups v1
This commit is contained in:
Akihiro Suda 2022-03-25 10:24:43 +09:00 committed by GitHub
commit eaf7929320
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 4 additions and 12 deletions

View File

@ -35,9 +35,7 @@ func setCgroup(cgroupPath string, cmd *exec.Cmd) error {
if err != nil { if err != nil {
return fmt.Errorf("failed to load cgroup %s: %w", cgroupPath, err) return fmt.Errorf("failed to load cgroup %s: %w", cgroupPath, err)
} }
if err := cg.Add(cgroups.Process{ if err := cg.AddProc(uint64(cmd.Process.Pid)); err != nil {
Pid: cmd.Process.Pid,
}); err != nil {
return fmt.Errorf("failed to join cgroup %s: %w", cgroupPath, err) return fmt.Errorf("failed to join cgroup %s: %w", cgroupPath, err)
} }
return nil return nil

View File

@ -221,9 +221,7 @@ func (manager) Start(ctx context.Context, id string, opts shim.StartOpts) (_ str
if err != nil { if err != nil {
return "", fmt.Errorf("failed to load cgroup %s: %w", opts.ShimCgroup, err) return "", fmt.Errorf("failed to load cgroup %s: %w", opts.ShimCgroup, err)
} }
if err := cg.Add(cgroups.Process{ if err := cg.AddProc(uint64(cmd.Process.Pid)); err != nil {
Pid: cmd.Process.Pid,
}); err != nil {
return "", fmt.Errorf("failed to join cgroup %s: %w", opts.ShimCgroup, err) return "", fmt.Errorf("failed to join cgroup %s: %w", opts.ShimCgroup, err)
} }
} }

View File

@ -207,9 +207,7 @@ func (s *service) StartShim(ctx context.Context, opts shim.StartOpts) (_ string,
if err != nil { if err != nil {
return "", fmt.Errorf("failed to load cgroup %s: %w", opts.ShimCgroup, err) return "", fmt.Errorf("failed to load cgroup %s: %w", opts.ShimCgroup, err)
} }
if err := cg.Add(cgroups.Process{ if err := cg.AddProc(uint64(cmd.Process.Pid)); err != nil {
Pid: cmd.Process.Pid,
}); err != nil {
return "", fmt.Errorf("failed to join cgroup %s: %w", opts.ShimCgroup, err) return "", fmt.Errorf("failed to join cgroup %s: %w", opts.ShimCgroup, err)
} }
} }

View File

@ -56,9 +56,7 @@ func apply(ctx context.Context, config *srvconfig.Config) error {
return err return err
} }
} }
if err := cg.Add(cgroups.Process{ if err := cg.AddProc(uint64(os.Getpid())); err != nil {
Pid: os.Getpid(),
}); err != nil {
return err return err
} }
} }