Skip to content
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

Merged
merged 2 commits into from
Feb 2, 2018

Conversation

dtnaylor
Copy link
Contributor

This PR 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.)

lucab
lucab previously requested changes Jan 31, 2018
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])
Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, will make private.

@@ -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))
Copy link
Contributor

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).

case c.propertiesSubscriber.updateCh <- update:
default:
select {
case c.propertiesSubscriber.errCh <- errors.New("update channel full!"):
Copy link
Contributor

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 😃 .

select {
case c.propertiesSubscriber.errCh <- errors.New("update channel full!"):
default:
}
Copy link
Contributor

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.

@lucab
Copy link
Contributor

lucab commented Jan 31, 2018

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 SetPropertiesSubscriber codepath?

@dtnaylor dtnaylor force-pushed the property_subscriber branch 2 times, most recently from 11b65cf to 8bcb5df Compare February 1, 2018 00:39
@dtnaylor
Copy link
Contributor Author

dtnaylor commented Feb 1, 2018

Ok, those fixups should address your comments. I'm happy to squash and rebase once #249 is in if this looks good.

@lucab
Copy link
Contributor

lucab commented Feb 1, 2018

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.

@lucab lucab changed the title Systemd unit property subscriber dbus: add SetPropertiesSubscriber method Feb 1, 2018
@lucab lucab dismissed their stale review February 1, 2018 10:18

Stale review, dismissing.

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.)
@dtnaylor dtnaylor force-pushed the property_subscriber branch from 8bcb5df to 6579259 Compare February 1, 2018 17:08
@dtnaylor
Copy link
Contributor Author

dtnaylor commented Feb 1, 2018

Great—squashed and rebased.

@lucab lucab merged commit 90ece6e into coreos:master Feb 2, 2018
@lucab lucab modified the milestone: v17 May 7, 2018
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Mar 28, 2019
- 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]>
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Mar 28, 2019
- 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]>
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Apr 12, 2019
- 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]>
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Apr 12, 2019
- 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]>
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Apr 12, 2019
- 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]>
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Apr 25, 2019
- 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]>
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Jul 14, 2019
- 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]>
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Aug 26, 2019
- 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]>
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Sep 5, 2019
- 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]>
stefanberger pushed a commit to stefanberger/runc that referenced this pull request Dec 31, 2019
- 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]>
adrianreber pushed a commit to adrianreber/runc that referenced this pull request Feb 10, 2020
- 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants