From a40602bdb5c20ff865c8207c50cb03597faa7ca7 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 16 Jul 2024 19:59:34 +0200 Subject: [PATCH] user/userns: add godoc for package Signed-off-by: Sebastiaan van Stijn --- user/userns/userns.go | 8 ++++++++ user/userns/userns_linux.go | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/user/userns/userns.go b/user/userns/userns.go index a07afe0..56b24c4 100644 --- a/user/userns/userns.go +++ b/user/userns/userns.go @@ -1,3 +1,11 @@ +// Package userns provides utilities to detect whether we are currently running +// in a Linux user namespace. +// +// This code was migrated from [libcontainer/runc], which based its implementation +// on code from [lcx/incus]. +// +// [libcontainer/runc]: https://github.com/opencontainers/runc/blob/3778ae603c706494fd1e2c2faf83b406e38d687d/libcontainer/userns/userns_linux.go#L12-L49 +// [lcx/incus]: https://github.com/lxc/incus/blob/e45085dd42f826b3c8c3228e9733c0b6f998eafe/shared/util.go#L678-L700 package userns // RunningInUserNS detects whether we are currently running in a Linux diff --git a/user/userns/userns_linux.go b/user/userns/userns_linux.go index a1462e1..87c1c38 100644 --- a/user/userns/userns_linux.go +++ b/user/userns/userns_linux.go @@ -11,7 +11,11 @@ var inUserNS = sync.OnceValue(runningInUserNS) // runningInUserNS detects whether we are currently running in a user namespace. // -// Originally copied from https://github.com/lxc/incus/blob/e45085dd42f826b3c8c3228e9733c0b6f998eafe/shared/util.go#L678-L700. +// This code was migrated from [libcontainer/runc] and based on an implementation +// from [lcx/incus]. +// +// [libcontainer/runc]: https://github.com/opencontainers/runc/blob/3778ae603c706494fd1e2c2faf83b406e38d687d/libcontainer/userns/userns_linux.go#L12-L49 +// [lcx/incus]: https://github.com/lxc/incus/blob/e45085dd42f826b3c8c3228e9733c0b6f998eafe/shared/util.go#L678-L700 func runningInUserNS() bool { file, err := os.Open("/proc/self/uid_map") if err != nil {