@@ -24,6 +24,18 @@ import (
2424 "github.com/godbus/dbus/v5"
2525)
2626
27+ // Who can be used to specify which process to kill in the unit via the KillUnitWithTarget API
28+ type Who string
29+
30+ const (
31+ // All sends the signal to all processes in the unit
32+ All Who = "all"
33+ // Main sends the signal to the main process of the unit
34+ Main Who = "main"
35+ // Control sends the signal to the control process of the unit
36+ Control Who = "control"
37+ )
38+
2739func (c * Conn ) jobComplete (signal * dbus.Signal ) {
2840 var id uint32
2941 var job dbus.ObjectPath
@@ -196,7 +208,12 @@ func (c *Conn) KillUnit(name string, signal int32) {
196208
197209// KillUnitContext same as KillUnit with context
198210func (c * Conn ) KillUnitContext (ctx context.Context , name string , signal int32 ) {
199- c .sysobj .CallWithContext (ctx , "org.freedesktop.systemd1.Manager.KillUnit" , 0 , name , "all" , signal ).Store ()
211+ c .KillUnitWithTarget (ctx , name , All , signal )
212+ }
213+
214+ // KillUnitWithTarget is like KillUnitContext, but allows you to specify which process in the unit to send the signal to
215+ func (c * Conn ) KillUnitWithTarget (ctx context.Context , name string , target Who , signal int32 ) error {
216+ return c .sysobj .CallWithContext (ctx , "org.freedesktop.systemd1.Manager.KillUnit" , 0 , name , string (target ), signal ).Store ()
200217}
201218
202219// ResetFailedUnit resets the "failed" state of a specific unit.
0 commit comments