-
Notifications
You must be signed in to change notification settings - Fork 313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dbus: add SetPropertiesSubscriber method #248
Conversation
dbus/dbus.go
Outdated
for i := 0; i < len(path); i++ { | ||
c := path[i] | ||
if c == '_' { | ||
res, err := hex.DecodeString(path[i+1 : i+3]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before looking ahead, please check that i+3
does not overflow len(path)
.
dbus/dbus.go
Outdated
@@ -60,6 +61,27 @@ func PathBusEscape(path string) string { | |||
return string(n) | |||
} | |||
|
|||
// PathBusUnescape is the inverse of PathBusEscape. | |||
func PathBusUnescape(path string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need this to be public in order to use it in your consuming application? If not, I'd prefer to keep it private for the moment, we can always export it later if required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, will make private.
dbus/subscription.go
Outdated
@@ -84,6 +85,7 @@ func (c *Conn) dispatch() { | |||
case "org.freedesktop.DBus.Properties.PropertiesChanged": | |||
if signal.Body[0].(string) == "org.freedesktop.systemd1.Unit" { | |||
unitPath = signal.Path | |||
c.sendPropertiesUpdate(unitPath, signal.Body[1].(map[string]dbus.Variant)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a len(signal.Body) >= 2
check and a type-check for signal.Body[1].(map[string]dbus.Variant)
.
dbus/subscription.go
Outdated
case c.propertiesSubscriber.updateCh <- update: | ||
default: | ||
select { | ||
case c.propertiesSubscriber.errCh <- errors.New("update channel full!"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"update channel is full", no need for exclamation marks 😃 .
dbus/subscription.go
Outdated
select { | ||
case c.propertiesSubscriber.errCh <- errors.New("update channel full!"): | ||
default: | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the linter doesn't complain about a spurious return (I didn't try), perhaps consider adding an explicit return
after the inner select block. That way, code eventually added at the bottom is already fine with error handling.
Thanks for your PR, I left a few comments. This will probably conflict with #249, thus depending on timings you may need to rebase at some later point. Can you add at least a simple test to exercise |
11b65cf
to
8bcb5df
Compare
Ok, those fixups should address your comments. I'm happy to squash and rebase once #249 is in if this looks good. |
Thanks, I'm fine with this. Just squash and rebase your commits, I'll take care of merging this before #249 and then solve conflicts on my side. |
This commit adds a SetPropertiesSubscriber method which is similar to SetSubStateSubscriber but with two important differences: * Each update includes all changed properties, not just SubState * Each set of property values from systemd is reported; no update can be missed. With SubStateSubscriber, transient states can be missed because sendSubStateUpdate calls GetUnitPathProperties after receiving the original signal from systemd; by this point, the unit's state may have changed again. (This behavior is clearly documented, but for some use cases it might not be acceptable to miss a state transition.)
8bcb5df
to
6579259
Compare
Great—squashed and rebased. |
- https://github.com/coreos/go-systemd/compare/v14..v19 - coreos/go-systemd#248 dbus: add SetPropertiesSubscriber method - coreos/go-systemd#251 activation: add support for listeners with names - coreos/go-systemd#296 dbus: Fix API break from godbus - coreos/pkg@v3...v4 - no changes in vendored code - https://github.com/godbus/dbus/compare/v3..v5.0.1 - godbus/dbus#89 introduce MakeVariantWithSignature Signed-off-by: Sebastiaan van Stijn <[email protected]>
- https://github.com/coreos/go-systemd/compare/v14..v19 - coreos/go-systemd#248 dbus: add SetPropertiesSubscriber method - coreos/go-systemd#251 activation: add support for listeners with names - coreos/go-systemd#296 dbus: Fix API break from godbus - coreos/pkg@v3...v4 - no changes in vendored code - https://github.com/godbus/dbus/compare/v3..v5.0.1 - godbus/dbus#89 introduce MakeVariantWithSignature Signed-off-by: Sebastiaan van Stijn <[email protected]>
- https://github.com/coreos/go-systemd/compare/v14..v19 - coreos/go-systemd#248 dbus: add SetPropertiesSubscriber method - coreos/go-systemd#251 activation: add support for listeners with names - coreos/go-systemd#296 dbus: Fix API break from godbus - coreos/pkg@v3...v4 - no changes in vendored code - https://github.com/godbus/dbus/compare/v3..v5.0.1 - godbus/dbus#89 introduce MakeVariantWithSignature Signed-off-by: Sebastiaan van Stijn <[email protected]>
- https://github.com/coreos/go-systemd/compare/v14..v19 - coreos/go-systemd#248 dbus: add SetPropertiesSubscriber method - coreos/go-systemd#251 activation: add support for listeners with names - coreos/go-systemd#296 dbus: Fix API break from godbus - coreos/pkg@v3...v4 - no changes in vendored code - https://github.com/godbus/dbus/compare/v3..v5.0.1 - godbus/dbus#89 introduce MakeVariantWithSignature Signed-off-by: Sebastiaan van Stijn <[email protected]>
- https://github.com/coreos/go-systemd/compare/v14..v19 - coreos/go-systemd#248 dbus: add SetPropertiesSubscriber method - coreos/go-systemd#251 activation: add support for listeners with names - coreos/go-systemd#296 dbus: Fix API break from godbus - coreos/pkg@v3...v4 - no changes in vendored code - https://github.com/godbus/dbus/compare/v3..v5.0.1 - godbus/dbus#89 introduce MakeVariantWithSignature Signed-off-by: Sebastiaan van Stijn <[email protected]>
- https://github.com/coreos/go-systemd/compare/v14..v19 - coreos/go-systemd#248 dbus: add SetPropertiesSubscriber method - coreos/go-systemd#251 activation: add support for listeners with names - coreos/go-systemd#296 dbus: Fix API break from godbus - coreos/pkg@v3...v4 - no changes in vendored code - https://github.com/godbus/dbus/compare/v3..v5.0.1 - godbus/dbus#89 introduce MakeVariantWithSignature Signed-off-by: Sebastiaan van Stijn <[email protected]>
- https://github.com/coreos/go-systemd/compare/v14..v19 - coreos/go-systemd#248 dbus: add SetPropertiesSubscriber method - coreos/go-systemd#251 activation: add support for listeners with names - coreos/go-systemd#296 dbus: Fix API break from godbus - coreos/pkg@v3...v4 - no changes in vendored code - https://github.com/godbus/dbus/compare/v3..v5.0.1 - godbus/dbus#89 introduce MakeVariantWithSignature Signed-off-by: Sebastiaan van Stijn <[email protected]>
- https://github.com/coreos/go-systemd/compare/v14..v19 - coreos/go-systemd#248 dbus: add SetPropertiesSubscriber method - coreos/go-systemd#251 activation: add support for listeners with names - coreos/go-systemd#296 dbus: Fix API break from godbus - https://github.com/godbus/dbus/compare/v3..v5.0.1 - godbus/dbus#89 introduce MakeVariantWithSignature Signed-off-by: Sebastiaan van Stijn <[email protected]>
- https://github.com/coreos/go-systemd/compare/v14..v19 - coreos/go-systemd#248 dbus: add SetPropertiesSubscriber method - coreos/go-systemd#251 activation: add support for listeners with names - coreos/go-systemd#296 dbus: Fix API break from godbus - https://github.com/godbus/dbus/compare/v3..v5.0.1 - godbus/dbus#89 introduce MakeVariantWithSignature Signed-off-by: Sebastiaan van Stijn <[email protected]>
- https://github.com/coreos/go-systemd/compare/v14..v19 - coreos/go-systemd#248 dbus: add SetPropertiesSubscriber method - coreos/go-systemd#251 activation: add support for listeners with names - coreos/go-systemd#296 dbus: Fix API break from godbus - https://github.com/godbus/dbus/compare/v3..v5.0.1 - godbus/dbus#89 introduce MakeVariantWithSignature Signed-off-by: Sebastiaan van Stijn <[email protected]>
- https://github.com/coreos/go-systemd/compare/v14..v19 - coreos/go-systemd#248 dbus: add SetPropertiesSubscriber method - coreos/go-systemd#251 activation: add support for listeners with names - coreos/go-systemd#296 dbus: Fix API break from godbus - https://github.com/godbus/dbus/compare/v3..v5.0.1 - godbus/dbus#89 introduce MakeVariantWithSignature Signed-off-by: Sebastiaan van Stijn <[email protected]>
This PR adds a
SetPropertiesSubscriber
method which is similar toSetSubStateSubscriber
but with two important differences:missed. With
SubStateSubscriber
, transient states can be missedbecause
sendSubStateUpdate
callsGetUnitPathProperties
after receivingthe original signal from systemd; by this point, the unit's state may
have changed again. (This behavior is clearly documented, but for some
use cases it might not be acceptable to miss a state transition.)