2018-03-20 02:54:29 +00:00
|
|
|
package container
|
2016-04-15 06:42:40 +00:00
|
|
|
|
2018-03-20 02:54:29 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/opencontainers/runc/libcontainer/configs"
|
|
|
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
|
|
|
)
|
2016-04-15 06:42:40 +00:00
|
|
|
|
|
|
|
const (
|
2018-03-20 02:21:14 +00:00
|
|
|
rLimitCPU = iota // CPU time in sec
|
|
|
|
rLimitFsize // Maximum filesize
|
|
|
|
rLimitData // max data size
|
|
|
|
rLimitStack // max stack size
|
|
|
|
rLimitCore // max core file size
|
|
|
|
rLimitRss // max resident set size
|
|
|
|
rLimitNproc // max number of processes
|
|
|
|
rLimitNofile // max number of open files
|
|
|
|
rLimitMemlock // max locked-in-memory address space
|
|
|
|
rLimitAs // address space limit
|
|
|
|
rLimitLocks // maximum file locks held
|
|
|
|
rLimitSigpending // max number of pending signals
|
|
|
|
rLimitMsgqueue // maximum bytes in POSIX mqueues
|
|
|
|
rLimitNice // max nice prio allowed to raise to
|
|
|
|
rLimitRtprio // maximum realtime priority
|
|
|
|
rLimitRttime // timeout for RT tasks in us
|
2016-04-15 06:42:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var rlimitMap = map[string]int{
|
2018-03-20 02:21:14 +00:00
|
|
|
"RLIMIT_CPU": rLimitCPU,
|
|
|
|
"RLIMIT_FSIZE": rLimitFsize,
|
|
|
|
"RLIMIT_DATA": rLimitData,
|
|
|
|
"RLIMIT_STACK": rLimitStack,
|
|
|
|
"RLIMIT_CORE": rLimitCore,
|
|
|
|
"RLIMIT_RSS": rLimitRss,
|
|
|
|
"RLIMIT_NPROC": rLimitNproc,
|
|
|
|
"RLIMIT_NOFILE": rLimitNofile,
|
|
|
|
"RLIMIT_MEMLOCK": rLimitMemlock,
|
|
|
|
"RLIMIT_AS": rLimitAs,
|
|
|
|
"RLIMIT_LOCKS": rLimitLocks,
|
|
|
|
"RLIMIT_SIGPENDING": rLimitSigpending,
|
|
|
|
"RLIMIT_MSGQUEUE": rLimitMsgqueue,
|
|
|
|
"RLIMIT_NICE": rLimitNice,
|
|
|
|
"RLIMIT_RTPRIO": rLimitRtprio,
|
|
|
|
"RLIMIT_RTTIME": rLimitRttime,
|
2016-04-15 06:42:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func strToRlimit(key string) (int, error) {
|
|
|
|
rl, ok := rlimitMap[key]
|
|
|
|
if !ok {
|
2018-03-20 01:44:18 +00:00
|
|
|
return 0, fmt.Errorf("wrong rlimit value: %s", key)
|
2016-04-15 06:42:40 +00:00
|
|
|
}
|
|
|
|
return rl, nil
|
|
|
|
}
|
2018-03-20 02:54:29 +00:00
|
|
|
|
|
|
|
func createLibContainerRlimit(rlimit specs.POSIXRlimit) (configs.Rlimit, error) {
|
|
|
|
rl, err := strToRlimit(rlimit.Type)
|
|
|
|
if err != nil {
|
|
|
|
return configs.Rlimit{}, err
|
|
|
|
}
|
|
|
|
return configs.Rlimit{
|
|
|
|
Type: rl,
|
|
|
|
Hard: rlimit.Hard,
|
|
|
|
Soft: rlimit.Soft,
|
|
|
|
}, nil
|
|
|
|
}
|