Skip to content

Commit

Permalink
s6: provide fake dbus-daemon executable as bash script
Browse files Browse the repository at this point in the history
gdm expects to launch a dbus-daemon executable to create GNOME's session
bus
  • Loading branch information
st3r4g committed Dec 3, 2021
1 parent 1efa513 commit 9471c1f
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,10 @@ for the system and session bus, respectively.
You are free to further tweak this scandir as you like, for example removing
unwanted activatable services.

Some programs currently launch an hardcoded `dbus-daemon` executable. An
example is `gdm`, to spawn the user's session bus. In order to make them work, a
fake `dbus-daemon` is provided as `tools/dbus-daemon.skel`. Fill in
`DBUS_SERVICEREPO=` with the path to the directory generated by `s6-generator`.

[dbus-broker]: https://github.com/bus1/dbus-broker
[s6]: https://skarnet.org/software/s6
76 changes: 76 additions & 0 deletions tools/dbus-daemon.skel
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash
# dbus-daemon executable for compatibility with stuff that launches dbus-daemon, such as gdm

# this needs to be filled in, it's the directory generated by s6-generator
DBUS_SERVICEREPO=

warn() { echo warning: "$*" 1>&2 ; }
die() { echo error: "$*" 1>&2 ; exit 1; }

[ -z "$DBUS_SERVICEREPO" ] && die "variable DBUS_SERVICEREPO is empty"
[ -z "$XDG_RUNTIME_DIR" ] && die "variable XDG_RUNTIME_DIR is empty"
[ -d "$XDG_RUNTIME_DIR" ] || die "XDG_RUNTIME_DIR is not a directory"

DBUS_RUNTIME_DIR=$(mktemp -d "$XDG_RUNTIME_DIR/dbus-XXXXXXXXXX")
DBUS_SOCKET_PATH="$DBUS_RUNTIME_DIR/session_bus_socket"
DBUS_SCANDIR="$DBUS_RUNTIME_DIR/scandir"

# from /usr/share/doc/util-linux/getopt-example.bash
TEMP=$(getopt -q -o '' --long 'nofork,print-address:,session' -- "$@")
# NOTE: we cannot make the argument of print-address optional otherwise the '=' separator is required

eval set -- "$TEMP"
unset TEMP

while true; do
case "$1" in
'--print-address')
# I hope that 4<&4- is a no-op... seems to be the case
exec 4<&${2}-
print_address_fd=4
shift 2
continue
;;
'--session')
shift
continue
;;
'--nofork')
shift
continue
;;
'--')
shift
break
;;
*)
warn "ignoring unknown argument"
;;
esac
done

cp -a ${DBUS_SERVICEREPO} ${DBUS_SCANDIR}

# how do we avoid closing 4 when print_address_fd is not 4? should we care?
DBUS_SESSION_BUS_ADDRESS="unix:path=${DBUS_SOCKET_PATH}" s6-svscan ${DBUS_SCANDIR} 4<&- &

# Notification FD
pid_fifo=$(mktemp --dry-run)
mkfifo -m 600 "${pid_fifo}"
exec 3<>"${pid_fifo}"

rm "${pid_fifo}"

dbus-controller-s6 -3 -d ${DBUS_SOCKET_PATH} -a ${DBUS_SCANDIR} dbus-broker 4<&- &

read -r pid <&3
exec 3<&-

if [ -n "${print_address_fd}" ]; then
printf "unix:path=${DBUS_SOCKET_PATH}\n" >&${print_address_fd}
[ "${print_address_fd}" -eq 4 ] && exec 4<&-
fi

wait

rm -rf "${DBUS_RUNTIME_DIR}"

0 comments on commit 9471c1f

Please sign in to comment.