@@ -33,12 +33,12 @@ const (
3333// systemd will automatically stop sending signals so there is no need to
3434// explicitly call Unsubscribe().
3535func (c * Conn ) Subscribe () error {
36- c .sysconn .BusObject ().Call ("org.freedesktop.DBus.AddMatch" , 0 ,
36+ c .sigconn .BusObject ().Call ("org.freedesktop.DBus.AddMatch" , 0 ,
3737 "type='signal',interface='org.freedesktop.systemd1.Manager',member='UnitNew'" )
38- c .sysconn .BusObject ().Call ("org.freedesktop.DBus.AddMatch" , 0 ,
38+ c .sigconn .BusObject ().Call ("org.freedesktop.DBus.AddMatch" , 0 ,
3939 "type='signal',interface='org.freedesktop.DBus.Properties',member='PropertiesChanged'" )
4040
41- err := c .sysobj .Call ("org.freedesktop.systemd1.Manager.Subscribe" , 0 ).Store ()
41+ err := c .sigobj .Call ("org.freedesktop.systemd1.Manager.Subscribe" , 0 ).Store ()
4242 if err != nil {
4343 return err
4444 }
@@ -48,22 +48,18 @@ func (c *Conn) Subscribe() error {
4848
4949// Unsubscribe this connection from systemd dbus events.
5050func (c * Conn ) Unsubscribe () error {
51- err := c .sysobj .Call ("org.freedesktop.systemd1.Manager.Unsubscribe" , 0 ).Store ()
51+ err := c .sigobj .Call ("org.freedesktop.systemd1.Manager.Unsubscribe" , 0 ).Store ()
5252 if err != nil {
5353 return err
5454 }
5555
5656 return nil
5757}
5858
59- func (c * Conn ) initSubscription () {
60- c .subscriber .ignore = make (map [dbus.ObjectPath ]int64 )
61- }
62-
63- func (c * Conn ) initDispatch () {
59+ func (c * Conn ) dispatch () {
6460 ch := make (chan * dbus.Signal , signalBuffer )
6561
66- c .sysconn .Signal (ch )
62+ c .sigconn .Signal (ch )
6763
6864 go func () {
6965 for {
@@ -72,24 +68,32 @@ func (c *Conn) initDispatch() {
7268 return
7369 }
7470
75- switch signal .Name {
76- case "org.freedesktop.systemd1.Manager.JobRemoved" :
71+ if signal .Name == "org.freedesktop.systemd1.Manager.JobRemoved" {
7772 c .jobComplete (signal )
73+ }
74+
75+ if c .subscriber .updateCh == nil {
76+ continue
77+ }
7878
79+ var unitPath dbus.ObjectPath
80+ switch signal .Name {
81+ case "org.freedesktop.systemd1.Manager.JobRemoved" :
7982 unitName := signal .Body [2 ].(string )
80- var unitPath dbus.ObjectPath
8183 c .sysobj .Call ("org.freedesktop.systemd1.Manager.GetUnit" , 0 , unitName ).Store (& unitPath )
82- if unitPath != dbus .ObjectPath ("" ) {
83- c .sendSubStateUpdate (unitPath )
84- }
8584 case "org.freedesktop.systemd1.Manager.UnitNew" :
86- c . sendSubStateUpdate ( signal .Body [1 ].(dbus.ObjectPath ) )
85+ unitPath = signal .Body [1 ].(dbus.ObjectPath )
8786 case "org.freedesktop.DBus.Properties.PropertiesChanged" :
8887 if signal .Body [0 ].(string ) == "org.freedesktop.systemd1.Unit" {
89- // we only care about SubState updates, which are a Unit property
90- c .sendSubStateUpdate (signal .Path )
88+ unitPath = signal .Path
9189 }
9290 }
91+
92+ if unitPath == dbus .ObjectPath ("" ) {
93+ continue
94+ }
95+
96+ c .sendSubStateUpdate (unitPath )
9397 }
9498 }()
9599}
@@ -176,9 +180,6 @@ func (c *Conn) SetSubStateSubscriber(updateCh chan<- *SubStateUpdate, errCh chan
176180func (c * Conn ) sendSubStateUpdate (path dbus.ObjectPath ) {
177181 c .subscriber .Lock ()
178182 defer c .subscriber .Unlock ()
179- if c .subscriber .updateCh == nil {
180- return
181- }
182183
183184 if c .shouldIgnore (path ) {
184185 return
0 commit comments