site  contact  subhomenews

dbus dependency to start bluetooth

February 12, 2020 — BarryK

Easy 2.2.9 and has faster startup, due to parallel processing of kernel uevents by udevd, see here:

Unfortunately, those above versions of Easy have not managed to start the bluetooth daemon before the udev daemon has started. So bluetooth does not work, not always anyway.

The dependency needed to be solved properly. Easy has pup_event service management to do this. You can find documentation in /usr/local/pup_event.

I inserted "dbus" as a dependency in /etc/eventmanager:

PE_SERVICE_MANAGER='network%cups-net-fixONESHOT:qsyncONESHOT:dnsmasq:ec-net bluetoothhw:dbus%bluetooth:bluealsa', /etc/init.d/bluetooth and /etc/init.d/bluealsa will launch after both dependencies 'bluetoothhw' and 'dbus' are met. The former is met if there is bluetooth hardware, either at bootup or later in the case of a bluetooth dongle getting plugged in. The latter, 'dbus', is met when the 'dbusd' daemon is running.

/etc/rc.d/rc.services_ipc has this code:

 for aDEP in $DEPs
[ ! "$aDEP" ] && continue #200213 precaution.
#200213 detect if dep already avail...
[ -s /tmp/pup_event_backend/${aDEP}_ ] && MSG1="$(cat /tmp/pup_event_backend/${aDEP}_)"

[ ! "$MSG1" ] && MSG1="$(/usr/local/pup_event/pup_event_ipc "${aDEP}:${$}")" #***WAIT FOR FILE CHG***
#...ex: network:12345 MSG1=eth0 or MSG1='' (empty, meaning i/f gone down)
[ ! "$MSG1" ] && continue 2
if [ "$aDEP" == "x" ];then #180301
DISPLAY=":$(grep -o '[01]' /tmp/pup_event_backend/x_)"
export DISPLAY #ex: :0
done this case, $DEPs is "bluetoothhw dbus". 'pup_event_ipc' will wait until files /tmp/pup_event_ipc/bluetoothhw_<pid> and /tmp/pup_event_ipc/dbus_<pid> are written to, and if both non-empty content, the dependencies will be met.

EDIT 2020-02-13:
The green code above is a bug fix, slightly different from the original blog post.

I posted earlier how bluetooth hardware is detected, and /tmp/pup_event_ipc/bluetoothhw_<pid> gets written to.

For dbus, it is a simple matter of writing to /tmp/pup_event_ipc/dbus_<pid> after /etc/init.d/messagebus has run. This is handled in /etc/rc.d/

  #200212 see /etc/eventmanager
if [ "${baseSC}" == "messagebus" ];then
echo -n "started" > /tmp/pup_event_backend/dbus_ #permanent flag (see rc.services_ipc).
for aSC in /tmp/pup_event_ipc/dbus_* #rc.services_ipc should have already created this.
[ "$aSC" == "" ] && continue
[ ! -f $aSC ] && continue #200212b if no match for glob, ash uses literal filename.
echo -n "started" > ${aSC}
...which causes 'pup_event_ipc' in to exit, assigning "started" to MSG1. 

It is quite simple, when you get the hang of it. This is "proper" dependency management for bluetooth, and I have built Easy 2.2.10 and confirmed it works. 

Tags: easy