Products › lamco-dbus-tools › Docs
Record one program's D-Bus traffic behind a relay
Record one program's D-Bus traffic behind a relay with dbusdo relay: The moments it sent and received each message, its authentication, and what the bus saw.
Describes version 0.4.1.
Needs dbusdo and a bus this user can connect to. Layer 6: The program's connection goes through the
relay, and the bus sees the relay's process instead of the program's. It suits a program started for the
purpose.
A monitor sees what the bus passed on. The relay sits on one program's own socket, so it sees that program's moments: When it sent each message, within a hop of the socket, and when each answer reached it. It also sees the program's authentication, which no monitor does.
$ dbusdo --out relayed.json relay busctl --user call org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.DBus.Peer Ping
Relayed 2 messages to the bus and 3 back, on 1 connections, 0 descriptors passed. The bus saw this relay, process 1925023, where the program is process 1925025. The relay started the program, so the two start out with the same user, login session and cgroup: A service that asks the bus who called gets the relay's pid, pidfd and executable, and polkit and the portals, which go by the session, the user and the cgroup, see the program's own. Behind the relay a program is on the bus as uid 1000, whatever user it runs as: One that changes user gets in when its library lets the bus read the socket's credentials, as sd-bus and GLib do, and is refused when it names its own uid, as libdbus does.
relay takes the rest of the chain as the program and its arguments, so it's the last link. Write --
before a program whose name starts with --. --bus system runs the program on the system bus.
The program is given DBUS_SESSION_BUS_ADDRESS, or DBUS_SYSTEM_BUS_ADDRESS with --bus system, naming
the relay's socket, in a directory only this user can enter. A program that ignores the variable and
finds its bus another way isn't relayed, and the relay says it saw no connections.
Reading what it recorded
Every lens reads the capture:
$ dbustell timing relayed.json
2 calls asked for a reply: 2 replied, 0 answered with an error, 0 had no answer by the end. 0 asked for none.
Each figure runs from the relay reading the call from the program to the relay reading its answer from the bus: It holds the call's way to the bus, the bus's queueing, the service waking and working, and the answer's way back to the relay. A different figure from a monitor's, never pooled with one. Times are the recorder's arrival times, on CLOCK_MONOTONIC.
...
DESTINATION METHOD CALLS ERR MIN MEDIAN 95TH 99TH MAX
org.freedesktop.DBus org.freedesktop.DBus.Hello 1 0 339.62 µs 339.62 µs 339.62 µs 339.62 µs 339.62 µs
org.freedesktop.systemd1 org.freedesktop.DBus.Peer.Ping 1 0 148.58 µs 148.58 µs 148.58 µs 148.58 µs 148.58 µs
The figure is the relay's own, and the report names it so. The capture holds:
- The authentication lines, each way. A
DATAline's contents aren't kept, only its length. - Each message, as a monitor would record it, with the leg it went (
to_bus,to_program), its connection, and two stamps: When the relay read it and when it had passed it on. - The relay's act: The program, both pids, its exit status, the connections, how many messages and file descriptors went each way, and what the bus saw instead of the program.
--bodies keeps as much of each body as for dbussee record: length by default.
What changes for the program
- Its time. A call through the relay takes about 20 to 30 µs longer at the caller, measured on calls to the bus driver. A call to a real service, which takes milliseconds, hardly changes.
- The process the bus names. A service that asks the bus who called gets the relay's pid, pidfd and executable. The relay starts the program, so they share the user, the login session and the cgroup, and polkit and the portals, which decide by those, see the program's own.
- A program that changes user, through
sudofor one, reaches the bus as the relay's user when its library lets the bus read the socket's credentials, as sd-bus and GLib do. One that names its own uid, as libdbus does, is refused, and the relay's act says so with the uid it named.
Bytes pass unchanged, and file descriptors with the bytes they came with, so a program that receives a
pidfd or a file from a service works as without the relay. A relay that doesn't pass descriptors, such as
socat, hangs such a program.
What can go wrong
- The program's own exit status is the act's: When it fails,
relayfails anddbusdoexits 1. Not read back: ...: The relay couldn't read the stream back as D-Bus after some point. The bytes were still passed on, so the program went on working; the capture stops there for that connection.- The relay ends when the program does, and closes any connection still open then, a child's included.
docs/measurements/stage-6/README.md has the measurements.