Skip to content

Commit efa8cb5

Browse files
committed
Add investigation: can dbus-broker replace dbus-daemon for ruby-dbus?
Document findings on dbus-broker compatibility. The library works transparently with dbus-broker since it only connects via socket addresses. The test suite explicitly spawns dbus-daemon and would need changes (e.g. migrating to dbus-run-session) to be fully daemon-agnostic. https://claude.ai/code/session_017TKMdbvByVBNUpfkLHMJea
1 parent 4a6c96d commit efa8cb5

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

doc/dbus-broker-investigation.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Can dbus-broker replace dbus-daemon for ruby-dbus?
2+
3+
## Summary
4+
5+
**Yes, mostly.** For normal library usage (connecting to the system or session
6+
bus), dbus-broker is a transparent drop-in — ruby-dbus simply connects to a
7+
socket address and doesn't care which daemon is behind it. For **testing**,
8+
the situation is more nuanced because the test suite explicitly spawns
9+
`dbus-daemon`.
10+
11+
## What is dbus-broker?
12+
13+
dbus-broker is a Linux-native reimplementation of the D-Bus message bus. It is
14+
wire-compatible with dbus-daemon and is already the **default** on Fedora and
15+
Arch Linux. Key improvements over dbus-daemon:
16+
17+
- **Reliability**: no silently dropped messages
18+
- **Performance**: O(log n) lookups vs O(n) in dbus-daemon
19+
- **Accounting**: per-user resource quotas resistant to chaining-exhaustion
20+
- **Security**: resistant to deadlocks and DoS attacks
21+
22+
The main caveat: `dbus-broker-launch` (the compatibility launcher) **requires
23+
systemd** for service activation. The broker binary itself has no hard
24+
dependencies beyond libc.
25+
26+
## How ruby-dbus uses dbus-daemon
27+
28+
### 1. Runtime library (no direct dependency)
29+
30+
The library code in `lib/dbus/` never spawns or references `dbus-daemon`
31+
directly. It connects to a bus via:
32+
33+
- **Session bus** (`lib/dbus/bus.rb`): reads `DBUS_SESSION_BUS_ADDRESS` env
34+
var, or falls back to `~/.dbus/session-bus/*` files, or macOS launchd.
35+
- **System bus** (`lib/dbus/bus.rb`): reads `DBUS_SYSTEM_BUS_ADDRESS` env var,
36+
or defaults to `unix:path=/var/run/dbus/system_bus_socket`.
37+
- **Connection** (`lib/dbus/message_queue.rb`): connects to unix sockets, TCP,
38+
or launchd — pure socket-level, daemon-agnostic.
39+
40+
**Conclusion**: If the system runs dbus-broker instead of dbus-daemon, the
41+
library works without any changes. The bus address and wire protocol are
42+
identical.
43+
44+
### 2. Test infrastructure (explicit dbus-daemon dependency)
45+
46+
The test suite spawns a **private session bus** to run integration tests in
47+
isolation:
48+
49+
- **`spec/spec_helper.rb`**`with_private_bus` spawns:
50+
```
51+
dbus-daemon --nofork --config-file=spec/tools/dbus-limited-session.conf \
52+
--print-address=3 --print-pid=4
53+
```
54+
- **`spec/tools/dbus-launch-simple`** — shell script that does the same, used
55+
by `spec/tools/test_env`.
56+
- **`spec/tools/dbus-limited-session.conf`** — XML config file for the test
57+
bus (session type, custom limits, multiple listen addresses including TCP).
58+
59+
Both launchers wait for the daemon to write its address and PID to temp files,
60+
then set `DBUS_SESSION_BUS_ADDRESS` for the tests.
61+
62+
### 3. CI
63+
64+
`.travis.yml` installs the `dbus` apt package. GitHub Actions
65+
(`.github/workflows/ruby.yml`) relies on the system-installed dbus.
66+
67+
## Can dbus-broker replace dbus-daemon here?
68+
69+
### For users of the library: YES, transparently
70+
71+
No changes needed. If the system session/system bus is provided by dbus-broker,
72+
ruby-dbus connects to it exactly the same way.
73+
74+
### For the test suite: NOT a drop-in replacement
75+
76+
The test suite invokes `dbus-daemon` directly with `--nofork`,
77+
`--config-file`, `--print-address`, and `--print-pid` flags. dbus-broker's
78+
`dbus-broker-launch` is **not** a CLI-compatible replacement for
79+
`dbus-daemon` — it has a different command-line interface and requires systemd
80+
for service activation.
81+
82+
To support running tests against dbus-broker, we would need to either:
83+
84+
1. **Keep using dbus-daemon for tests** (simplest, it remains available even on
85+
dbus-broker systems since dbus-broker doesn't remove dbus-daemon).
86+
2. **Use `dbus-run-session`** instead of invoking dbus-daemon directly.
87+
`dbus-run-session` is a small wrapper (from the dbus package) that starts a
88+
private session bus and runs a command within it. It works with whichever
89+
daemon is installed and is simpler than our custom launcher. This would be
90+
the cleanest approach.
91+
3. **Abstract the daemon launch** so tests can use either dbus-daemon or
92+
dbus-broker-launch, selected by an env var. This is more complex and
93+
probably not worth it.
94+
95+
### Recommendation
96+
97+
- The **library itself** needs no changes for dbus-broker compatibility.
98+
- For **testing**, consider migrating from the hand-rolled `dbus-launch-simple`
99+
/ `with_private_bus` to `dbus-run-session` which is daemon-agnostic. Even
100+
without this change, tests will continue to work since dbus-daemon remains
101+
installable alongside dbus-broker on all major distributions.
102+
103+
## References
104+
105+
- [dbus-broker wiki](https://github.com/bus1/dbus-broker/wiki)
106+
- [Fedora: Make dbus-broker the default](https://fedoraproject.org/wiki/Changes/DbusBrokerAsTheDefaultDbusImplementation)
107+
- [Arch Linux RFC 0025](https://rfc.archlinux.page/0025-dbus-broker-default/)
108+
- [Arch Linux D-Bus wiki](https://wiki.archlinux.org/title/D-Bus)
109+
- [LWN: The D-Bus Broker project](https://lwn.net/Articles/731755/)

0 commit comments

Comments
 (0)