summaryrefslogtreecommitdiff
path: root/pkg/spec/spec_linux.go
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivan@redhat.com>2019-07-03 18:18:02 +0200
committerGiuseppe Scrivano <gscrivan@redhat.com>2019-07-08 19:22:54 +0200
commitfb88074e68db25474290535e8a778e39434cc2a2 (patch)
treea2938cf4f442823ba25ddf6755eca68f75458761 /pkg/spec/spec_linux.go
parent1055b22e9b900e5f4d41f39b506de4f2d1aa2f8e (diff)
downloadpodman-fb88074e68db25474290535e8a778e39434cc2a2.tar.gz
podman-fb88074e68db25474290535e8a778e39434cc2a2.tar.bz2
podman-fb88074e68db25474290535e8a778e39434cc2a2.zip
podman: add --ulimit host
add a simple way to copy ulimit values from the host. if --ulimit host is used then the current ulimits in place are copied to the container. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Diffstat (limited to 'pkg/spec/spec_linux.go')
-rw-r--r--pkg/spec/spec_linux.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/pkg/spec/spec_linux.go b/pkg/spec/spec_linux.go
new file mode 100644
index 000000000..fcdfc5c4e
--- /dev/null
+++ b/pkg/spec/spec_linux.go
@@ -0,0 +1,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
+
+}