From 333fe311f6169794258dfea8e688e33c5503111e 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; ab29593e7b0392c30a04c97cf889b575ed419aad 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 --- user/userns/userns.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/user/userns/userns.go b/user/userns/userns.go index b225f18..069a9bb 100644 --- a/user/userns/userns.go +++ b/user/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() +}