daemon: improve handling of ROOTLESSKIT_PARENT_EUID
- daemon.WithRootless(): make sure ROOTLESSKIT_PARENT_EUID is valid int - daemon.RawSysInfo(): minor simplification, and rename variable that clashed with imported package. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
8dbd90ec00
commit
aa4dce742f
2 changed files with 9 additions and 7 deletions
|
@ -1712,15 +1712,13 @@ func (daemon *Daemon) setupSeccompProfile() error {
|
|||
|
||||
// RawSysInfo returns *sysinfo.SysInfo .
|
||||
func (daemon *Daemon) RawSysInfo(quiet bool) *sysinfo.SysInfo {
|
||||
var opts []sysinfo.Opt
|
||||
var siOpts []sysinfo.Opt
|
||||
if daemon.getCgroupDriver() == cgroupSystemdDriver {
|
||||
rootlesskitParentEUID := os.Getenv("ROOTLESSKIT_PARENT_EUID")
|
||||
if rootlesskitParentEUID != "" {
|
||||
groupPath := fmt.Sprintf("/user.slice/user-%s.slice", rootlesskitParentEUID)
|
||||
opts = append(opts, sysinfo.WithCgroup2GroupPath(groupPath))
|
||||
if euid := os.Getenv("ROOTLESSKIT_PARENT_EUID"); euid != "" {
|
||||
siOpts = append(siOpts, sysinfo.WithCgroup2GroupPath("/user.slice/user-"+euid+".slice"))
|
||||
}
|
||||
}
|
||||
return sysinfo.New(quiet, opts...)
|
||||
return sysinfo.New(quiet, siOpts...)
|
||||
}
|
||||
|
||||
func recursiveUnmount(target string) error {
|
||||
|
|
|
@ -97,7 +97,11 @@ func WithRootless(daemon *Daemon) coci.SpecOpts {
|
|||
if rootlesskitParentEUID == "" {
|
||||
return errors.New("$ROOTLESSKIT_PARENT_EUID is not set (requires RootlessKit v0.8.0)")
|
||||
}
|
||||
controllersPath := fmt.Sprintf("/sys/fs/cgroup/user.slice/user-%s.slice/cgroup.controllers", rootlesskitParentEUID)
|
||||
euid, err := strconv.Atoi(rootlesskitParentEUID)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "invalid $ROOTLESSKIT_PARENT_EUID: must be a numeric value")
|
||||
}
|
||||
controllersPath := fmt.Sprintf("/sys/fs/cgroup/user.slice/user-%d.slice/cgroup.controllers", euid)
|
||||
controllersFile, err := ioutil.ReadFile(controllersPath)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Add table
Reference in a new issue