 9f5182f394
			
		
	
	9f5182f394
	
	
	
		
			
			This allows other packages and plugins to easily exec things without racing with the reaper. The reaper is mostly needed in the shim but can be removed in containerd in favor of the `exec.Cmd` apis Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
		
			
				
	
	
		
			39 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package server
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 	"os"
 | |
| 
 | |
| 	"github.com/containerd/cgroups"
 | |
| 	"github.com/containerd/containerd/log"
 | |
| 	"github.com/containerd/containerd/sys"
 | |
| 	specs "github.com/opencontainers/runtime-spec/specs-go"
 | |
| )
 | |
| 
 | |
| // apply sets config settings on the server process
 | |
| func apply(ctx context.Context, config *Config) error {
 | |
| 	if config.OOMScore != 0 {
 | |
| 		log.G(ctx).Debugf("changing OOM score to %d", config.OOMScore)
 | |
| 		if err := sys.SetOOMScore(os.Getpid(), config.OOMScore); err != nil {
 | |
| 			log.G(ctx).WithError(err).Errorf("failed to change OOM score to %d", config.OOMScore)
 | |
| 		}
 | |
| 	}
 | |
| 	if config.Cgroup.Path != "" {
 | |
| 		cg, err := cgroups.Load(cgroups.V1, cgroups.StaticPath(config.Cgroup.Path))
 | |
| 		if err != nil {
 | |
| 			if err != cgroups.ErrCgroupDeleted {
 | |
| 				return err
 | |
| 			}
 | |
| 			if cg, err = cgroups.New(cgroups.V1, cgroups.StaticPath(config.Cgroup.Path), &specs.LinuxResources{}); err != nil {
 | |
| 				return err
 | |
| 			}
 | |
| 		}
 | |
| 		if err := cg.Add(cgroups.Process{
 | |
| 			Pid: os.Getpid(),
 | |
| 		}); err != nil {
 | |
| 			return err
 | |
| 		}
 | |
| 	}
 | |
| 	return nil
 | |
| }
 |