From c6e2f3162231a77e1813ecd26e88b3e8cb1ca9ed Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 12 Jun 2009 17:40:17 +0000 Subject: [PATCH] - Switch to on-demand start/stop using udev --- 97-bluetooth-ondemand.rules | 3 -- bluetooth-check | 30 +++++++++++ bluetooth.conf | 5 +- bluetooth.init | 101 +++--------------------------------- bluez | 10 ++++ bluez.spec | 15 ++++-- 6 files changed, 59 insertions(+), 105 deletions(-) delete mode 100644 97-bluetooth-ondemand.rules create mode 100755 bluetooth-check create mode 100644 bluez diff --git a/97-bluetooth-ondemand.rules b/97-bluetooth-ondemand.rules deleted file mode 100644 index a3a42e8..0000000 --- a/97-bluetooth-ondemand.rules +++ /dev/null @@ -1,3 +0,0 @@ -#bluetooth on demand rules -SUBSYSTEM=="bluetooth", ACTION=="add", RUN+="/sbin/service bluetooth condstart" -SUBSYSTEM=="bluetooth", ACTION=="remove", RUN+="/sbin/service bluetooth condstop" diff --git a/bluetooth-check b/bluetooth-check new file mode 100755 index 0000000..e056632 --- /dev/null +++ b/bluetooth-check @@ -0,0 +1,30 @@ +#!/bin/sh + +# Run "initctl log-priority info" to get debug from +# upstart about events being processed, or pass +# --debug to your kernel arguments + +emit_event() +{ + /sbin/initctl emit --no-wait $1 +} + +# If any of those paths are read-only, bail +if `mount | grep "on / type" | grep -q ro` ; then + return 1; +fi + +# If the action is add, we always have an adapter +if test "x$ACTION" = "xadd" ; then + emit_event fedora.bluetooth-adapter-available + exit 0 +fi + +# Check whether any devices are available +if `udevadm info --export-db | grep -q -e '/devices/.*/bluetooth/.*'` ; then + emit_event fedora.bluetooth-adapter-available +else + emit_event fedora.bluetooth-adapter-not-available +fi + +exit 0 diff --git a/bluetooth.conf b/bluetooth.conf index 65f5892..b29fc98 100644 --- a/bluetooth.conf +++ b/bluetooth.conf @@ -4,7 +4,4 @@ # Enable this to switch capable devices back to HID mode on Bluetooth shutdown #HID2HCI_UNDO=true -# -#Enable this to allow automatic start or stop when bluetooth -#inserted or removed -#BLUETOOTH_ONDEMAND=true + diff --git a/bluetooth.init b/bluetooth.init index 0bf9fd5..fc44e4f 100644 --- a/bluetooth.init +++ b/bluetooth.init @@ -1,14 +1,11 @@ #!/bin/sh # # chkconfig: 345 50 83 -# description: Bluetooth services for service discovery, authentication, \ -# Human Interface Devices, etc. +# description: Turn HID adapters into Bluetooth ones # ### BEGIN INIT INFO -# Required-Start: $syslog messagebus -# Short-Description: Bluetooth services -# Description: Bluetooth services for service discovery, authentication, -# Human Interface Devices, etc. +# Short-Description: Turn HID adapters into Bluetooth ones +# Description: Turn HID adapters into Bluetooth ones ### END INIT INFO # Source function library. @@ -16,54 +13,11 @@ [ -e /etc/sysconfig/bluetooth ] && . /etc/sysconfig/bluetooth -is_enabled_in_runlevel() -{ - level=`runlevel | awk '{print $2;}'` - - #check file in runlevel - [ -f /etc/rc$level.d/S??bluetooth ] - return $? -} - -has_bt_devices() -{ - #Look for Bluetooth adapters: - udevadm info --export-db | grep -q -e '/devices/.*/bluetooth/.*' - - return $? -} - -check_condstart() -{ - is_enabled_in_runlevel || return $? - - /sbin/service bluetooth status && return 1 - - #Look for Bluetooth adapters: - has_bt_devices && return 0 - return 1 -} - -condstart() -{ - if [ "$BLUETOOTH_ONDEMAND" = "true" ]; then - start - return $? - fi - return 1 -} - start() { - if [ "$BLUETOOTH_ONDEMAND" = "true" ]; then - check_condstart || return 1 - fi - - echo -n $"Starting Bluetooth services:" - daemon /usr/sbin/bluetoothd - RETVAL=$? - [ $RETVAL = 0 ] && touch /var/lock/subsys/bluetoothd + echo -n $"Starting hid2hci:" [ "$HID2HCI_ENABLE" = "true" ] && hid2hci --tohci > /dev/null 2>&1 || : + RETVAL=$? touch /var/lock/subsys/bluetooth echo "" return $RETVAL @@ -73,64 +27,23 @@ stop() { echo -n "Stopping Bluetooth services:" [ "$HID2HCI_UNDO" = "true" ] && hid2hci --tohid > /dev/null 2>&1 || : - killproc bluetoothd RETVAL=$? - rm -f /var/lock/subsys/bluetooth - rm -f /var/lock/subsys/bluetoothd echo "" return $RETVAL } -check_condstop() -{ - is_enabled_in_runlevel || return $? - - /sbin/service bluetooth status || return $? - - #Look for Bluetooth adapters: - has_bt_devices && return 1 - return 0 -} - -condstop() -{ - if [ "$BLUETOOTH_ONDEMAND" = "true" ]; then - check_condstop || return 1 - else - return 2 - fi - - stop - return $? -} - - case "$1" in start) start ;; - condstart) - condstart - ;; stop) stop ;; - condstop) - condstop - ;; - force-reload|restart|reload) - stop - start - ;; - try-restart|condrestart) - [ -e /var/lock/subsys/bluetooth ] && (stop; start) - ;; status) - status bluetoothd - RETVAL=$? + RETVAL=0 ;; *) - echo $"Usage: $0 {start|stop|status|restart|reload|condrestart|condstart|condstop}" + echo $"Usage: $0 {start|stop|status}" exit 3 ;; esac diff --git a/bluez b/bluez new file mode 100644 index 0000000..eecaf3d --- /dev/null +++ b/bluez @@ -0,0 +1,10 @@ +# Automatically start bluetoothd when an adapter is plugged in +# + +start on fedora.bluetooth-adapter-available + +stop on runlevel [016] +stop on fedora.bluetooth-adapter-not-available + +exec /usr/sbin/bluetoothd --nodaemon + diff --git a/bluez.spec b/bluez.spec index afb54bd..da62526 100644 --- a/bluez.spec +++ b/bluez.spec @@ -1,7 +1,7 @@ Summary: Bluetooth utilities Name: bluez Version: 4.41 -Release: 1%{?dist} +Release: 2%{?dist} License: GPLv2+ Group: Applications/System Source: http://www.kernel.org/pub/linux/bluetooth/%{name}-%{version}.tar.gz @@ -13,7 +13,8 @@ Source5: pand.init Source6: pand.conf Source7: rfcomm.init Source8: bluez-uinput.modules -Source9: 97-bluetooth-ondemand.rules +Source9: 96-bluez.rules + Patch1: bluez-utils-oui-usage.patch # https://bugzilla.redhat.com/show_bug.cgi?id=450081 # http://thread.gmane.org/gmane.linux.bluez.kernel/1687 @@ -24,6 +25,8 @@ Patch3: bluez-activate-wacom-mode2.patch Patch4: bluez-socket-mobile-cf-connection-kit.patch # http://thread.gmane.org/gmane.linux.bluez.kernel/2396 Patch5: 0001-Add-sixaxis-cable-pairing-plugin.patch +# http://thread.gmane.org/gmane.linux.bluez.kernel/2474 +Patch6: 0001-Add-udev-mode-to-bluetoothd.patch BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root URL: http://www.bluez.org/ @@ -129,6 +132,7 @@ This includes hidd, dund and pand. %patch3 -p1 -b .wacom %patch4 -p1 -b .socket-mobile %patch5 -p1 -b .cable-pairing +%patch6 -p1 -b .udev %build libtoolize -f -c @@ -161,8 +165,8 @@ fi rm -f ${RPM_BUILD_ROOT}/%{_sysconfdir}/udev/*.rules install -D -m0644 scripts/bluetooth-serial.rules ${RPM_BUILD_ROOT}/%{_sysconfdir}/udev/rules.d/97-bluetooth-serial.rules -install -D -m0644 %{SOURCE9} ${RPM_BUILD_ROOT}/%{_sysconfdir}/udev/rules.d/97-bluetooth-ondemand.rules install -D -m0755 scripts/bluetooth_serial ${RPM_BUILD_ROOT}/lib/udev/bluetooth_serial +install -D -m0644 %{SOURCE9} ${RPM_BUILD_ROOT}/lib/udev/rules.d/96-bluez.rules install -D -m0755 %{SOURCE8} $RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig/modules/bluez-uinput.modules @@ -227,8 +231,8 @@ fi %config %{_sysconfdir}/dbus-1/system.d/bluetooth.conf %{_libdir}/bluetooth/ /lib/udev/bluetooth_serial +/lib/udev/rules.d/96-bluez.rules %{_sysconfdir}/udev/rules.d/97-bluetooth-serial.rules -%{_sysconfdir}/udev/rules.d/97-bluetooth-ondemand.rules %{_sysconfdir}/rc.d/init.d/bluetooth %{_localstatedir}/lib/bluetooth @@ -269,6 +273,9 @@ fi %config(noreplace) %{_sysconfdir}/sysconfig/pand %changelog +* Thu Jun 11 2009 Bastien Nocera 4.41-2 +- Switch to on-demand start/stop using udev + * Mon Jun 08 2009 Bastien Nocera 4.41-1 - Update to 4.41