diff options
author | Giuseppe Scrivano <gscrivan@redhat.com> | 2020-07-17 13:58:22 +0200 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2020-07-22 14:05:20 -0400 |
commit | e21a6368f9308292641ed5ce58321b1cd46abdc9 (patch) | |
tree | 3965dc2cfc5cea33cb04b10cf528f7570f3b38f5 /cmd/podman | |
parent | 92186cbd28df57bda027c90eb3715c8a636c1037 (diff) | |
download | podman-e21a6368f9308292641ed5ce58321b1cd46abdc9.tar.gz podman-e21a6368f9308292641ed5ce58321b1cd46abdc9.tar.bz2 podman-e21a6368f9308292641ed5ce58321b1cd46abdc9.zip |
abi: set default umask and rlimits
the code got lost in the migration to podman 2.0, reintroduce it.
Closes: https://github.com/containers/podman/issues/6989
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
<MH: Fixed build>
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'cmd/podman')
-rw-r--r-- | cmd/podman/early_init_linux.go | 39 | ||||
-rw-r--r-- | cmd/podman/early_init_unsupported.go | 6 | ||||
-rw-r--r-- | cmd/podman/root.go | 1 |
3 files changed, 46 insertions, 0 deletions
diff --git a/cmd/podman/early_init_linux.go b/cmd/podman/early_init_linux.go new file mode 100644 index 000000000..b43450a7f --- /dev/null +++ b/cmd/podman/early_init_linux.go @@ -0,0 +1,39 @@ +package main + +import ( + "fmt" + "os" + "syscall" + + "github.com/containers/libpod/v2/libpod/define" + "github.com/pkg/errors" +) + +func setRLimits() error { + rlimits := new(syscall.Rlimit) + rlimits.Cur = define.RLimitDefaultValue + rlimits.Max = define.RLimitDefaultValue + if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, rlimits); err != nil { + if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, rlimits); err != nil { + return errors.Wrapf(err, "error getting rlimits") + } + rlimits.Cur = rlimits.Max + if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, rlimits); err != nil { + return errors.Wrapf(err, "error setting new rlimits") + } + } + return nil +} + +func setUMask() { + // Be sure we can create directories with 0755 mode. + syscall.Umask(0022) +} + +func earlyInitHook() { + if err := setRLimits(); err != nil { + fmt.Fprint(os.Stderr, "Failed to set rlimits: "+err.Error()) + } + + setUMask() +} diff --git a/cmd/podman/early_init_unsupported.go b/cmd/podman/early_init_unsupported.go new file mode 100644 index 000000000..4e748559f --- /dev/null +++ b/cmd/podman/early_init_unsupported.go @@ -0,0 +1,6 @@ +// +build !linux + +package main + +func earlyInitHook() { +} diff --git a/cmd/podman/root.go b/cmd/podman/root.go index 7c54da91a..b2c9f9c2c 100644 --- a/cmd/podman/root.go +++ b/cmd/podman/root.go @@ -77,6 +77,7 @@ func init() { cobra.OnInitialize( loggingHook, syslogHook, + earlyInitHook, ) rootFlags(rootCmd, registry.PodmanConfig()) |