summaryrefslogtreecommitdiffstats
path: root/hcid/dbus-service.c
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2007-01-15 19:49:02 +0000
committerJohan Hedberg <johan.hedberg@nokia.com>2007-01-15 19:49:02 +0000
commit6040c15370d703cdadf7fa6c98caced1b9e32e30 (patch)
tree405407624934a51651322588235b528fc1a414e3 /hcid/dbus-service.c
parent467f83c3ac4e4afba959e8cfd8aadb0f1614c9fb (diff)
Add startup timeout for spawned services
Diffstat (limited to 'hcid/dbus-service.c')
-rw-r--r--hcid/dbus-service.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/hcid/dbus-service.c b/hcid/dbus-service.c
index e9d851b4..727ae5b3 100644
--- a/hcid/dbus-service.c
+++ b/hcid/dbus-service.c
@@ -45,6 +45,8 @@
#define SERVICE_INTERFACE "org.bluez.Service"
+#define STARTUP_TIMEOUT (10 * 1000) /* 10 seconds */
+
#define SERVICE_SUFFIX ".service"
#define SERVICE_GROUP "Bluetooth Service"
@@ -324,6 +326,11 @@ static void service_died(GPid pid, gint status, gpointer data)
debug("%s (%s) exited with status %d", service->exec, service->name,
status);
+ if (service->startup_timer) {
+ g_timeout_remove(service->startup_timer);
+ service->startup_timer = 0;
+ }
+
g_spawn_close_pid(pid);
service->pid = 0;
@@ -372,9 +379,26 @@ static DBusHandlerResult service_filter(DBusConnection *conn,
if (signal)
send_message_and_unref(conn, signal);
+ g_timeout_remove(service->startup_timer);
+ service->startup_timer = 0;
+
+ name_listener_add(conn, new, service_exit, conn);
+
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
+static gboolean service_startup_timeout(gpointer data)
+{
+ struct service *service = data;
+
+ debug("Killing %s because it did not connect to D-Bus in time",
+ service->exec);
+
+ kill(service->pid, SIGTERM);
+
+ return FALSE;
+}
+
static DBusHandlerResult start(DBusConnection *conn,
DBusMessage *msg, void *data)
{
@@ -416,6 +440,10 @@ static DBusHandlerResult start(DBusConnection *conn,
dbus_bus_add_match(conn, NAME_MATCH, NULL);
+ service->startup_timer = g_timeout_add(STARTUP_TIMEOUT,
+ service_startup_timeout,
+ service);
+
reply = dbus_message_new_method_return(msg);
if (reply)
send_message_and_unref(conn, reply);