From 5b09a71228a4f4e22a8e55b318000b918dc65fd2 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 29 Jun 2024 17:53:53 +0200 Subject: [PATCH] libct/userns: change RunningInUserNS to a wrapper instead of an alias This was a poor decision on my side; 4316df8b53cce2933d7f0f3cf4bf87da67459835 moved this utility to a separate package, and split the exported function from the implementation (and stubs). Out of convenience, I used an alias for the latter part, but there's two downsides to that; - `RunningInUserNS` being an exported var means that (technically) it can be replaced by other code; perhaps that's a "feature", but not one we intended it to be used for. - `RunningInUserNS` being implemented through a var / alias means it's also documented as such on [pkg.go.dev], which is confusing. This patch changes it to a regular function, acting as a wrapper for the underlying implementations. While at it, also slightly touching up the GoDoc to describe its functionality / behavior. [pkg.go.dev]: https://pkg.go.dev/github.com/opencontainers/runc@v1.1.13/libcontainer/userns#RunningInUserNS Signed-off-by: Sebastiaan van Stijn --- libcontainer/userns/userns.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libcontainer/userns/userns.go b/libcontainer/userns/userns.go index b225f18f2..069a9bb28 100644 --- a/libcontainer/userns/userns.go +++ b/libcontainer/userns/userns.go @@ -1,4 +1,8 @@ package userns -// RunningInUserNS detects whether we are currently running in a user namespace. -var RunningInUserNS = runningInUserNS +// RunningInUserNS detects whether we are currently running in a Linux +// user namespace and memoizes the result. It returns false on non-Linux +// platforms. +func RunningInUserNS() bool { + return runningInUserNS() +}