Expand description
A minimal D-Bus client for the user session bus, for the provisioning’s two calls.
What:
A minimal D-Bus client for the user session bus: authenticate as the current user, say Hello, and call methods of
org.freedesktop.systemd1.Manager with string arguments, each bounded by one deadline for the whole exchange.
Why:
The wrapper provisions socket activation itself, and may start no program to do it (systemctl would be one). The
supported surface of the user manager is its D-Bus API (org.freedesktop.systemd1(5)), reached through the session
bus; the manager’s own private socket is documented as private to systemd. Only Reload, ResetFailedUnit,
StartUnit, StopUnit and the state query (GetUnit, then a property read) are needed, all with at most two string
arguments, so the writer and the reader below cover exactly the types those calls and the bus’s replies use (s, o,
g, u, and a variant holding s) and stop at anything else. The reader is total over arbitrary bytes (a
fuzz target holds it to that). The comparison with a D-Bus crate is in doc/planning/cli-git-resident-service.md,
“Provisioning”.
In TS you’d write (pseudocode):
const bus = await connect(address, 5000); await bus.startUnit('cli-git.socket', 'replace'); // throws with the error nameStructs§
- Bus
- An authenticated connection to the session bus, past
Hello. - Reply
- A reply: its type, the error name its header carries, and the first string of its body.
- Target
- Where a method call goes.
Enums§
- Call
Error - Why a call did not succeed.
Constants§
- EXCHANGE_
WAIT - How long the whole exchange (connect, authenticate, say hello, make the calls) may take; a stuck bus never holds a commit longer.
- GET_
UNIT GetUniton the user manager: the object path of a loaded unit.- HELLO
Helloon the bus daemon, the first call of every connection.- MANAGER_
INTERFACE - The manager’s interface.
- MANAGER_
NAME - The manager’s bus name.
- MANAGER_
PATH - The manager’s object path.
- NO_
SUCH_ UNIT - The error name of a unit the manager does not hold (never loaded, or unloaded after it stopped).
- RELOAD
Reloadon the user manager.- RESET_
FAILED_ UNIT ResetFailedUniton the user manager.- START_
UNIT StartUniton the user manager.- STOP_
UNIT StopUniton the user manager.
Functions§
- decode_
reply - What: Reads a complete reply message. Why: Only the type, the error name and the first string of the body matter; a header field of a kind this reader does not know ends the walk of the header, which is safe because the fields it needs come first in what the manager sends or are looked for before any unknown kind.
- encode_
call - What: The bytes of a method call with string arguments. Why: Kept apart from the socket so a test can read them back and compare them with the specification’s layout.
- session_
bus_ path - The path of the session bus socket: the
unix:path=entry of the address variable, else$XDG_RUNTIME_DIR/bus.