From: Petr Lautrbach <plautrba@redhat.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH] Add on demand functionality to bluetooth init script
Date: Thu, 04 Jun 2009 16:52:46 +0200 [thread overview]
Message-ID: <4A27DFBE.407@redhat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 326 bytes --]
Hi.
This patch adds on demand functionality for bluetooth service based on udev events.
It's adapted from Fedora [1].
Idea is that bluetoothd doesn't need to be running unless the user actually has a bluetooth device.
[1] https://bugzilla.redhat.com/show_bug.cgi?id=484345
Cheers,
Petr
--
Petr Lautrbach, Red Hat, Inc.
[-- Attachment #2: bluetooth-ondemand-service-based-on-udev.patch --]
[-- Type: text/plain, Size: 4030 bytes --]
From 96c257e72a6a2ab5ef1325f98498817e0709600e Mon Sep 17 00:00:00 2001
From: Petr Lautrbach <plautrba@redhat.com>
Date: Thu, 4 Jun 2009 15:09:52 +0200
Subject: [PATCH] bluetooth ondemand service based on udev
---
acinclude.m4 | 6 ++++++
scripts/Makefile.am | 10 +++++++++-
scripts/bluetooth-ondemand.rules | 3 +++
scripts/bluetooth.init | 24 ++++++++++++++++++++++--
4 files changed, 40 insertions(+), 3 deletions(-)
create mode 100644 scripts/bluetooth-ondemand.rules
diff --git a/acinclude.m4 b/acinclude.m4
index eb7cdeb..4082110 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -199,6 +199,7 @@ AC_DEFUN([AC_ARG_BLUEZ], [
configfiles_enable=yes
initscripts_enable=no
pcmciarules_enable=no
+ ondemand_enable=no
telephony_driver=dummy
AC_ARG_ENABLE(fortify, AC_HELP_STRING([--disable-fortify], [disable compile time buffer checks]), [
@@ -297,6 +298,10 @@ AC_DEFUN([AC_ARG_BLUEZ], [
pcmciarules_enable=${enableval}
])
+ AC_ARG_ENABLE(ondemand, AC_HELP_STRING([--enable-ondemand], [install ONDEMAND udev rules]), [
+ ondemand_enable=${enableval}
+ ])
+
AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug], [enable compiling with debugging information]), [
debug_enable=${enableval}
])
@@ -357,4 +362,5 @@ AC_DEFUN([AC_ARG_BLUEZ], [
AM_CONDITIONAL(CONFIGFILES, test "${configfiles_enable}" = "yes")
AM_CONDITIONAL(INITSCRIPTS, test "${initscripts_enable}" = "yes")
AM_CONDITIONAL(PCMCIARULES, test "${pcmciarules_enable}" = "yes")
+ AM_CONDITIONAL(ONDEMAND, test "${ondemand_enable}" = "yes")
])
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 494a9c2..4914612 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -11,6 +11,10 @@ endif
if PCMCIARULES
rules_DATA += bluetooth-serial.rules
endif
+
+if ONDEMAND
+rules_DATA += bluetooth-ondemand.rules
+endif
endif
if PCMCIARULES
@@ -20,7 +24,8 @@ udev_SCRIPTS = bluetooth_serial
endif
EXTRA_DIST = bluetooth.init bluetooth.default bluetooth-hid2hci.rules \
- bluetooth-serial.rules bluetooth_serial
+ bluetooth-serial.rules bluetooth_serial \
+ bluetooth-ondemand.rules
MAINTAINERCLEANFILES = Makefile.in
@@ -30,6 +35,9 @@ install-data-local:
$(mkinstalldirs) $(DESTDIR)$(sysconfdir)/default
[ -f $(DESTDIR)$(sysconfdir)/default/bluetooth ] || \
$(INSTALL_DATA) $(srcdir)/bluetooth.default $(DESTDIR)$(sysconfdir)/default/bluetooth
+if ONDEMAND
+ echo "DAEMON_ONDEMAND=true" >> $(DESTDIR)$(sysconfdir)/default/bluetooth
+endif
uninstall-local:
@rm -f $(DESTDIR)$(sysconfdir)/init.d/bluetooth
diff --git a/scripts/bluetooth-ondemand.rules b/scripts/bluetooth-ondemand.rules
new file mode 100644
index 0000000..6146935
--- /dev/null
+++ b/scripts/bluetooth-ondemand.rules
@@ -0,0 +1,3 @@
+#bluetooth on demand rules
+SUBSYSTEM=="bluetooth", ACTION=="add", RUN+="/etc/init.d/bluetooth condstart"
+SUBSYSTEM=="bluetooth", ACTION=="remove", RUN+="/etc/init.d/bluetooth condstop"
diff --git a/scripts/bluetooth.init b/scripts/bluetooth.init
index 3ea8a89..b9a1454 100644
--- a/scripts/bluetooth.init
+++ b/scripts/bluetooth.init
@@ -17,21 +17,41 @@ DAEMON_ENABLE=true
[ -e /etc/default/bluetooth ] && . /etc/default/bluetooth
+has_bt_devices()
+{
+ #Look for Bluetooth adapters:
+ udevadm info --export-db | grep -q -e '/devices/.*/bluetooth/.*'
+
+ return $?
+}
+
case "$1" in
start)
echo -n "Starting $DESC:"
if $DAEMON_ENABLE && [ -x "$DAEMON_EXEC" ]; then
- $DAEMON_EXEC
- echo -n " $DAEMON_NAME"
+ if [ -z $DAEMON_ONDEMAND ] || has_bt_devices; then
+ $DAEMON_EXEC
+ echo -n " $DAEMON_NAME"
+ fi
fi
echo "."
;;
+ condstart)
+ if [ -n $DAEMON_ONDEMAND ]; then
+ /etc/init.d/$NAME start
+ fi
+ ;;
stop)
echo -n "Stopping $DESC:"
killall $DAEMON_NAME > /dev/null 2>&1 || true
echo -n " $DAEMON_NAME"
echo "."
;;
+ condstop)
+ if [ -n $DAEMON_ONDEMAND ]; then
+ has_bt_devices || /etc/init.d/$NAME stop
+ fi
+ ;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop}" >&2
--
1.6.0.6
next reply other threads:[~2009-06-04 14:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-04 14:52 Petr Lautrbach [this message]
2009-06-05 14:51 ` [PATCH] Add on demand functionality to bluetooth init script Stefan Seyfried
2009-06-08 11:31 ` Petr Lautrbach
2009-06-08 11:59 ` Stefan Seyfried
2009-06-08 12:17 ` Petr Lautrbach
2009-06-05 15:38 ` Johan Hedberg
2009-06-05 15:48 ` Marcel Holtmann
2009-06-05 16:42 ` Stefan Seyfried
2009-06-05 16:53 ` Stefan Seyfried
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4A27DFBE.407@redhat.com \
--to=plautrba@redhat.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox