Skip to content

Commit

Permalink
dbus config
Browse files Browse the repository at this point in the history
- add script to monitor the dbus process (it is the linux OOM killer
its most favorite target)
- wait for dbus socket creation, so that after dbus start, the dbus
can be used..
- drill a big hole in the dbus config for the bpp3
  • Loading branch information
jhofstee committed Jan 29, 2016
1 parent 0d8313a commit 7bfdbb6
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 32 deletions.
16 changes: 16 additions & 0 deletions meta-venus/recipes-core/dbus/dbus_%.bbappend
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"

SRC_URI += " \
file://dbus-daemon-watch.sh \
file://system.conf \
"

RDEPENDS_${PN} = "inotify-tools"

do_install_append() {
install ${WORKDIR}/dbus-daemon-watch.sh ${D}${bindir}/dbus-daemon-watch.sh
}

do_install_append_bpp3() {
install -m 0644 ${WORKDIR}/system.conf ${D}${sysconfdir}/dbus-1/system.conf
}
53 changes: 21 additions & 32 deletions meta-venus/recipes-core/dbus/files/dbus-1.init
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,17 @@
# Debian init.d script for D-BUS
# Copyright © 2003 Colin Walters <walters@debian.org>

set -e
# set -e

DAEMON=/usr/bin/dbus-daemon
# Source function library.
. /etc/init.d/functions

DAEMON=@bindir@/dbus-daemon
NAME=dbus
DAEMONUSER=messagebus # must match /etc/dbus-1/system.conf
PIDFILE=/var/run/messagebus.pid # must match /etc/dbus-1/system.conf
UUIDDIR=/var/lib/dbus
DESC="system message bus"
EVENTDIR=/etc/dbus-1/event.d

test -x $DAEMON || exit 0

# Source defaults file; edit that file to configure this script.
ENABLED=1
PARAMS=""
if [ -e /etc/default/dbus ]; then
. /etc/default/dbus
fi

test "$ENABLED" != "0" || exit 0

start_it_up()
{
Expand All @@ -57,28 +48,22 @@ start_it_up()
dbus-uuidgen --ensure

echo -n "Starting $DESC: "
start-stop-daemon --start --quiet --pidfile $PIDFILE \
--user $DAEMONUSER --exec $DAEMON -- --system $PARAMS
echo "$NAME."
if [ -d $EVENTDIR ]; then
run-parts --arg=start $EVENTDIR
fi
# note dbus-daemon-watch.sh start dbus-daemon to catch crashes
start-stop-daemon -o --start --quiet --pidfile $PIDFILE \
--user $DAEMONUSER --exec /usr/bin/dbus-daemon-watch.sh -- --system
# wait for the socket creation
inotifywait -e create /var/run/dbus --timeout 10
}

shut_it_down()
{
if [ -d $EVENTDIR ]; then
# TODO: --reverse when busybox supports it
run-parts --arg=stop $EVENTDIR
# kill the script monitoring dbus execution
if [ "X${pid=$(pidof -x /usr/bin/dbus-daemon-watch.sh)}" != "X" ]; then
kill $pid
fi
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --pidfile $PIDFILE \
--user $DAEMONUSER
# We no longer include these arguments so that start-stop-daemon
# can do its job even given that we may have been upgraded.
# We rely on the pidfile being sanely managed
# --exec $DAEMON -- --system $PARAMS
echo "$NAME."

echo "Stopping $DESC"
start-stop-daemon --stop --quiet --pidfile $PIDFILE --user $DAEMONUSER
rm -f $PIDFILE
}

Expand All @@ -99,6 +84,10 @@ case "$1" in
stop)
shut_it_down
;;
status)
status $DAEMON
exit $?
;;
reload|force-reload)
reload_it
;;
Expand All @@ -108,7 +97,7 @@ case "$1" in
start_it_up
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|restart|reload|force-reload}" >&2
echo "Usage: /etc/init.d/$NAME {start|stop|status|restart|reload|force-reload}" >&2
exit 1
;;
esac
Expand Down
13 changes: 13 additions & 0 deletions meta-venus/recipes-core/dbus/files/dbus-daemon-watch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

watch() {
dbus-daemon "$1" --nofork
logger -t dbus_watch -p user.error "the dbus process unexpectedly stopped ($?), you have 5 minutes to fix it.."
sleep 300
logger -t dbus_watch -p user.info "initiating reboot due to dbus failure."
# In case the OOM killer killed dbus, simply rebooting may no longer
# work. Hence trigger a watchdog reset.
exec killall -STOP watchdog
}

watch "$@" &
72 changes: 72 additions & 0 deletions meta-venus/recipes-core/dbus/files/system.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<!-- This configuration file controls the systemwide message bus.
Add a system-local.conf and edit that rather than changing this
file directly. -->

<!-- Note that there are any number of ways you can hose yourself
security-wise by screwing up this file; in particular, you
probably don't want to listen on any more addresses, add any more
auth mechanisms, run as a different user, etc. -->

<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>

<!-- Our well-known bus type, do not change this -->
<type>system</type>

<!-- Run as special user -->
<user>messagebus</user>

<!-- Fork into daemon mode -->
<fork/>

<!-- We use system service launching using a helper -->
<standard_system_servicedirs/>

<!-- This is a setuid helper that is used to launch system services -->
<servicehelper>/usr/libexec/dbus-daemon-launch-helper</servicehelper>

<!-- Write a pid file (must be the same as init script!) -->
<pidfile>/var/run/messagebus.pid</pidfile>

<!-- Enable logging to syslog -->
<syslog/>

<!-- Only listen on a local socket. (abstract=/path/to/socket
means use abstract namespace, don't really create filesystem
file; only Linux supports this. Use path=/whatever on other
systems.) -->
<listen>unix:path=/var/run/dbus/system_bus_socket</listen>

<policy context="default">
<!-- All users can connect to system bus -->
<allow user="*"/>

<!-- Signals and reply messages (method returns, errors) are allowed
by default -->
<allow send_type="signal"/>
<allow send_requested_reply="true" send_type="method_return"/>
<allow send_requested_reply="true" send_type="error"/>
<allow send_interface="*"/>
<allow receive_interface="*"/>
<allow receive_sender="*"/>

<!-- All messages may be received by default -->
<allow receive_type="method_call"/>
<allow receive_type="method_return"/>
<allow receive_type="error"/>
<allow receive_type="signal"/>

<!-- Allow everything to be sent -->
<allow send_destination="*" eavesdrop="true"/>
<!-- Allow everything to be received -->
<allow eavesdrop="true"/>
<!-- Allow anyone to own anything -->
<allow own="*"/>

<!-- Allow anyone to talk to the message bus -->
<allow send_destination="org.freedesktop.DBus"/>
</policy>

<limit name="max_match_rules_per_connection">1024</limit>
</busconfig>

0 comments on commit 7bfdbb6

Please sign in to comment.