Skip to content

Commit 48734f2

Browse files
committed
UserConnection is used by non linux platforms
Take this oppurtunity to remove Get prefix on functions in cgroups. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
1 parent 40d88ea commit 48734f2

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

pkg/cgroups/cgroups_linux.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ func getAvailableControllers(exclude map[string]controllerHandler, cgroup2 bool)
135135
return controllers, nil
136136
}
137137

138-
// GetAvailableControllers get string:bool map of all the available controllers
139-
func GetAvailableControllers(exclude map[string]controllerHandler, cgroup2 bool) ([]string, error) {
138+
// AvailableControllers get string:bool map of all the available controllers
139+
func AvailableControllers(exclude map[string]controllerHandler, cgroup2 bool) ([]string, error) {
140140
availableControllers, err := getAvailableControllers(exclude, cgroup2)
141141
if err != nil {
142142
return nil, err
@@ -392,20 +392,13 @@ func (c *CgroupControl) CreateSystemdUnit(path string) error {
392392
return systemdCreate(c.config.Resources, path, conn)
393393
}
394394

395-
// GetUserConnection returns an user connection to D-BUS
396-
func GetUserConnection(uid int) (*systemdDbus.Conn, error) {
397-
return systemdDbus.NewConnection(func() (*dbus.Conn, error) {
398-
return dbusAuthConnection(uid, dbus.SessionBusPrivateNoAutoStartup)
399-
})
400-
}
401-
402395
// CreateSystemdUserUnit creates the systemd cgroup for the specified user
403396
func (c *CgroupControl) CreateSystemdUserUnit(path string, uid int) error {
404397
if !c.systemd {
405398
return fmt.Errorf("the cgroup controller is not using systemd")
406399
}
407400

408-
conn, err := GetUserConnection(uid)
401+
conn, err := UserConnection(uid)
409402
if err != nil {
410403
return err
411404
}

pkg/cgroups/cgroups_supported.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
"syscall"
1616
"time"
1717

18+
systemdDbus "github.com/coreos/go-systemd/v22/dbus"
19+
"github.com/godbus/dbus/v5"
1820
"golang.org/x/sys/unix"
1921
)
2022

@@ -37,6 +39,13 @@ func IsCgroup2UnifiedMode() (bool, error) {
3739
return isUnified, isUnifiedErr
3840
}
3941

42+
// UserConnection returns an user connection to D-BUS
43+
func UserConnection(uid int) (*systemdDbus.Conn, error) {
44+
return systemdDbus.NewConnection(func() (*dbus.Conn, error) {
45+
return dbusAuthConnection(uid, dbus.SessionBusPrivateNoAutoStartup)
46+
})
47+
}
48+
4049
// UserOwnsCurrentSystemdCgroup checks whether the current EUID owns the
4150
// current cgroup.
4251
func UserOwnsCurrentSystemdCgroup() (bool, error) {

pkg/cgroups/utils_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ func ReadFile(dir, file string) (string, error) {
104104
return buf.String(), err
105105
}
106106

107-
// GetBlkioFiles gets the proper files for blkio weights
108-
func GetBlkioFiles(cgroupPath string) (wtFile, wtDevFile string) {
107+
// BlkioFiles gets the proper files for blkio weights
108+
func BlkioFiles(cgroupPath string) (wtFile, wtDevFile string) {
109109
var weightFile string
110110
var weightDeviceFile string
111111
// in this important since runc keeps these variables private, they won't be set

0 commit comments

Comments
 (0)