summaryrefslogtreecommitdiff
path: root/pkg/spec/spec_linux.go
blob: fcdfc5c4ecd3f407a414dc9ee0f2fc9808828682 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//+build linux

package createconfig

import (
	"syscall"

	"github.com/pkg/errors"
)

type systemRlimit struct {
	name  string
	value int
}

var systemLimits = []systemRlimit{
	{"RLIMIT_AS", syscall.RLIMIT_AS},
	{"RLIMIT_CORE", syscall.RLIMIT_CORE},
	{"RLIMIT_CPU", syscall.RLIMIT_CPU},
	{"RLIMIT_DATA", syscall.RLIMIT_DATA},
	{"RLIMIT_FSIZE", syscall.RLIMIT_FSIZE},
	{"RLIMIT_NOFILE", syscall.RLIMIT_NOFILE},
	{"RLIMIT_STACK", syscall.RLIMIT_STACK},
}

func getHostRlimits() ([]systemUlimit, error) {
	ret := []systemUlimit{}
	for _, i := range systemLimits {
		var l syscall.Rlimit
		if err := syscall.Getrlimit(i.value, &l); err != nil {
			return nil, errors.Wrapf(err, "cannot read limits for %s", i.name)
		}
		s := systemUlimit{
			name: i.name,
			max:  l.Max,
			cur:  l.Cur,
		}
		ret = append(ret, s)
	}
	return ret, nil

}