Simon,
Thanks for this.
On Sat, Feb 21, 2026 at 03:09:41AM +0000, Simon McVittie wrote:
> There are three ways to wait for dbus-daemon to be ready:
>
> 1. Wait for `dbus-daemon --fork` to exit with status 0, which indicates
> that the long-running dbus-daemon process has finished startup,
> double-forked and been reparented to pid 1. This is how
> /etc/init.d/dbus works.
If I understand correctly, this is not suitable as it puts dbus-daemon in new
session group.
> 2. Use `dbus-daemon --print-address=$FD` and/or
> `dbus-daemon --print-pid=$FD` where $FD is the file descriptor number
> of the write end of a pipe, and wait for EOF on the read end of the
> same pipe before continuing. This is how dbus-run-session(1) works.
I believe this is implemented as attached. Initial testing is OK. It probably
needs a read timeout as well.
Thanks
Mark
#!/bin/sh
DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/bus"
die() {
echo "$@" >&2
exit 1
}
tmp_dir=$(mktemp -d)
[ -d "$tmp_dir" ] || die "Failed to create ready notification directory"
ready_pipe="$tmp_dir/fifo"
mkfifo "$ready_pipe" || die "Failed to create notification pipe"
exec 3<> "$ready_pipe"
rm -r "$tmp_dir"
dbus-daemon --session --nofork --address=$DBUS_SESSION_BUS_ADDRESS
--print-address=3 &
read -r ready <&3
[ "$ready" = "$DBUS_SESSION_BUS_ADDRESS" ] || die "Failed to start user session
bus on $DBUS_SESSION_BUS_ADDRESS"
if [ "$XDG_RUNTIME_DIR" = "/run/user/$(id -u)" ]; then
echo export DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS" >>
"$XDG_RUNTIME_DIR/profile"
fi