Skip to content

Commit

Permalink
libct/cg/sd/systemdVersion: don't return error
Browse files Browse the repository at this point in the history
As the caller of this function just logs the error, it does not make
sense to pass it. Instead, log it (once) and return -1.

This is a preparation for the second user.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Jan 14, 2021
1 parent dbbe7e6 commit eee425f
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions libcontainer/cgroups/systemd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ var (

versionOnce sync.Once
version int
versionErr error

isRunningSystemdOnce sync.Once
isRunningSystemd bool
Expand Down Expand Up @@ -372,19 +371,20 @@ func stopUnit(dbusConnection *systemdDbus.Conn, unitName string) error {
return nil
}

func systemdVersion(conn *systemdDbus.Conn) (int, error) {
func systemdVersion(conn *systemdDbus.Conn) int {
versionOnce.Do(func() {
version = -1
verStr, err := conn.GetManagerProperty("Version")
if err != nil {
versionErr = err
return
if err == nil {
version, err = systemdVersionAtoi(verStr)
}

version, versionErr = systemdVersionAtoi(verStr)
if err != nil {
logrus.WithError(err).Error("unable to get systemd version")
}
})

return version, versionErr
return version
}

func systemdVersionAtoi(verStr string) (int, error) {
Expand All @@ -405,10 +405,8 @@ func systemdVersionAtoi(verStr string) (int, error) {
func addCpuQuota(conn *systemdDbus.Conn, properties *[]systemdDbus.Property, quota int64, period uint64) {
if period != 0 {
// systemd only supports CPUQuotaPeriodUSec since v242
sdVer, err := systemdVersion(conn)
if err != nil {
logrus.Warnf("systemdVersion: %s", err)
} else if sdVer >= 242 {
sdVer := systemdVersion(conn)
if sdVer >= 242 {
*properties = append(*properties,
newProp("CPUQuotaPeriodUSec", period))
}
Expand Down

0 comments on commit eee425f

Please sign in to comment.