public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Stefan Seyfried <seife@suse.de>
To: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH] Add udev mode to bluetoothd
Date: Fri, 12 Jun 2009 10:28:19 +0200	[thread overview]
Message-ID: <4A3211A3.2040203@suse.de> (raw)
In-Reply-To: <4A320683.7000103@suse.de>

[-- Attachment #1: Type: text/plain, Size: 609 bytes --]

Stefan Seyfried wrote:

> I had patches for waiting for the bus long time ago and can dig them out if
> wanted.

Actually I quickly dug them out and adapted them to the current code.

I arbitrarily chose to stop waiting after 5 minutes. This timeout is certainly
 a topic that might need to be discussed.

Best regards,

	Stefan
-- 
Stefan Seyfried
R&D Team Mobile Devices            |              "Any ideas, John?"
SUSE LINUX Products GmbH, Nürnberg | "Well, surrounding them's out."

This footer brought to you by insane German lawmakers:
SUSE Linux Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg)

[-- Attachment #2: 0001-Wait-for-system-bus-to-appear.patch --]
[-- Type: text/x-patch, Size: 1462 bytes --]

>From 8b41af8ac12e2cf0824af4f65e0ef47ffac3dcb8 Mon Sep 17 00:00:00 2001
From: Stefan Seyfried <seife@tuxbox-git.slipkontur.de>
Date: Fri, 12 Jun 2009 10:22:29 +0200
Subject: [PATCH] Wait for system bus to appear

If the system bus is not there when starting bluetoothd,
wait up to five minutes for it to appear and retry the
connection every five seconds.
---
 src/dbus-common.c |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/dbus-common.c b/src/dbus-common.c
index d06d8e5..dc648be 100644
--- a/src/dbus-common.c
+++ b/src/dbus-common.c
@@ -162,21 +162,32 @@ void hcid_dbus_exit(void)
 	dbus_connection_unref(conn);
 }
 
+#define MAX_DBUS_RETRY		60
 int hcid_dbus_init(void)
 {
 	DBusConnection *conn;
 	DBusError err;
+	int retry = 0;
 
-	dbus_error_init(&err);
+	do {
+		dbus_error_init(&err);
+		conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, BLUEZ_NAME, &err);
+		if (conn)
+			break;
 
-	conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, BLUEZ_NAME, &err);
-	if (!conn) {
 		if (error != NULL && dbus_error_is_set(&err)) {
 			dbus_error_free(&err);
-			return -EIO;
+			if (retry >= MAX_DBUS_RETRY)
+				return -EIO;
+			if (!retry)
+				info("Can't connect to system bus, will retry "
+					"%i times.", MAX_DBUS_RETRY);
+			sleep(5);
+			retry++;
+			continue;
 		}
 		return -EALREADY;
-	}
+	} while (1);
 
 	if (g_dbus_set_disconnect_function(conn, disconnect_callback,
 							NULL, NULL) == FALSE) {
-- 
1.6.3.2


  reply	other threads:[~2009-06-12  8:28 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-11 17:38 [PATCH] Add udev mode to bluetoothd Bastien Nocera
2009-06-11 17:50 ` Marcel Holtmann
2009-06-12  7:40   ` Stefan Seyfried
2009-06-12  8:28     ` Stefan Seyfried [this message]
2009-06-12 17:43       ` Bastien Nocera
2009-06-12  8:40     ` Bastien Nocera
2009-06-12 15:28       ` Marcel Holtmann
2009-06-12 17:58         ` Bastien Nocera
2009-06-13 19:51           ` Marcel Holtmann

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=4A3211A3.2040203@suse.de \
    --to=seife@suse.de \
    --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