-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
s6: provide fake dbus-daemon executable as bash script
gdm expects to launch a dbus-daemon executable to create GNOME's session bus
- Loading branch information
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |