diff options
author | Johan Hedberg <johan.hedberg@nokia.com> | 2007-01-19 17:02:28 +0000 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@nokia.com> | 2007-01-19 17:02:28 +0000 |
commit | 47ff7500e63b5a94266e6a23b8c015822cec3d19 (patch) | |
tree | 7d6fad021e5ae67e4083f6420026363e4a8aa230 /hcid/dbus-service.c | |
parent | 06e0a7f62e2f594784c01ce232e040dae333dc18 (diff) |
Add signal filter and match before spawning service processes
Diffstat (limited to 'hcid/dbus-service.c')
-rw-r--r-- | hcid/dbus-service.c | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/hcid/dbus-service.c b/hcid/dbus-service.c index 8115a693..2bfaa588 100644 --- a/hcid/dbus-service.c +++ b/hcid/dbus-service.c @@ -494,9 +494,27 @@ static int start_service(struct service *service, DBusConnection *conn) return -1; } + if (!dbus_connection_add_filter(conn, service_filter, service, NULL)) { + error("Unable to add signal filter"); + g_strfreev(argv); + return -1; + } + + dbus_error_init(&derr); + dbus_bus_add_match(conn, NAME_MATCH, &derr); + if (dbus_error_is_set(&derr)) { + error("Add match \"%s\" failed: %s", derr.message); + dbus_error_free(&derr); + dbus_connection_remove_filter(conn, service_filter, service); + g_strfreev(argv); + return -1; + } + if (!g_spawn_async(NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, service_setup, service, &service->pid, NULL)) { error("Unable to execute %s", service->exec); + dbus_connection_remove_filter(conn, service_filter, service); + dbus_bus_remove_match(conn, NAME_MATCH, NULL); g_strfreev(argv); return -1; } @@ -508,22 +526,6 @@ static int start_service(struct service *service, DBusConnection *conn) debug("%s executed with PID %d", service->exec, service->pid); - if (!dbus_connection_add_filter(conn, service_filter, service, NULL)) { - error("Unable to add signal filter"); - if (kill(service->pid, SIGKILL) < 0) - error("kill(%d, SIGKILL): %s (%d)", service->pid, - strerror(errno), errno); - return -1; - } - - dbus_error_init(&derr); - dbus_bus_add_match(conn, NAME_MATCH, &derr); - if (dbus_error_is_set(&derr)) { - error("Add match \"%s\" failed: %s", derr.message); - dbus_error_free(&derr); - return -1; - } - service->startup_timer = g_timeout_add(STARTUP_TIMEOUT, service_startup_timeout, service); |