Use cgroups.AddProc() for cgroups v1
All occurrences only passed a PID, so we can use this utility to make the code more symmetrical with their cgroups v2 counterparts. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
		| @@ -35,9 +35,7 @@ func setCgroup(cgroupPath string, cmd *exec.Cmd) error { | ||||
| 	if err != nil { | ||||
| 		return fmt.Errorf("failed to load cgroup %s: %w", cgroupPath, err) | ||||
| 	} | ||||
| 	if err := cg.Add(cgroups.Process{ | ||||
| 		Pid: cmd.Process.Pid, | ||||
| 	}); err != nil { | ||||
| 	if err := cg.AddProc(uint64(cmd.Process.Pid)); err != nil { | ||||
| 		return fmt.Errorf("failed to join cgroup %s: %w", cgroupPath, err) | ||||
| 	} | ||||
| 	return nil | ||||
|   | ||||
| @@ -221,9 +221,7 @@ func (manager) Start(ctx context.Context, id string, opts shim.StartOpts) (_ str | ||||
| 						if err != nil { | ||||
| 							return "", fmt.Errorf("failed to load cgroup %s: %w", opts.ShimCgroup, err) | ||||
| 						} | ||||
| 						if err := cg.Add(cgroups.Process{ | ||||
| 							Pid: cmd.Process.Pid, | ||||
| 						}); err != nil { | ||||
| 						if err := cg.AddProc(uint64(cmd.Process.Pid)); err != nil { | ||||
| 							return "", fmt.Errorf("failed to join cgroup %s: %w", opts.ShimCgroup, err) | ||||
| 						} | ||||
| 					} | ||||
|   | ||||
| @@ -207,9 +207,7 @@ func (s *service) StartShim(ctx context.Context, opts shim.StartOpts) (_ string, | ||||
| 					if err != nil { | ||||
| 						return "", fmt.Errorf("failed to load cgroup %s: %w", opts.ShimCgroup, err) | ||||
| 					} | ||||
| 					if err := cg.Add(cgroups.Process{ | ||||
| 						Pid: cmd.Process.Pid, | ||||
| 					}); err != nil { | ||||
| 					if err := cg.AddProc(uint64(cmd.Process.Pid)); err != nil { | ||||
| 						return "", fmt.Errorf("failed to join cgroup %s: %w", opts.ShimCgroup, err) | ||||
| 					} | ||||
| 				} | ||||
|   | ||||
| @@ -56,9 +56,7 @@ func apply(ctx context.Context, config *srvconfig.Config) error { | ||||
| 					return err | ||||
| 				} | ||||
| 			} | ||||
| 			if err := cg.Add(cgroups.Process{ | ||||
| 				Pid: os.Getpid(), | ||||
| 			}); err != nil { | ||||
| 			if err := cg.AddProc(uint64(os.Getpid())); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 		} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Sebastiaan van Stijn
					Sebastiaan van Stijn