github.com/georgethebeatle/containerd@v0.2.5/api/grpc/server/server_linux.go (about) 1 package server 2 3 import ( 4 "fmt" 5 6 "github.com/docker/containerd/api/grpc/types" 7 "github.com/docker/containerd/specs" 8 "github.com/docker/containerd/supervisor" 9 "github.com/opencontainers/runc/libcontainer/system" 10 ocs "github.com/opencontainers/runtime-spec/specs-go" 11 "golang.org/x/net/context" 12 ) 13 14 var clockTicksPerSecond = uint64(system.GetClockTicks()) 15 16 func (s *apiServer) AddProcess(ctx context.Context, r *types.AddProcessRequest) (*types.AddProcessResponse, error) { 17 process := &specs.ProcessSpec{ 18 Terminal: r.Terminal, 19 Args: r.Args, 20 Env: r.Env, 21 Cwd: r.Cwd, 22 } 23 process.User = ocs.User{ 24 UID: r.User.Uid, 25 GID: r.User.Gid, 26 AdditionalGids: r.User.AdditionalGids, 27 } 28 process.Capabilities = r.Capabilities 29 process.ApparmorProfile = r.ApparmorProfile 30 process.SelinuxLabel = r.SelinuxLabel 31 process.NoNewPrivileges = r.NoNewPrivileges 32 for _, rl := range r.Rlimits { 33 process.Rlimits = append(process.Rlimits, ocs.Rlimit{ 34 Type: rl.Type, 35 Soft: rl.Soft, 36 Hard: rl.Hard, 37 }) 38 } 39 if r.Id == "" { 40 return nil, fmt.Errorf("container id cannot be empty") 41 } 42 if r.Pid == "" { 43 return nil, fmt.Errorf("process id cannot be empty") 44 } 45 e := &supervisor.AddProcessTask{} 46 e.ID = r.Id 47 e.PID = r.Pid 48 e.ProcessSpec = process 49 e.Stdin = r.Stdin 50 e.Stdout = r.Stdout 51 e.Stderr = r.Stderr 52 e.StartResponse = make(chan supervisor.StartResponse, 1) 53 s.sv.SendTask(e) 54 if err := <-e.ErrorCh(); err != nil { 55 return nil, err 56 } 57 <-e.StartResponse 58 return &types.AddProcessResponse{}, nil 59 }