rlimit_linux.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package runc
  2. import "fmt"
  3. const (
  4. RLIMIT_CPU = iota // CPU time in sec
  5. RLIMIT_FSIZE // Maximum filesize
  6. RLIMIT_DATA // max data size
  7. RLIMIT_STACK // max stack size
  8. RLIMIT_CORE // max core file size
  9. RLIMIT_RSS // max resident set size
  10. RLIMIT_NPROC // max number of processes
  11. RLIMIT_NOFILE // max number of open files
  12. RLIMIT_MEMLOCK // max locked-in-memory address space
  13. RLIMIT_AS // address space limit
  14. RLIMIT_LOCKS // maximum file locks held
  15. RLIMIT_SIGPENDING // max number of pending signals
  16. RLIMIT_MSGQUEUE // maximum bytes in POSIX mqueues
  17. RLIMIT_NICE // max nice prio allowed to raise to
  18. RLIMIT_RTPRIO // maximum realtime priority
  19. RLIMIT_RTTIME // timeout for RT tasks in us
  20. )
  21. var rlimitMap = map[string]int{
  22. "RLIMIT_CPU": RLIMIT_CPU,
  23. "RLIMIT_FSIZE": RLIMIT_FSIZE,
  24. "RLIMIT_DATA": RLIMIT_DATA,
  25. "RLIMIT_STACK": RLIMIT_STACK,
  26. "RLIMIT_CORE": RLIMIT_CORE,
  27. "RLIMIT_RSS": RLIMIT_RSS,
  28. "RLIMIT_NPROC": RLIMIT_NPROC,
  29. "RLIMIT_NOFILE": RLIMIT_NOFILE,
  30. "RLIMIT_MEMLOCK": RLIMIT_MEMLOCK,
  31. "RLIMIT_AS": RLIMIT_AS,
  32. "RLIMIT_LOCKS": RLIMIT_LOCKS,
  33. "RLIMIT_SIGPENDING": RLIMIT_SIGPENDING,
  34. "RLIMIT_MSGQUEUE": RLIMIT_MSGQUEUE,
  35. "RLIMIT_NICE": RLIMIT_NICE,
  36. "RLIMIT_RTPRIO": RLIMIT_RTPRIO,
  37. "RLIMIT_RTTIME": RLIMIT_RTTIME,
  38. }
  39. func strToRlimit(key string) (int, error) {
  40. rl, ok := rlimitMap[key]
  41. if !ok {
  42. return 0, fmt.Errorf("Wrong rlimit value: %s", key)
  43. }
  44. return rl, nil
  45. }