summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2008-05-15 03:26:35 +0000
committerMarcel Holtmann <marcel@holtmann.org>2008-05-15 03:26:35 +0000
commitc478f8907398cf742b00a4e3043f72efbb7d0801 (patch)
tree001e0bfff0ff3527bee00ab6748834908cf16745
parent2a3cf9a57e3e6f4a56d309c794999356ab73439c (diff)
Add IO channel for handling netlink messages
-rw-r--r--plugins/netlink.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/plugins/netlink.c b/plugins/netlink.c
index 51301bfb..887b51ea 100644
--- a/plugins/netlink.c
+++ b/plugins/netlink.c
@@ -34,6 +34,8 @@
#include <bluetooth/bluetooth.h>
+#include <glib.h>
+
#include "plugin.h"
#include "logging.h"
@@ -41,6 +43,35 @@ static struct nl_handle *handle;
static struct nl_cache *cache;
static struct genl_family *family;
+static GIOChannel *channel;
+
+static gboolean channel_callback(GIOChannel *chan,
+ GIOCondition cond, void *user_data)
+{
+ int err;
+
+ if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL))
+ return FALSE;
+
+ debug("Message available on netlink channel");
+
+ err = nl_recvmsgs_default(handle);
+
+ return TRUE;
+}
+
+static int create_channel(int fd)
+{
+ channel = g_io_channel_unix_new(fd);
+ if (channel == NULL)
+ return -ENOMEM;
+
+ g_io_add_watch(channel, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
+ channel_callback, NULL);
+
+ return 0;
+}
+
static int netlink_init(void)
{
info("Starting experimental netlink support");
@@ -72,11 +103,21 @@ static int netlink_init(void)
return -ENOENT;
}
+ if (create_channel(nl_socket_get_fd(handle)) < 0) {
+ error("Failed to create netlink IO channel");
+ genl_family_put(family);
+ nl_cache_free(cache);
+ nl_handle_destroy(handle);
+ return -ENOMEM;
+ }
+
return 0;
}
static void netlink_exit(void)
{
+ g_io_channel_unref(channel);
+
genl_family_put(family);
nl_cache_free(cache);
nl_handle_destroy(handle);