libct/cg/sd/systemdVersion: don't return error
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.
@@ -34,7 +34,6 @@ var (
versionOnce sync.Once
version int
- versionErr error
isRunningSystemdOnce sync.Once
isRunningSystemd bool
@@ -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) {
@@ -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))
}
