- Switch to on-demand start/stop using udev

This commit is contained in:
Bastien Nocera 2009-06-12 17:40:17 +00:00
parent 28d541380f
commit c6e2f31622
6 changed files with 59 additions and 105 deletions

View File

@ -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"

30
bluetooth-check Executable file
View File

@ -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

View File

@ -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

View File

@ -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

10
bluez Normal file
View File

@ -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

View File

@ -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 <bnocera@redhat.com> 4.41-2
- Switch to on-demand start/stop using udev
* Mon Jun 08 2009 Bastien Nocera <bnocera@redhat.com> 4.41-1
- Update to 4.41