aboutsummaryrefslogtreecommitdiff
path: root/pkg/rootless
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivan@redhat.com>2018-11-14 10:13:47 +0100
committerGiuseppe Scrivano <gscrivan@redhat.com>2018-11-14 10:13:50 +0100
commit1e3ff6950269cb7fdb1c9ac161cf1aabf4933326 (patch)
treeeff54904beec62a3b8a5991fa3c687d33cc230a1 /pkg/rootless
parent7965716c74ef249e14f66702cff66baf759f6d68 (diff)
downloadpodman-1e3ff6950269cb7fdb1c9ac161cf1aabf4933326.tar.gz
podman-1e3ff6950269cb7fdb1c9ac161cf1aabf4933326.tar.bz2
podman-1e3ff6950269cb7fdb1c9ac161cf1aabf4933326.zip
rootless: call IsRootless just once
we are calling this function several times, it is worth to store its result and re-use it. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Diffstat (limited to 'pkg/rootless')
-rw-r--r--pkg/rootless/rootless_linux.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/pkg/rootless/rootless_linux.go b/pkg/rootless/rootless_linux.go
index ff8c8fe34..85b0ef392 100644
--- a/pkg/rootless/rootless_linux.go
+++ b/pkg/rootless/rootless_linux.go
@@ -12,6 +12,7 @@ import (
"runtime"
"strconv"
"strings"
+ "sync"
"syscall"
"unsafe"
@@ -33,9 +34,17 @@ func runInUser() error {
return nil
}
+var (
+ isRootlessOnce sync.Once
+ isRootless bool
+)
+
// IsRootless tells us if we are running in rootless mode
func IsRootless() bool {
- return os.Geteuid() != 0 || os.Getenv("_LIBPOD_USERNS_CONFIGURED") != ""
+ isRootlessOnce.Do(func() {
+ isRootless = os.Geteuid() != 0 || os.Getenv("_LIBPOD_USERNS_CONFIGURED") != ""
+ })
+ return isRootless
}
var (