Skip to content

Commit

Permalink
merge branch 'pr-2926'
Browse files Browse the repository at this point in the history
Sebastiaan van Stijn (1):
  cgroups/systemd: replace deprecated dbus functions

LGTMs: AkihiroSuda cyphar
Closes #2926
  • Loading branch information
cyphar committed Apr 30, 2021
2 parents 8f85f4f + 71a8aee commit 016717a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions libcontainer/cgroups/systemd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package systemd

import (
"bufio"
"context"
"fmt"
"math"
"os"
Expand Down Expand Up @@ -321,7 +322,7 @@ func isUnitExists(err error) bool {
func startUnit(cm *dbusConnManager, unitName string, properties []systemdDbus.Property) error {
statusChan := make(chan string, 1)
err := cm.retryOnDisconnect(func(c *systemdDbus.Conn) error {
_, err := c.StartTransientUnit(unitName, "replace", properties, statusChan)
_, err := c.StartTransientUnitContext(context.TODO(), unitName, "replace", properties, statusChan)
return err
})
if err == nil {
Expand All @@ -331,7 +332,7 @@ func startUnit(cm *dbusConnManager, unitName string, properties []systemdDbus.Pr
select {
case s := <-statusChan:
close(statusChan)
// Please refer to https://godoc.org/github.com/coreos/go-systemd/dbus#Conn.StartUnit
// Please refer to https://pkg.go.dev/github.com/coreos/go-systemd/v22/dbus#Conn.StartUnit
if s != "done" {
resetFailedUnit(cm, unitName)
return errors.Errorf("error creating systemd unit `%s`: got `%s`", unitName, s)
Expand All @@ -350,14 +351,14 @@ func startUnit(cm *dbusConnManager, unitName string, properties []systemdDbus.Pr
func stopUnit(cm *dbusConnManager, unitName string) error {
statusChan := make(chan string, 1)
err := cm.retryOnDisconnect(func(c *systemdDbus.Conn) error {
_, err := c.StopUnit(unitName, "replace", statusChan)
_, err := c.StopUnitContext(context.TODO(), unitName, "replace", statusChan)
return err
})
if err == nil {
select {
case s := <-statusChan:
close(statusChan)
// Please refer to https://godoc.org/github.com/coreos/go-systemd/dbus#Conn.StartUnit
// Please refer to https://godoc.org/github.com/coreos/go-systemd/v22/dbus#Conn.StartUnit
if s != "done" {
logrus.Warnf("error removing unit `%s`: got `%s`. Continuing...", unitName, s)
}
Expand All @@ -370,7 +371,7 @@ func stopUnit(cm *dbusConnManager, unitName string) error {

func resetFailedUnit(cm *dbusConnManager, name string) {
err := cm.retryOnDisconnect(func(c *systemdDbus.Conn) error {
return c.ResetFailedUnit(name)
return c.ResetFailedUnitContext(context.TODO(), name)
})
if err != nil {
logrus.Warnf("unable to reset failed unit: %v", err)
Expand All @@ -379,7 +380,7 @@ func resetFailedUnit(cm *dbusConnManager, name string) {

func setUnitProperties(cm *dbusConnManager, name string, properties ...systemdDbus.Property) error {
return cm.retryOnDisconnect(func(c *systemdDbus.Conn) error {
return c.SetUnitProperties(name, true, properties...)
return c.SetUnitPropertiesContext(context.TODO(), name, true, properties...)
})
}

Expand Down

0 comments on commit 016717a

Please sign in to comment.