diff --git a/README.md b/README.md index 4d5c6e3..9ecf04a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/tools/dbus-daemon.skel b/tools/dbus-daemon.skel new file mode 100755 index 0000000..abcbdd0 --- /dev/null +++ b/tools/dbus-daemon.skel @@ -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}"