Diff between 3ccda2440d80e664499097a638388869c6f70da6 and d0903aa40797642b10b6ce67f783c9d707b9a7aa

Changed Files

File Additions Deletions Status
tools/obex-server-tool.c +14 -12 modified

Full Patch

diff --git a/tools/obex-server-tool.c b/tools/obex-server-tool.c
index b47238e..9be797c 100644
--- a/tools/obex-server-tool.c
+++ b/tools/obex-server-tool.c
@@ -110,13 +110,14 @@ static gboolean unix_accept(GIOChannel *chan, GIOCondition cond, gpointer data)
 	return TRUE;
 }
 
-static GIOChannel *unix_listen(void)
+static guint unix_listen(void)
 {
 	GIOChannel *io;
 	struct sockaddr_un addr = {
 		AF_UNIX, "\0/gobex/server"
 	};
 	int sk, err, sock_type;
+	guint id;
 
 	if (option_packet)
 		sock_type = SOCK_SEQPACKET;
@@ -128,33 +129,34 @@ static GIOChannel *unix_listen(void)
 		err = errno;
 		g_printerr("Can't create unix socket: %s (%d)\n",
 						strerror(err), err);
-		return NULL;
+		return 0;
 	}
 
 	if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
 		g_printerr("Can't bind unix socket: %s (%d)\n",
 						strerror(errno), errno);
 		close(sk);
-		return NULL;
+		return 0;
 	}
 
 	if (listen(sk, 1) < 0) {
 		g_printerr("Can't listen on unix socket: %s (%d)\n",
 						strerror(errno), errno);
 		close(sk);
-		return NULL;
+		return 0;
 	}
 
+	g_print("Unix socket created: %d\n", sk);
+
 	io = g_io_channel_unix_new(sk);
-	g_io_add_watch(io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+	id = g_io_add_watch(io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
 							unix_accept, NULL);
 
 	g_io_channel_set_flags(io, G_IO_FLAG_NONBLOCK, NULL);
 	g_io_channel_set_close_on_unref(io, TRUE);
+	g_io_channel_unref(io);
 
-	g_print("Unix socket created: %d\n", sk);
-
-	return io;
+	return id;
 }
 
 int main(int argc, char *argv[])
@@ -162,7 +164,7 @@ int main(int argc, char *argv[])
 	GOptionContext *context;
 	GError *err = NULL;
 	struct sigaction sa;
-	GIOChannel *io;
+	guint server_id;
 
 	context = g_option_context_new(NULL);
 	g_option_context_add_main_entries(context, options, NULL);
@@ -174,8 +176,8 @@ int main(int argc, char *argv[])
 		exit(EXIT_FAILURE);
 	}
 
-	io = unix_listen();
-	if (io == NULL)
+	server_id = unix_listen();
+	if (server_id == 0)
 		exit(EXIT_FAILURE);
 
 	memset(&sa, 0, sizeof(sa));
@@ -187,7 +189,7 @@ int main(int argc, char *argv[])
 
 	g_main_loop_run(main_loop);
 
-	g_io_channel_unref(io);
+	g_source_remove(server_id);
 	g_slist_free_full(clients, (GDestroyNotify) g_obex_unref);
 	g_option_context_free(context);
 	g_main_loop_unref(main_loop);