...
1 package main
2
3 import (
4 "os"
5
6 "github.com/opencontainers/runc/libcontainer/cgroups/systemd"
7 "github.com/opencontainers/runc/libcontainer/userns"
8 "github.com/sirupsen/logrus"
9 "github.com/urfave/cli"
10 )
11
12 func shouldUseRootlessCgroupManager(context *cli.Context) (bool, error) {
13 if context != nil {
14 b, err := parseBoolOrAuto(context.GlobalString("rootless"))
15 if err != nil {
16 return false, err
17 }
18
19 if b != nil {
20 return *b, nil
21 }
22 }
23 if os.Geteuid() != 0 {
24 return true, nil
25 }
26 if !userns.RunningInUserNS() {
27
28 return false, nil
29 }
30
31
32
33
34
35
36
37
38
39 if context.GlobalBool("systemd-cgroup") {
40 ownerUID, err := systemd.DetectUID()
41 if err != nil {
42 logrus.WithError(err).Debug("failed to get the OwnerUID value, assuming the value to be 0")
43 ownerUID = 0
44 }
45 return ownerUID != 0, nil
46 }
47
48
49
50
51 return true, nil
52 }
53
54 func shouldHonorXDGRuntimeDir() bool {
55 if os.Getenv("XDG_RUNTIME_DIR") == "" {
56 return false
57 }
58 if os.Geteuid() != 0 {
59 return true
60 }
61 if !userns.RunningInUserNS() {
62
63
64
65
66 return false
67 }
68
69 u, ok := os.LookupEnv("USER")
70 return !ok || u != "root"
71 }
72
View as plain text