build(deps): bump github.com/coreos/go-systemd/v22 from 22.6.0 to 22.7.0

Bumps [github.com/coreos/go-systemd/v22](https://github.com/coreos/go-systemd) from 22.6.0 to 22.7.0.
- [Release notes](https://github.com/coreos/go-systemd/releases)
- [Commits](https://github.com/coreos/go-systemd/compare/v22.6.0...v22.7.0)

---
updated-dependencies:
- dependency-name: github.com/coreos/go-systemd/v22
  dependency-version: 22.7.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
dependabot[bot]
2026-01-28 04:52:18 +00:00
committed by GitHub
parent 3d60760d3b
commit 9abc1824f2
8 changed files with 105 additions and 207 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ go 1.24.0
require ( require (
github.com/checkpoint-restore/go-criu/v7 v7.2.0 github.com/checkpoint-restore/go-criu/v7 v7.2.0
github.com/containerd/console v1.0.5 github.com/containerd/console v1.0.5
github.com/coreos/go-systemd/v22 v22.6.0 github.com/coreos/go-systemd/v22 v22.7.0
github.com/cyphar/filepath-securejoin v0.6.1 github.com/cyphar/filepath-securejoin v0.6.1
github.com/docker/go-units v0.5.0 github.com/docker/go-units v0.5.0
github.com/godbus/dbus/v5 v5.2.2 github.com/godbus/dbus/v5 v5.2.2
+2 -2
View File
@@ -7,8 +7,8 @@ github.com/cilium/ebpf v0.17.3 h1:FnP4r16PWYSE4ux6zN+//jMcW4nMVRvuTLVTvCjyyjg=
github.com/cilium/ebpf v0.17.3/go.mod h1:G5EDHij8yiLzaqn0WjyfJHvRa+3aDlReIaLVRMvOyJk= github.com/cilium/ebpf v0.17.3/go.mod h1:G5EDHij8yiLzaqn0WjyfJHvRa+3aDlReIaLVRMvOyJk=
github.com/containerd/console v1.0.5 h1:R0ymNeydRqH2DmakFNdmjR2k0t7UPuiOV/N/27/qqsc= github.com/containerd/console v1.0.5 h1:R0ymNeydRqH2DmakFNdmjR2k0t7UPuiOV/N/27/qqsc=
github.com/containerd/console v1.0.5/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk= github.com/containerd/console v1.0.5/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk=
github.com/coreos/go-systemd/v22 v22.6.0 h1:aGVa/v8B7hpb0TKl0MWoAavPDmHvobFe5R5zn0bCJWo= github.com/coreos/go-systemd/v22 v22.7.0 h1:LAEzFkke61DFROc7zNLX/WA2i5J8gYqe0rSj9KI28KA=
github.com/coreos/go-systemd/v22 v22.6.0/go.mod h1:iG+pp635Fo7ZmV/j14KUcmEyWF+0X7Lua8rrTWzYgWU= github.com/coreos/go-systemd/v22 v22.7.0/go.mod h1:xNUYtjHu2EDXbsxz1i41wouACIwT7Ybq9o0BQhMwD0w=
github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo= github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo=
github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/cyphar/filepath-securejoin v0.6.1 h1:5CeZ1jPXEiYt3+Z6zqprSAgSWiggmpVyciv8syjIpVE= github.com/cyphar/filepath-securejoin v0.6.1 h1:5CeZ1jPXEiYt3+Z6zqprSAgSWiggmpVyciv8syjIpVE=
+2 -2
View File
@@ -95,7 +95,7 @@ type Conn struct {
sigobj dbus.BusObject sigobj dbus.BusObject
jobListener struct { jobListener struct {
jobs map[dbus.ObjectPath]chan<- string jobs map[dbus.ObjectPath][]chan<- string
sync.Mutex sync.Mutex
} }
subStateSubscriber struct { subStateSubscriber struct {
@@ -207,7 +207,7 @@ func NewConnection(dialBus func() (*dbus.Conn, error)) (*Conn, error) {
} }
c.subStateSubscriber.ignore = make(map[dbus.ObjectPath]int64) c.subStateSubscriber.ignore = make(map[dbus.ObjectPath]int64)
c.jobListener.jobs = make(map[dbus.ObjectPath]chan<- string) c.jobListener.jobs = make(map[dbus.ObjectPath][]chan<- string)
// Setup the listeners on jobs so that we can get completions // Setup the listeners on jobs so that we can get completions
c.sigconn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0, c.sigconn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0,
+49 -190
View File
@@ -24,7 +24,7 @@ import (
"github.com/godbus/dbus/v5" "github.com/godbus/dbus/v5"
) )
// Who specifies which process to send a signal to via the [KillUnitWithTarget]. // Who specifies which process to send a signal to via the [Conn.KillUnitWithTarget].
type Who string type Who string
const ( const (
@@ -44,11 +44,10 @@ func (c *Conn) jobComplete(signal *dbus.Signal) {
_ = dbus.Store(signal.Body, &id, &job, &unit, &result) _ = dbus.Store(signal.Body, &id, &job, &unit, &result)
c.jobListener.Lock() c.jobListener.Lock()
out, ok := c.jobListener.jobs[job] for _, out := range c.jobListener.jobs[job] {
if ok {
out <- result out <- result
delete(c.jobListener.jobs, job)
} }
delete(c.jobListener.jobs, job)
c.jobListener.Unlock() c.jobListener.Unlock()
} }
@@ -65,7 +64,7 @@ func (c *Conn) startJob(ctx context.Context, ch chan<- string, job string, args
} }
if ch != nil { if ch != nil {
c.jobListener.jobs[p] = ch c.jobListener.jobs[p] = append(c.jobListener.jobs[p], ch)
} }
// ignore error since 0 is fine if conversion fails // ignore error since 0 is fine if conversion fails
@@ -194,10 +193,16 @@ func (c *Conn) StartTransientUnit(name string, mode string, properties []Propert
// unique. mode is the same as in StartUnitContext, properties contains properties // unique. mode is the same as in StartUnitContext, properties contains properties
// of the unit. // of the unit.
func (c *Conn) StartTransientUnitContext(ctx context.Context, name string, mode string, properties []Property, ch chan<- string) (int, error) { func (c *Conn) StartTransientUnitContext(ctx context.Context, name string, mode string, properties []Property, ch chan<- string) (int, error) {
return c.startJob(ctx, ch, "org.freedesktop.systemd1.Manager.StartTransientUnit", name, mode, properties, make([]PropertyCollection, 0)) return c.StartTransientUnitAux(ctx, name, mode, properties, make([]PropertyCollection, 0), ch)
} }
// Deprecated: use [KillUnitWithTarget] instead. // StartTransientUnitAux is the same as StartTransientUnitContext but allows passing
// auxiliary units in the aux parameter.
func (c *Conn) StartTransientUnitAux(ctx context.Context, name string, mode string, properties []Property, aux []PropertyCollection, ch chan<- string) (int, error) {
return c.startJob(ctx, ch, "org.freedesktop.systemd1.Manager.StartTransientUnit", name, mode, properties, aux)
}
// Deprecated: use [Conn.KillUnitWithTarget] instead.
func (c *Conn) KillUnit(name string, signal int32) { func (c *Conn) KillUnit(name string, signal int32) {
c.KillUnitContext(context.Background(), name, signal) c.KillUnitContext(context.Background(), name, signal)
} }
@@ -205,7 +210,7 @@ func (c *Conn) KillUnit(name string, signal int32) {
// KillUnitContext takes the unit name and a UNIX signal number to send. // KillUnitContext takes the unit name and a UNIX signal number to send.
// All of the unit's processes are killed. // All of the unit's processes are killed.
// //
// Deprecated: use [KillUnitWithTarget] instead, with target argument set to [All]. // Deprecated: use [Conn.KillUnitWithTarget] instead, with target argument set to [All].
func (c *Conn) KillUnitContext(ctx context.Context, name string, signal int32) { func (c *Conn) KillUnitContext(ctx context.Context, name string, signal int32) {
_ = c.KillUnitWithTarget(ctx, name, All, signal) _ = c.KillUnitWithTarget(ctx, name, All, signal)
} }
@@ -398,30 +403,33 @@ type UnitStatus struct {
type storeFunc func(retvalues ...any) error type storeFunc func(retvalues ...any) error
func (c *Conn) listUnitsInternal(f storeFunc) ([]UnitStatus, error) { // convertSlice converts a []any result into a slice of the target type T
result := make([][]any, 0) // using dbus.Store to handle the type conversion.
func convertSlice[T any](result []any) ([]T, error) {
converted := make([]T, len(result))
convertedInterface := make([]any, len(converted))
for i := range converted {
convertedInterface[i] = &converted[i]
}
err := dbus.Store(result, convertedInterface...)
if err != nil {
return nil, err
}
return converted, nil
}
// storeSlice fetches D-Bus array results via the provided storeFunc
// and converts them into a slice of the target type T.
func storeSlice[T any](f storeFunc) ([]T, error) {
var result []any
err := f(&result) err := f(&result)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resultInterface := make([]any, len(result)) return convertSlice[T](result)
for i := range result {
resultInterface[i] = result[i]
}
status := make([]UnitStatus, len(result))
statusInterface := make([]any, len(status))
for i := range status {
statusInterface[i] = &status[i]
}
err = dbus.Store(resultInterface, statusInterface...)
if err != nil {
return nil, err
}
return status, nil
} }
// GetUnitByPID returns the unit object path of the unit a process ID // GetUnitByPID returns the unit object path of the unit a process ID
@@ -458,7 +466,7 @@ func (c *Conn) ListUnits() ([]UnitStatus, error) {
// Also note that a unit is only loaded if it is active and/or enabled. // Also note that a unit is only loaded if it is active and/or enabled.
// Units that are both disabled and inactive will thus not be returned. // Units that are both disabled and inactive will thus not be returned.
func (c *Conn) ListUnitsContext(ctx context.Context) ([]UnitStatus, error) { func (c *Conn) ListUnitsContext(ctx context.Context) ([]UnitStatus, error) {
return c.listUnitsInternal(c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListUnits", 0).Store) return storeSlice[UnitStatus](c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListUnits", 0).Store)
} }
// Deprecated: use ListUnitsFilteredContext instead. // Deprecated: use ListUnitsFilteredContext instead.
@@ -469,7 +477,7 @@ func (c *Conn) ListUnitsFiltered(states []string) ([]UnitStatus, error) {
// ListUnitsFilteredContext returns an array with units filtered by state. // ListUnitsFilteredContext returns an array with units filtered by state.
// It takes a list of units' statuses to filter. // It takes a list of units' statuses to filter.
func (c *Conn) ListUnitsFilteredContext(ctx context.Context, states []string) ([]UnitStatus, error) { func (c *Conn) ListUnitsFilteredContext(ctx context.Context, states []string) ([]UnitStatus, error) {
return c.listUnitsInternal(c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListUnitsFiltered", 0, states).Store) return storeSlice[UnitStatus](c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListUnitsFiltered", 0, states).Store)
} }
// Deprecated: use ListUnitsByPatternsContext instead. // Deprecated: use ListUnitsByPatternsContext instead.
@@ -482,7 +490,7 @@ func (c *Conn) ListUnitsByPatterns(states []string, patterns []string) ([]UnitSt
// Note that units may be known by multiple names at the same time, // Note that units may be known by multiple names at the same time,
// and hence there might be more unit names loaded than actual units behind them. // and hence there might be more unit names loaded than actual units behind them.
func (c *Conn) ListUnitsByPatternsContext(ctx context.Context, states []string, patterns []string) ([]UnitStatus, error) { func (c *Conn) ListUnitsByPatternsContext(ctx context.Context, states []string, patterns []string) ([]UnitStatus, error) {
return c.listUnitsInternal(c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListUnitsByPatterns", 0, states, patterns).Store) return storeSlice[UnitStatus](c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListUnitsByPatterns", 0, states, patterns).Store)
} }
// Deprecated: use ListUnitsByNamesContext instead. // Deprecated: use ListUnitsByNamesContext instead.
@@ -497,7 +505,7 @@ func (c *Conn) ListUnitsByNames(units []string) ([]UnitStatus, error) {
// //
// Requires systemd v230 or higher. // Requires systemd v230 or higher.
func (c *Conn) ListUnitsByNamesContext(ctx context.Context, units []string) ([]UnitStatus, error) { func (c *Conn) ListUnitsByNamesContext(ctx context.Context, units []string) ([]UnitStatus, error) {
return c.listUnitsInternal(c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListUnitsByNames", 0, units).Store) return storeSlice[UnitStatus](c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListUnitsByNames", 0, units).Store)
} }
type UnitFile struct { type UnitFile struct {
@@ -505,32 +513,6 @@ type UnitFile struct {
Type string Type string
} }
func (c *Conn) listUnitFilesInternal(f storeFunc) ([]UnitFile, error) {
result := make([][]any, 0)
err := f(&result)
if err != nil {
return nil, err
}
resultInterface := make([]any, len(result))
for i := range result {
resultInterface[i] = result[i]
}
files := make([]UnitFile, len(result))
fileInterface := make([]any, len(files))
for i := range files {
fileInterface[i] = &files[i]
}
err = dbus.Store(resultInterface, fileInterface...)
if err != nil {
return nil, err
}
return files, nil
}
// Deprecated: use ListUnitFilesContext instead. // Deprecated: use ListUnitFilesContext instead.
func (c *Conn) ListUnitFiles() ([]UnitFile, error) { func (c *Conn) ListUnitFiles() ([]UnitFile, error) {
return c.ListUnitFilesContext(context.Background()) return c.ListUnitFilesContext(context.Background())
@@ -538,7 +520,7 @@ func (c *Conn) ListUnitFiles() ([]UnitFile, error) {
// ListUnitFilesContext returns an array of all available units on disk. // ListUnitFilesContext returns an array of all available units on disk.
func (c *Conn) ListUnitFilesContext(ctx context.Context) ([]UnitFile, error) { func (c *Conn) ListUnitFilesContext(ctx context.Context) ([]UnitFile, error) {
return c.listUnitFilesInternal(c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListUnitFiles", 0).Store) return storeSlice[UnitFile](c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListUnitFiles", 0).Store)
} }
// Deprecated: use ListUnitFilesByPatternsContext instead. // Deprecated: use ListUnitFilesByPatternsContext instead.
@@ -548,7 +530,7 @@ func (c *Conn) ListUnitFilesByPatterns(states []string, patterns []string) ([]Un
// ListUnitFilesByPatternsContext returns an array of all available units on disk matched the patterns. // ListUnitFilesByPatternsContext returns an array of all available units on disk matched the patterns.
func (c *Conn) ListUnitFilesByPatternsContext(ctx context.Context, states []string, patterns []string) ([]UnitFile, error) { func (c *Conn) ListUnitFilesByPatternsContext(ctx context.Context, states []string, patterns []string) ([]UnitFile, error) {
return c.listUnitFilesInternal(c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListUnitFilesByPatterns", 0, states, patterns).Store) return storeSlice[UnitFile](c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListUnitFilesByPatterns", 0, states, patterns).Store)
} }
type LinkUnitFileChange EnableUnitFileChange type LinkUnitFileChange EnableUnitFileChange
@@ -576,29 +558,7 @@ func (c *Conn) LinkUnitFiles(files []string, runtime bool, force bool) ([]LinkUn
// or unlink), the file name of the symlink and the destination of the // or unlink), the file name of the symlink and the destination of the
// symlink. // symlink.
func (c *Conn) LinkUnitFilesContext(ctx context.Context, files []string, runtime bool, force bool) ([]LinkUnitFileChange, error) { func (c *Conn) LinkUnitFilesContext(ctx context.Context, files []string, runtime bool, force bool) ([]LinkUnitFileChange, error) {
result := make([][]any, 0) return storeSlice[LinkUnitFileChange](c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.LinkUnitFiles", 0, files, runtime, force).Store)
err := c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.LinkUnitFiles", 0, files, runtime, force).Store(&result)
if err != nil {
return nil, err
}
resultInterface := make([]any, len(result))
for i := range result {
resultInterface[i] = result[i]
}
changes := make([]LinkUnitFileChange, len(result))
changesInterface := make([]any, len(changes))
for i := range changes {
changesInterface[i] = &changes[i]
}
err = dbus.Store(resultInterface, changesInterface...)
if err != nil {
return nil, err
}
return changes, nil
} }
// Deprecated: use EnableUnitFilesContext instead. // Deprecated: use EnableUnitFilesContext instead.
@@ -624,25 +584,14 @@ func (c *Conn) EnableUnitFiles(files []string, runtime bool, force bool) (bool,
// symlink. // symlink.
func (c *Conn) EnableUnitFilesContext(ctx context.Context, files []string, runtime bool, force bool) (bool, []EnableUnitFileChange, error) { func (c *Conn) EnableUnitFilesContext(ctx context.Context, files []string, runtime bool, force bool) (bool, []EnableUnitFileChange, error) {
var carries_install_info bool var carries_install_info bool
var result []any
result := make([][]any, 0)
err := c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.EnableUnitFiles", 0, files, runtime, force).Store(&carries_install_info, &result) err := c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.EnableUnitFiles", 0, files, runtime, force).Store(&carries_install_info, &result)
if err != nil { if err != nil {
return false, nil, err return false, nil, err
} }
resultInterface := make([]any, len(result)) changes, err := convertSlice[EnableUnitFileChange](result)
for i := range result {
resultInterface[i] = result[i]
}
changes := make([]EnableUnitFileChange, len(result))
changesInterface := make([]any, len(changes))
for i := range changes {
changesInterface[i] = &changes[i]
}
err = dbus.Store(resultInterface, changesInterface...)
if err != nil { if err != nil {
return false, nil, err return false, nil, err
} }
@@ -674,29 +623,7 @@ func (c *Conn) DisableUnitFiles(files []string, runtime bool) ([]DisableUnitFile
// symlink or unlink), the file name of the symlink and the destination of the // symlink or unlink), the file name of the symlink and the destination of the
// symlink. // symlink.
func (c *Conn) DisableUnitFilesContext(ctx context.Context, files []string, runtime bool) ([]DisableUnitFileChange, error) { func (c *Conn) DisableUnitFilesContext(ctx context.Context, files []string, runtime bool) ([]DisableUnitFileChange, error) {
result := make([][]any, 0) return storeSlice[DisableUnitFileChange](c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.DisableUnitFiles", 0, files, runtime).Store)
err := c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.DisableUnitFiles", 0, files, runtime).Store(&result)
if err != nil {
return nil, err
}
resultInterface := make([]any, len(result))
for i := range result {
resultInterface[i] = result[i]
}
changes := make([]DisableUnitFileChange, len(result))
changesInterface := make([]any, len(changes))
for i := range changes {
changesInterface[i] = &changes[i]
}
err = dbus.Store(resultInterface, changesInterface...)
if err != nil {
return nil, err
}
return changes, nil
} }
type DisableUnitFileChange struct { type DisableUnitFileChange struct {
@@ -720,29 +647,7 @@ func (c *Conn) MaskUnitFiles(files []string, runtime bool, force bool) ([]MaskUn
// runtime only (true, /run/systemd/..), or persistently (false, // runtime only (true, /run/systemd/..), or persistently (false,
// /etc/systemd/..). // /etc/systemd/..).
func (c *Conn) MaskUnitFilesContext(ctx context.Context, files []string, runtime bool, force bool) ([]MaskUnitFileChange, error) { func (c *Conn) MaskUnitFilesContext(ctx context.Context, files []string, runtime bool, force bool) ([]MaskUnitFileChange, error) {
result := make([][]any, 0) return storeSlice[MaskUnitFileChange](c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.MaskUnitFiles", 0, files, runtime, force).Store)
err := c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.MaskUnitFiles", 0, files, runtime, force).Store(&result)
if err != nil {
return nil, err
}
resultInterface := make([]any, len(result))
for i := range result {
resultInterface[i] = result[i]
}
changes := make([]MaskUnitFileChange, len(result))
changesInterface := make([]any, len(changes))
for i := range changes {
changesInterface[i] = &changes[i]
}
err = dbus.Store(resultInterface, changesInterface...)
if err != nil {
return nil, err
}
return changes, nil
} }
type MaskUnitFileChange struct { type MaskUnitFileChange struct {
@@ -764,29 +669,7 @@ func (c *Conn) UnmaskUnitFiles(files []string, runtime bool) ([]UnmaskUnitFileCh
// for runtime only (true, /run/systemd/..), or persistently (false, // for runtime only (true, /run/systemd/..), or persistently (false,
// /etc/systemd/..). // /etc/systemd/..).
func (c *Conn) UnmaskUnitFilesContext(ctx context.Context, files []string, runtime bool) ([]UnmaskUnitFileChange, error) { func (c *Conn) UnmaskUnitFilesContext(ctx context.Context, files []string, runtime bool) ([]UnmaskUnitFileChange, error) {
result := make([][]any, 0) return storeSlice[UnmaskUnitFileChange](c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.UnmaskUnitFiles", 0, files, runtime).Store)
err := c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.UnmaskUnitFiles", 0, files, runtime).Store(&result)
if err != nil {
return nil, err
}
resultInterface := make([]any, len(result))
for i := range result {
resultInterface[i] = result[i]
}
changes := make([]UnmaskUnitFileChange, len(result))
changesInterface := make([]any, len(changes))
for i := range changes {
changesInterface[i] = &changes[i]
}
err = dbus.Store(resultInterface, changesInterface...)
if err != nil {
return nil, err
}
return changes, nil
} }
type UnmaskUnitFileChange struct { type UnmaskUnitFileChange struct {
@@ -832,35 +715,11 @@ func (c *Conn) ListJobs() ([]JobStatus, error) {
// ListJobsContext returns an array with all currently queued jobs. // ListJobsContext returns an array with all currently queued jobs.
func (c *Conn) ListJobsContext(ctx context.Context) ([]JobStatus, error) { func (c *Conn) ListJobsContext(ctx context.Context) ([]JobStatus, error) {
return c.listJobsInternal(ctx) return storeSlice[JobStatus](c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListJobs", 0).Store)
}
func (c *Conn) listJobsInternal(ctx context.Context) ([]JobStatus, error) {
result := make([][]any, 0)
if err := c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListJobs", 0).Store(&result); err != nil {
return nil, err
}
resultInterface := make([]any, len(result))
for i := range result {
resultInterface[i] = result[i]
}
status := make([]JobStatus, len(result))
statusInterface := make([]any, len(status))
for i := range status {
statusInterface[i] = &status[i]
}
if err := dbus.Store(resultInterface, statusInterface...); err != nil {
return nil, err
}
return status, nil
} }
// FreezeUnit freezes the cgroup associated with the unit. // FreezeUnit freezes the cgroup associated with the unit.
// Note that FreezeUnit and [ThawUnit] are only supported on systems running with cgroup v2. // Note that FreezeUnit and [Conn.ThawUnit] are only supported on systems running with cgroup v2.
func (c *Conn) FreezeUnit(ctx context.Context, unit string) error { func (c *Conn) FreezeUnit(ctx context.Context, unit string) error {
return c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.FreezeUnit", 0, unit).Store() return c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.FreezeUnit", 0, unit).Store()
} }
+16 -1
View File
@@ -14,28 +14,43 @@
package dbus package dbus
import (
"sync"
)
type set struct { type set struct {
data map[string]bool data map[string]bool
mu sync.Mutex
} }
func (s *set) Add(value string) { func (s *set) Add(value string) {
s.mu.Lock()
defer s.mu.Unlock()
s.data[value] = true s.data[value] = true
} }
func (s *set) Remove(value string) { func (s *set) Remove(value string) {
s.mu.Lock()
defer s.mu.Unlock()
delete(s.data, value) delete(s.data, value)
} }
func (s *set) Contains(value string) (exists bool) { func (s *set) Contains(value string) (exists bool) {
s.mu.Lock()
defer s.mu.Unlock()
_, exists = s.data[value] _, exists = s.data[value]
return return
} }
func (s *set) Length() int { func (s *set) Length() int {
s.mu.Lock()
defer s.mu.Unlock()
return len(s.data) return len(s.data)
} }
func (s *set) Values() (values []string) { func (s *set) Values() (values []string) {
s.mu.Lock()
defer s.mu.Unlock()
for val := range s.data { for val := range s.data {
values = append(values, val) values = append(values, val)
} }
@@ -43,5 +58,5 @@ func (s *set) Values() (values []string) {
} }
func newSet() *set { func newSet() *set {
return &set{make(map[string]bool)} return &set{data: make(map[string]bool)}
} }
+25 -7
View File
@@ -15,6 +15,7 @@
package dbus package dbus
import ( import (
"context"
"errors" "errors"
"log" "log"
"time" "time"
@@ -94,16 +95,26 @@ func (c *Conn) dispatch() {
}() }()
} }
// SubscribeUnits returns two unbuffered channels which will receive all changed units every // Deprecated: use SubscribeUnitsContext instead.
// interval. Deleted units are sent as nil.
func (c *Conn) SubscribeUnits(interval time.Duration) (<-chan map[string]*UnitStatus, <-chan error) { func (c *Conn) SubscribeUnits(interval time.Duration) (<-chan map[string]*UnitStatus, <-chan error) {
return c.SubscribeUnitsCustom(interval, 0, func(u1, u2 *UnitStatus) bool { return *u1 != *u2 }, nil) return c.SubscribeUnitsContext(context.Background(), interval)
} }
// SubscribeUnitsCustom is like SubscribeUnits but lets you specify the buffer // SubscribeUnitsContext returns two unbuffered channels which will receive all changed units every
// interval. Deleted units are sent as nil.
func (c *Conn) SubscribeUnitsContext(ctx context.Context, interval time.Duration) (<-chan map[string]*UnitStatus, <-chan error) {
return c.SubscribeUnitsCustomContext(ctx, interval, 0, func(u1, u2 *UnitStatus) bool { return *u1 != *u2 }, nil)
}
// Deprecated: use SubscribeUnitsCustomContext instead.
func (c *Conn) SubscribeUnitsCustom(interval time.Duration, buffer int, isChanged func(*UnitStatus, *UnitStatus) bool, filterUnit func(string) bool) (<-chan map[string]*UnitStatus, <-chan error) {
return c.SubscribeUnitsCustomContext(context.Background(), interval, buffer, isChanged, filterUnit)
}
// SubscribeUnitsCustomContext is like [Conn.SubscribeUnitsContext] but lets you specify the buffer
// size of the channels, the comparison function for detecting changes and a filter // size of the channels, the comparison function for detecting changes and a filter
// function for cutting down on the noise that your channel receives. // function for cutting down on the noise that your channel receives.
func (c *Conn) SubscribeUnitsCustom(interval time.Duration, buffer int, isChanged func(*UnitStatus, *UnitStatus) bool, filterUnit func(string) bool) (<-chan map[string]*UnitStatus, <-chan error) { func (c *Conn) SubscribeUnitsCustomContext(ctx context.Context, interval time.Duration, buffer int, isChanged func(*UnitStatus, *UnitStatus) bool, filterUnit func(string) bool) (<-chan map[string]*UnitStatus, <-chan error) {
old := make(map[string]*UnitStatus) old := make(map[string]*UnitStatus)
statusChan := make(chan map[string]*UnitStatus, buffer) statusChan := make(chan map[string]*UnitStatus, buffer)
errChan := make(chan error, buffer) errChan := make(chan error, buffer)
@@ -112,7 +123,7 @@ func (c *Conn) SubscribeUnitsCustom(interval time.Duration, buffer int, isChange
for { for {
timerChan := time.After(interval) timerChan := time.After(interval)
units, err := c.ListUnits() units, err := c.ListUnitsContext(ctx)
if err == nil { if err == nil {
cur := make(map[string]*UnitStatus) cur := make(map[string]*UnitStatus)
for i := range units { for i := range units {
@@ -145,7 +156,14 @@ func (c *Conn) SubscribeUnitsCustom(interval time.Duration, buffer int, isChange
errChan <- err errChan <- err
} }
<-timerChan select {
case <-timerChan:
continue
case <-ctx.Done():
close(statusChan)
close(errChan)
return
}
} }
}() }()
+9 -3
View File
@@ -15,6 +15,7 @@
package dbus package dbus
import ( import (
"context"
"time" "time"
) )
@@ -29,16 +30,21 @@ func (s *SubscriptionSet) filter(unit string) bool {
return !s.Contains(unit) return !s.Contains(unit)
} }
// Subscribe starts listening for dbus events for all of the units in the set. // SubscribeContext starts listening for dbus events for all of the units in the set.
// Returns channels identical to conn.SubscribeUnits. // Returns channels identical to conn.SubscribeUnits.
func (s *SubscriptionSet) Subscribe() (<-chan map[string]*UnitStatus, <-chan error) { func (s *SubscriptionSet) SubscribeContext(ctx context.Context) (<-chan map[string]*UnitStatus, <-chan error) {
// TODO: Make fully evented by using systemd 209 with properties changed values // TODO: Make fully evented by using systemd 209 with properties changed values
return s.conn.SubscribeUnitsCustom(time.Second, 0, return s.conn.SubscribeUnitsCustomContext(ctx, time.Second, 0,
mismatchUnitStatus, mismatchUnitStatus,
func(unit string) bool { return s.filter(unit) }, func(unit string) bool { return s.filter(unit) },
) )
} }
// Deprecated: use SubscribeContext instead.
func (s *SubscriptionSet) Subscribe() (<-chan map[string]*UnitStatus, <-chan error) {
return s.SubscribeContext(context.Background())
}
// NewSubscriptionSet returns a new subscription set. // NewSubscriptionSet returns a new subscription set.
func (c *Conn) NewSubscriptionSet() *SubscriptionSet { func (c *Conn) NewSubscriptionSet() *SubscriptionSet {
return &SubscriptionSet{newSet(), c} return &SubscriptionSet{newSet(), c}
+1 -1
View File
@@ -26,7 +26,7 @@ github.com/cilium/ebpf/link
# github.com/containerd/console v1.0.5 # github.com/containerd/console v1.0.5
## explicit; go 1.13 ## explicit; go 1.13
github.com/containerd/console github.com/containerd/console
# github.com/coreos/go-systemd/v22 v22.6.0 # github.com/coreos/go-systemd/v22 v22.7.0
## explicit; go 1.23 ## explicit; go 1.23
github.com/coreos/go-systemd/v22/dbus github.com/coreos/go-systemd/v22/dbus
# github.com/cpuguy83/go-md2man/v2 v2.0.7 # github.com/cpuguy83/go-md2man/v2 v2.0.7