MCPcopy
hub / github.com/apptainer/apptainer / UserNamespace

Function UserNamespace

internal/pkg/test/tool/require/require.go:44–66  ·  view source on GitHub ↗

UserNamespace checks that the current test could use user namespace, if user namespaces are not enabled or supported, the current test is skipped with a message.

(t *testing.T)

Source from the content-addressed store, hash-verified

42// user namespace, if user namespaces are not enabled or
43// supported, the current test is skipped with a message.
44func UserNamespace(t *testing.T) {
45 // not performance critical, just save extra execution
46 // to get the same result
47 hasUserNamespaceOnce.Do(func() {
48 // user namespace is a bit special, as there is no simple
49 // way to detect if it's supported or enabled via a call
50 // on /proc/self/ns/user, the easiest and reliable way seems
51 // to directly execute a command by requesting user namespace
52 cmd := exec.Command("/bin/true")
53 cmd.SysProcAttr = &syscall.SysProcAttr{
54 Cloneflags: syscall.CLONE_NEWUSER,
55 }
56 // no error means user namespaces are enabled
57 err := cmd.Run()
58 hasUserNamespace = err == nil
59 if !hasUserNamespace {
60 t.Logf("Could not use user namespaces: %s", err)
61 }
62 })
63 if !hasUserNamespace {
64 t.Skipf("user namespaces seems not enabled or supported")
65 }
66}
67
68var (
69 supportNetwork bool

Callers 1

fakerootRequirementsFunction · 0.92

Calls 2

RunMethod · 0.45
LogfMethod · 0.45

Tested by

no test coverage detected