server_linux.go 1.5 KB

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