(context *cli.Context)
| 11 | ) |
| 12 | |
| 13 | func shouldUseRootlessCgroupManager(context *cli.Context) (bool, error) { |
| 14 | if context != nil { |
| 15 | b, err := parseBoolOrAuto(context.GlobalString("rootless")) |
| 16 | if err != nil { |
| 17 | return false, err |
| 18 | } |
| 19 | // nil b stands for "auto detect" |
| 20 | if b != nil { |
| 21 | return *b, nil |
| 22 | } |
| 23 | } |
| 24 | if os.Geteuid() != 0 { |
| 25 | return true, nil |
| 26 | } |
| 27 | if !userns.RunningInUserNS() { |
| 28 | // euid == 0 , in the initial ns (i.e. the real root) |
| 29 | return false, nil |
| 30 | } |
| 31 | // euid = 0, in a userns. |
| 32 | // |
| 33 | // [systemd driver] |
| 34 | // We can call DetectUID() to parse the OwnerUID value from `busctl --user --no-pager status` result. |
| 35 | // The value corresponds to sd_bus_creds_get_owner_uid(3). |
| 36 | // If the value is 0, we have rootful systemd inside userns, so we do not need the rootless cgroup manager. |
| 37 | // |
| 38 | // On error, we assume we are root. An error may happen during shelling out to `busctl` CLI, |
| 39 | // mostly when $DBUS_SESSION_BUS_ADDRESS is unset. |
| 40 | if context.GlobalBool("systemd-cgroup") { |
| 41 | ownerUID, err := systemd.DetectUID() |
| 42 | if err != nil { |
| 43 | logrus.WithError(err).Debug("failed to get the OwnerUID value, assuming the value to be 0") |
| 44 | ownerUID = 0 |
| 45 | } |
| 46 | return ownerUID != 0, nil |
| 47 | } |
| 48 | // [cgroupfs driver] |
| 49 | // As we are unaware of cgroups path, we can't determine whether we have the full |
| 50 | // access to the cgroups path. |
| 51 | // Either way, we can safely decide to use the rootless cgroups manager. |
| 52 | return true, nil |
| 53 | } |
| 54 | |
| 55 | func shouldHonorXDGRuntimeDir() bool { |
| 56 | if os.Geteuid() != 0 { |
no test coverage detected
searching dependent graphs…