summaryrefslogtreecommitdiffstats
path: root/daemon
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2007-01-20 21:34:32 +0000
committerMarcel Holtmann <marcel@holtmann.org>2007-01-20 21:34:32 +0000
commitee0d353d9dc1b7ea330312bd644c5d3012e211d0 (patch)
tree90da3a26278463bdcaa0a98994f87d97aa28b038 /daemon
parent79169bd1c7f9b311a20fe25324c974633c7d7876 (diff)
Don't call unref in IO handling function
Diffstat (limited to 'daemon')
-rw-r--r--daemon/echo.c4
-rw-r--r--daemon/service.c31
2 files changed, 32 insertions, 3 deletions
diff --git a/daemon/echo.c b/daemon/echo.c
index 34b38737..91fd4ab3 100644
--- a/daemon/echo.c
+++ b/daemon/echo.c
@@ -51,10 +51,8 @@ static gboolean session_event(GIOChannel *chan, GIOCondition cond, gpointer data
gsize len, written;
GIOError err;
- if (cond & (G_IO_HUP | G_IO_ERR)) {
- g_io_channel_unref(chan);
+ if (cond & (G_IO_HUP | G_IO_ERR))
return FALSE;
- }
err = g_io_channel_read(chan, (gchar *) buf, sizeof(buf), &len);
if (err == G_IO_ERROR_AGAIN)
diff --git a/daemon/service.c b/daemon/service.c
index 830ca7dc..3d523a34 100644
--- a/daemon/service.c
+++ b/daemon/service.c
@@ -27,6 +27,9 @@
#include <stdlib.h>
#include <string.h>
+#include <signal.h>
+
+#include <glib.h>
#include <dbus/dbus.h>
@@ -42,6 +45,8 @@
static DBusConnection *connection = NULL;
static char *test_conn_name = NULL;
+static GPid test_service_pid = 0;
+static guint test_watch_id = -1;
DBusHandlerResult manager_list_services(DBusConnection *conn,
DBusMessage *msg, void *data)
@@ -139,10 +144,21 @@ static DBusHandlerResult service_get_description(DBusConnection *conn,
return dbus_connection_send_and_unref(conn, reply);
}
+static void service_died(GPid pid, gint status, gpointer data)
+{
+ debug("Child with PID %d died with status %d", pid, status);
+
+ g_spawn_close_pid(pid);
+ test_service_pid = 0;
+}
+
static DBusHandlerResult service_start(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessage *reply;
+ GPid pid;
+ char **argv;
+ int argc;
debug("Starting service");
@@ -161,6 +177,18 @@ static DBusHandlerResult service_start(DBusConnection *conn,
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
dbus_message_append_args(reply, DBUS_TYPE_INVALID);
+
+ g_shell_parse_argv("/data/bluez/utils/daemon/bluetoothd_echo", &argc, &argv, NULL);
+
+ g_spawn_async(NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, NULL);
+
+ g_strfreev(argv);
+
+ test_watch_id = g_child_watch_add(pid, service_died, NULL);
+
+ debug("New process with PID %d executed", pid);
+
+ test_service_pid = pid;
}
return dbus_connection_send_and_unref(conn, reply);
@@ -181,6 +209,9 @@ static DBusHandlerResult service_stop(DBusConnection *conn,
free(test_conn_name);
test_conn_name = NULL;
+ kill(test_service_pid, SIGTERM);
+ test_service_pid = 0;
+
dbus_message_append_args(reply, DBUS_TYPE_INVALID);
} else {
reply = dbus_message_new_error(msg, ERROR_INTERFACE ".NotRunning",