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
interfaces: support D-Bus activation #6258
Changes from 42 commits
f9209c2
2324695
70ad190
ca5a1a5
4b4fab4
651d584
447c0f4
ed3c4ac
be08f4f
74ad61f
6f01882
b4f85d6
f192269
c1337f2
4d64766
8ef5358
0392c81
e7fb17c
3be7f06
e3615af
7a933c2
9b47622
1d89564
c090c3c
c29c5db
bba40c3
7d2edb0
3f958aa
7eeca84
8e9d600
ff3ee18
10f73a5
8f02916
3494675
7e878e6
d52872e
81bea96
6642c75
5c74fd0
07304db
31df3de
eefbc10
1c5533b
9c307da
f2f3485
d9f934e
44ea334
dc3a065
61dbfe8
c8283a7
90d6838
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<!-- keep in sync with interfaces/dbus/backend.go:setupHostDBusConf() --> | ||
<busconfig> | ||
<servicedir>/var/lib/snapd/dbus/services/</servicedir> | ||
</busconfig> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<!-- keep in sync with interfaces/dbus/backend.go:setupHostDBusConf() --> | ||
<busconfig> | ||
<servicedir>/var/lib/snapd/dbus/system-services/</servicedir> | ||
</busconfig> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ package builtin | |
import ( | ||
"bytes" | ||
"fmt" | ||
"os" | ||
"regexp" | ||
"strings" | ||
|
||
|
@@ -231,9 +232,8 @@ func (iface *dbusInterface) StaticInfo() interfaces.StaticInfo { | |
var isInvalidSnappyBusName = regexp.MustCompile("-[0-9]+$").MatchString | ||
|
||
// Obtain yaml-specified bus well-known name | ||
func (iface *dbusInterface) getAttribs(attribs interfaces.Attrer) (string, string, error) { | ||
func (iface *dbusInterface) getAttribs(attribs interfaces.Attrer) (bus, name string, err error) { | ||
// bus attribute | ||
var bus string | ||
if err := attribs.Attr("bus", &bus); err != nil { | ||
return "", "", fmt.Errorf("cannot find attribute 'bus'") | ||
} | ||
|
@@ -243,13 +243,11 @@ func (iface *dbusInterface) getAttribs(attribs interfaces.Attrer) (string, strin | |
} | ||
|
||
// name attribute | ||
var name string | ||
if err := attribs.Attr("name", &name); err != nil { | ||
return "", "", fmt.Errorf("cannot find attribute 'name'") | ||
} | ||
|
||
err := interfaces.ValidateDBusBusName(name) | ||
if err != nil { | ||
if err = interfaces.ValidateDBusBusName(name); err != nil { | ||
return "", "", err | ||
} | ||
|
||
|
@@ -350,13 +348,24 @@ func (iface *dbusInterface) DBusPermanentSlot(spec *dbus.Specification, slot *sn | |
} | ||
|
||
// only system services need bus policy | ||
if bus != "system" { | ||
return nil | ||
if bus == "system" { | ||
old := "###DBUS_NAME###" | ||
new := name | ||
spec.AddSnippet(strings.Replace(dbusPermanentSlotDBus, old, new, -1)) | ||
} | ||
|
||
old := "###DBUS_NAME###" | ||
new := name | ||
spec.AddSnippet(strings.Replace(dbusPermanentSlotDBus, old, new, -1)) | ||
// handle activatable services | ||
for _, app := range slot.Apps { | ||
for _, slotName := range app.ActivatesOn { | ||
if slotName == slot.Name { | ||
err = spec.AddService(bus, name, app) | ||
if err != nil { | ||
return err | ||
} | ||
break | ||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
|
@@ -428,8 +437,49 @@ func (iface *dbusInterface) BeforePreparePlug(plug *snap.PlugInfo) error { | |
} | ||
|
||
func (iface *dbusInterface) BeforePrepareSlot(slot *snap.SlotInfo) error { | ||
_, _, err := iface.getAttribs(slot) | ||
return err | ||
bus, name, err := iface.getAttribs(slot) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var apps []*snap.AppInfo | ||
for _, app := range slot.Apps { | ||
for _, slotName := range app.ActivatesOn { | ||
if slotName == slot.Name { | ||
apps = append(apps, app) | ||
break | ||
} | ||
} | ||
} | ||
if len(apps) > 1 { | ||
return fmt.Errorf("cannot add activatable dbus service slot to multiple apps") | ||
} | ||
if len(apps) == 1 { | ||
app := apps[0] | ||
if !app.IsService() { | ||
return fmt.Errorf("only daemons can be activatable D-Bus services") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This made me realize that the proper spelling is indeed |
||
} | ||
switch app.DaemonScope { | ||
case snap.SystemDaemon: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should all of this not be done by validation in the |
||
if bus != "system" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be a constant in |
||
return fmt.Errorf("system daemons can only activate from the D-Bus system bus") | ||
} | ||
case snap.UserDaemon: | ||
if bus != "session" { | ||
return fmt.Errorf("user daemons can only activate from the D-Bus session bus") | ||
} | ||
} | ||
if owner, err := dbus.BusNameOwner(bus, name); err != nil { | ||
if !os.IsNotExist(err) { | ||
return err | ||
} | ||
} else if owner == "" { | ||
return fmt.Errorf("bus name %q is owned by a non-snap application", name) | ||
} else if owner != slot.Snap.InstanceName() { | ||
return fmt.Errorf("bus name %q is already owned by snap %q", name, owner) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (iface *dbusInterface) AutoConnect(*snap.PlugInfo, *snap.SlotInfo) bool { | ||
|
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.
will there be dbus-2 ? should this be dbus-1? or no chance of that being an issue?
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.
I think this was some forward thinking by DBus authors. There might be dbus-2 eventually or never, depending on how things evolve.