libcontainer/system: move userns utilities to separate package

Moving these utilities to a separate package, so that consumers of this
package don't have to pull in the whole "system" package.

Looking at uses of these utilities (outside of runc itself);

`RunningInUserNS()` is used by [various external consumers][1],
so adding a "Deprecated" alias for this.

[1]: https://grep.app/search?current=2&q=.RunningInUserNS

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2021-03-13 16:40:51 +01:00
parent e7fd383bce
commit 4316df8b53
15 changed files with 70 additions and 57 deletions
+3 -3
View File
@@ -6,7 +6,7 @@ import (
"os"
"github.com/opencontainers/runc/libcontainer/cgroups/systemd"
"github.com/opencontainers/runc/libcontainer/system"
"github.com/opencontainers/runc/libcontainer/userns"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
@@ -25,7 +25,7 @@ func shouldUseRootlessCgroupManager(context *cli.Context) (bool, error) {
if os.Geteuid() != 0 {
return true, nil
}
if !system.RunningInUserNS() {
if !userns.RunningInUserNS() {
// euid == 0 , in the initial ns (i.e. the real root)
return false, nil
}
@@ -60,7 +60,7 @@ func shouldHonorXDGRuntimeDir() bool {
if os.Geteuid() != 0 {
return true
}
if !system.RunningInUserNS() {
if !userns.RunningInUserNS() {
// euid == 0 , in the initial ns (i.e. the real root)
// in this case, we should use /run/runc and ignore
// $XDG_RUNTIME_DIR (e.g. /run/user/0) for backward