dbus: handle bizarre dbus proxy behaviour
All checks were successful
Test / Create distribution (push) Successful in 28s
Test / Sandbox (push) Successful in 1m53s
Test / Fortify (push) Successful in 2m44s
Test / Sandbox (race detector) (push) Successful in 3m2s
Test / Fpkg (push) Successful in 3m36s
Test / Fortify (race detector) (push) Successful in 4m16s
Test / Flake checks (push) Successful in 1m17s
All checks were successful
Test / Create distribution (push) Successful in 28s
Test / Sandbox (push) Successful in 1m53s
Test / Fortify (push) Successful in 2m44s
Test / Sandbox (race detector) (push) Successful in 3m2s
Test / Fpkg (push) Successful in 3m36s
Test / Fortify (race detector) (push) Successful in 4m16s
Test / Flake checks (push) Successful in 1m17s
There is a strange behaviour in xdg-dbus-proxy where if any interface string when stripped of a single ".*" suffix does not contain a '.' byte anywhere, the program will exit with code 1 without any output. This checks for such conditions to make the failure less confusing. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
f30a439bcd
commit
dde2516304
@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ProxyPair is an upstream dbus address and a downstream socket path.
|
||||
@ -27,6 +28,61 @@ type Config struct {
|
||||
Filter bool `json:"filter"`
|
||||
}
|
||||
|
||||
func (c *Config) interfaces(yield func(string) bool) {
|
||||
for _, iface := range c.See {
|
||||
if !yield(iface) {
|
||||
return
|
||||
}
|
||||
}
|
||||
for _, iface := range c.Talk {
|
||||
if !yield(iface) {
|
||||
return
|
||||
}
|
||||
}
|
||||
for _, iface := range c.Own {
|
||||
if !yield(iface) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
for iface := range c.Call {
|
||||
if !yield(iface) {
|
||||
return
|
||||
}
|
||||
}
|
||||
for iface := range c.Broadcast {
|
||||
if !yield(iface) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Config) checkInterfaces(segment string) error {
|
||||
for iface := range c.interfaces {
|
||||
/*
|
||||
xdg-dbus-proxy fails without output when this condition is not met:
|
||||
char *dot = strrchr (filter->interface, '.');
|
||||
if (dot != NULL)
|
||||
{
|
||||
*dot = 0;
|
||||
if (strcmp (dot + 1, "*") != 0)
|
||||
filter->member = g_strdup (dot + 1);
|
||||
}
|
||||
|
||||
trim ".*" since they are removed before searching for '.':
|
||||
if (g_str_has_suffix (name, ".*"))
|
||||
{
|
||||
name[strlen (name) - 2] = 0;
|
||||
wildcard = TRUE;
|
||||
}
|
||||
*/
|
||||
if strings.IndexByte(strings.TrimSuffix(iface, ".*"), '.') == -1 {
|
||||
return &BadInterfaceError{iface, segment}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Config) Args(bus ProxyPair) (args []string) {
|
||||
argc := 2 + len(c.See) + len(c.Talk) + len(c.Own) + len(c.Call) + len(c.Broadcast)
|
||||
if c.Log {
|
||||
@ -63,9 +119,7 @@ func (c *Config) Args(bus ProxyPair) (args []string) {
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Config) Load(r io.Reader) error {
|
||||
return json.NewDecoder(r).Decode(&c)
|
||||
}
|
||||
func (c *Config) Load(r io.Reader) error { return json.NewDecoder(r).Decode(&c) }
|
||||
|
||||
// NewConfigFromFile opens the target config file at path and parses its contents into *Config.
|
||||
func NewConfigFromFile(path string) (*Config, error) {
|
||||
|
@ -2,6 +2,7 @@ package dbus
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os/exec"
|
||||
"sync"
|
||||
@ -14,6 +15,15 @@ import (
|
||||
// Overriding ProxyName will only affect Proxy instance created after the change.
|
||||
var ProxyName = "xdg-dbus-proxy"
|
||||
|
||||
type BadInterfaceError struct {
|
||||
Interface string
|
||||
Segment string
|
||||
}
|
||||
|
||||
func (e *BadInterfaceError) Error() string {
|
||||
return fmt.Sprintf("bad interface string %q in %s bus configuration", e.Interface, e.Segment)
|
||||
}
|
||||
|
||||
// Proxy holds the state of a xdg-dbus-proxy process, and should never be copied.
|
||||
type Proxy struct {
|
||||
helper helper.Helper
|
||||
@ -66,9 +76,15 @@ func Finalise(sessionBus, systemBus ProxyPair, session, system *Config) (final *
|
||||
|
||||
var args []string
|
||||
if session != nil {
|
||||
if err = session.checkInterfaces("session"); err != nil {
|
||||
return
|
||||
}
|
||||
args = append(args, session.Args(sessionBus)...)
|
||||
}
|
||||
if system != nil {
|
||||
if err = system.checkInterfaces("system"); err != nil {
|
||||
return
|
||||
}
|
||||
args = append(args, system.Args(systemBus)...)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user