Skip to contentSkip to conversation

Should hcid wait for dbus daemon?

Bluez-devel Daniel Gollub 6 participants 9 messages Jan 8, 2007 – Jan 15, 2007 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

Hi,

the hcid daemon aborts when there is no dbus daemon running. What about enhancing hcid to handle the case that the dbus daemon get started after hcid. I know there are might be not many use cases. But at least i know one case ;)

To avoid that there is another "unneeded" service running, i want to call only the bluetooth init scripts when there is a bluetooth device plugged in. This is done by a simple udev rule, which calls the bluetooth init script when the device got plugged in.

So there is no need to insserv or do any other stuff like running YaST or something like that. Just turn on the bluetooth device or plug it in and the bluetooth service get started by udev.

The only problem is during boot. udev get started before the dbus daemon, and will trigger the udev rule which calls the bluetooth init script. Then hcid will fail because the dbus daemon isn't started in this early stage of boot.

If the hcid would wait for the dbus daemon this wouldn't be a problem. At least hcid can handle a dbus daemon restart, maybe we can enhance this.

I know this can be also done in the bluetooth init script, but maybe someone else insist on this enhancement.

best regards,
Daniel

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#1 lore raw

Hi Daniel,

Quoted 2 lines · Daniel Gollub

If the hcid would wait for the dbus daemon this wouldn't be a problem. At least hcid can handle a dbus daemon restart, maybe we can enhance this.

Sounds like a useful feature. It should be quite simple to implement too since most of the required code already exists due to the dbus restart detection support. Feel free to provide a patch for it :)

Johan

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#2 lore raw

Hello!

NB, I'm not deeply involved in bluetooth neither dbus development, just a "power user". If my thoughts are wrong, just discard them.

Quoted 6 lines · Johan Hedberg
Quoted 3 lines · Daniel Gollub

If the hcid would wait for the dbus daemon this wouldn't be a problem. At least hcid can handle a dbus daemon restart, maybe we can enhance this.

Sounds like a useful feature.

Shouldn't be the contrary? I mean, on a clean Debian etch, every dbus-dependent service is started by dbus:
=====

root@gismo:/home/luca# ls -l /etc/dbus-1/eventd.d/
total 16
-rwxr-xr-x 1 root root 1901 2006-11-11 15:38 20hal
-rwxr-xr-x 1 root root 1091 2006-10-24 15:22 24dhcdbd
lrwxrwxrwx 1 root root   25 2007-01-07 21:53 25avahi-daemon -> \
 ../../init.d/avahi-daemon
-rwxr-xr-x 1 root root 1766 2006-11-30 22:22 25NetworkManager
-rwxr-xr-x 1 root root 1684 2006-11-30 22:22 26NetworkManagerDispatcher
root@gismo:/home/luca# invoke-rc.d dbus start
Starting system message bus: dbus.
Starting Hardware abstraction layer: hald.
Starting DHCP D-Bus daemon: dhcdbd.
Starting network connection manager: NetworkManager.
Starting Avahi mDNS/DNS-SD Daemon: avahi-daemon.
Starting network events dispatcher: NetworkManagerDispatcher.

root@gismo:/home/luca#
=====

Just my 0.02€...

Thx, bye,
Gismo / Luca

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#5 lore raw
In reply to Johan Hedberg
Quoted 3 lines · Johan Hedberg

Sounds like a useful feature. It should be quite simple to implement too since most of the required code already exists due to the dbus restart detection support. Feel free to provide a patch for it :)

How often should the daemons try to connect? Or infinitely? If not infinitely, then configurable by command line parameter or fixed?

Attachted is a _simple_ proof of concept patch which . It retries every 5 seconds. After #12 unsuccessfully dbus connect, it gives up and abort (as before).

Daniel

Index: common/dbus.c
===================================================================
RCS file: /cvsroot/bluez/utils/common/dbus.c,v
retrieving revision 1.2

dbus.c +16 -1
diff -u -p -r1.2 dbus.c
@@ -39,6 +39,7 @@
 #include "list.h"
 
 #define DISPATCH_TIMEOUT	0
+#define MAX_DBUS_RETRY		12
 
 static int name_listener_initialized = 0;
 
@@ -485,13 +486,27 @@ static void dispatch_status_cb(DBusConne
 
 DBusConnection *init_dbus(const char *name, void (*disconnect_cb)(void *), void *user_data)
 {
+	int retry = 0;
 	struct disconnect_data *dc_data;
 	DBusConnection *conn;
 	DBusError err;
 
 	dbus_error_init(&err);
 
-	conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
+	do {
+		if (dbus_error_is_set(&err))
+			dbus_error_free(&err);
+
+		conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
+		if (conn)
+			break;
+
+		if (!retry)
+			info("Can't connect to DBUS. Will retry %i times.", MAX_DBUS_RETRY);
+
+		usleep(5000000);
+		retry++;
+	} while (!conn && retry < MAX_DBUS_RETRY);
 
 	if (dbus_error_is_set(&err)) {
 		error("Can't connect to system message bus: %s", err.message);

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#3 lore raw
In reply to Luca Capello

T24gVHVlc2RheSAwOSBKYW51YXJ5IDIwMDcgMDA6MzEsIEx1Y2EgQ2FwZWxsbyB3cm90ZToKPiBT aG91bGRuJ3QgYmUgdGhlIGNvbnRyYXJ5PyDCoEkgbWVhbiwgb24gYSBjbGVhbiBEZWJpYW4gZXRj aCwgZXZlcnkKPiBkYnVzLWRlcGVuZGVudCBzZXJ2aWNlIGlzIHN0YXJ0ZWQgYnkgZGJ1czoKQnV0 IHRoZW4g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dHMvbGlzdGluZm8vYmx1ZXotZGV2ZWwK

#4 lore raw
In reply to Luca Capello

Hi Luca,

Quoted 2 lines · Luca Capello

NB, I'm not deeply involved in bluetooth neither dbus development, just a "power user". If my thoughts are wrong, just discard them.

They are not wrong, it is just a different use case :-)

Quoted 2 lines

Shouldn't be the contrary? I mean, on a clean Debian etch, every dbus-dependent service is started by dbus:

=

Quoted 10 lines
root@gismo:/home/luca# invoke-rc.d dbus start
Starting system message bus: dbus.
Starting Hardware abstraction layer: hald.
Starting DHCP D-Bus daemon: dhcdbd.
Starting network connection manager: NetworkManager.
Starting Avahi mDNS/DNS-SD Daemon: avahi-daemon.
Starting network events dispatcher: NetworkManagerDispatcher.
=

root@gismo:/home/luca#

This is about the same if i statically enable the bluetooth service on a SUSE machine. But i would like to avoid that (no need to run hcid on a machine that will never see a BT device). At the same time, i like to have it "just work", without the user needing to configure it. So i start the bluetooth services via udev, when a BT device is connected.

This works very well once the machine is up and running. If the device is connected during boot, it is different, because the udev "coldplug" happens before most of the services are started.

I hope this clears up my (and Daniels) intentions :-)

Have fun
-- =

Stefan Seyfried
QA / R&D Team Mobile Devices | "Any ideas, John?"
SUSE LINUX Products GmbH, N=FCrnberg | "Well, surrounding them's out." =

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID=3DDE=
VDEV
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#6 lore raw
In reply to Daniel Gollub

Ping! :-)

Any opinions on that approach? This fixes the hotplug issue for our users, but i want to stay as close to upstream as possible :-)

Quoted 12 lines · Daniel Gollub
Quoted 3 lines · Johan Hedberg

Sounds like a useful feature. It should be quite simple to implement too since most of the required code already exists due to the dbus restart detection support. Feel free to provide a patch for it :)

How often should the daemons try to connect? Or infinitely? If not infinitely, then configurable by command line parameter or fixed? =

Attachted is a _simple_ proof of concept patch which . It retries every 5 =

seconds. After #12 unsuccessfully dbus connect, it gives up and abort (as =

Quoted 7 lines

before).
=

Daniel

Index: common/dbus.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

Quoted 17 lines

RCS file: /cvsroot/bluez/utils/common/dbus.c,v
retrieving revision 1.2
diff -u -p -r1.2 dbus.c

dbus.c +1 -0
@@ -39,6 +39,7 @@
 #include "list.h"
 =
 
 #define DISPATCH_TIMEOUT	0
+#define MAX_DBUS_RETRY		12
 =
 

static int name_listener_initialized =3D 0;
=

dbus.c static void dispatch_status_cb(DBusConne · line 488

Quoted 3 lines
dbus.c +0 -0
@@ -485,13 +486,27 @@ static void dispatch_status_cb(DBusConne
 =
 
 DBusConnection *init_dbus(const char *name, void (*disconnect_cb)(void *=

), void *user_data)

Quoted 13 lines
dbus.c +3 -1
 {
+	int retry =3D 0;
 	struct disconnect_data *dc_data;
 	DBusConnection *conn;
 	DBusError err;
 =
 
 	dbus_error_init(&err);
 =
 
-	conn =3D dbus_bus_get(DBUS_BUS_SYSTEM, &err);
+	do {
+		if (dbus_error_is_set(&err))

dbus.c static void dispatch_status_cb(DBusConne · line 507

Quoted 10 lines
dbus.c +10 -0
+			dbus_error_free(&err);
+
+		conn =3D dbus_bus_get(DBUS_BUS_SYSTEM, &err);
+		if (conn)
+			break;
+
+		if (!retry)
+			info("Can't connect to DBUS. Will retry %i times.", MAX_DBUS_RETRY);
+
+		usleep(5000000);

here, a

		sleep(5);

might be easier to read :-)

dbus.c static void dispatch_status_cb(DBusConne · line 512

Quoted 6 lines
dbus.c +2 -0
+		retry++;
+	} while (!conn && retry < MAX_DBUS_RETRY);

=

dbus.c +0 -0
 	if (dbus_error_is_set(&err)) {
 		error("Can't connect to system message bus: %s", err.message);

-- =

Stefan Seyfried
QA / R&D Team Mobile Devices | "Any ideas, John?"
SUSE LINUX Products GmbH, N=FCrnberg | "Well, surrounding them's out." =

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID=3DDE=
VDEV
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#7 lore raw
In reply to Daniel Gollub

+1, we in ALT Linux use exactly the same scheme for launching hcid and we also want to fix this issue.

Signature · 1 line
WBR, wRAR (ALT Linux Team)

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

maintainer
#8 lore raw
In reply to Daniel Gollub

Hi Daniel,

Quoted 18 lines

the hcid daemon aborts when there is no dbus daemon running. What about enhancing hcid to handle the case that the dbus daemon get started after hcid. I know there are might be not many use cases. But at least i know one case ;)

To avoid that there is another "unneeded" service running, i want to call only the bluetooth init scripts when there is a bluetooth device plugged in. This is done by a simple udev rule, which calls the bluetooth init script when the device got plugged in.

So there is no need to insserv or do any other stuff like running YaST or something like that. Just turn on the bluetooth device or plug it in and the bluetooth service get started by udev.

The only problem is during boot. udev get started before the dbus daemon, and will trigger the udev rule which calls the bluetooth init script. Then hcid will fail because the dbus daemon isn't started in this early stage of boot.

Quoted 5 lines

If the hcid would wait for the dbus daemon this wouldn't be a problem. At least hcid can handle a dbus daemon restart, maybe we can enhance this.

I know this can be also done in the bluetooth init script, but maybe someone else insist on this enhancement.

I don't think that it is a good idea to have udev start daemons. My understanding is that udev is for creating device nodes or init hardware. In case of BlueZ it must start a number of daemons to have a fully working Bluetooth setup. This task is better done by systems like upstart which handle dependencies.

Regards

Marcel

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel