From 1e3ff6950269cb7fdb1c9ac161cf1aabf4933326 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Wed, 14 Nov 2018 10:13:47 +0100 Subject: 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 --- pkg/rootless/rootless_linux.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'pkg/rootless') 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 ( -- cgit v1.2.3-54-g00ecf