summaryrefslogtreecommitdiffstats
path: root/hcid/security.c
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2006-08-26 16:55:47 +0000
committerJohan Hedberg <johan.hedberg@nokia.com>2006-08-26 16:55:47 +0000
commitea7b976177bffc7f3c89e380a1273e1d85b2a24f (patch)
tree146321302301da35c12ae5ac10fd6f6700c13945 /hcid/security.c
parent448146fdeb6a90cdf11826fcdc88ce9068eb9646 (diff)
Cleanup/fix glib-ectomy.c and its usage
Diffstat (limited to 'hcid/security.c')
-rw-r--r--hcid/security.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/hcid/security.c b/hcid/security.c
index b5eca651..ebdc130c 100644
--- a/hcid/security.c
+++ b/hcid/security.c
@@ -657,23 +657,21 @@ static inline void conn_request(int dev, bdaddr_t *sba, void *ptr)
static gboolean io_security_event(GIOChannel *chan, GIOCondition cond, gpointer data)
{
unsigned char buf[HCI_MAX_EVENT_SIZE], *ptr = buf;
- struct hci_dev_info *di = (void *) data;
+ struct hci_dev_info *di = data;
int type, dev;
size_t len;
hci_event_hdr *eh;
GIOError err;
if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
- g_io_channel_close(chan);
- free(data);
+ g_io_channel_unref(chan);
return FALSE;
}
if ((err = g_io_channel_read(chan, (gchar *) buf, sizeof(buf), &len))) {
if (err == G_IO_ERROR_AGAIN)
return TRUE;
- g_io_channel_close(chan);
- free(data);
+ g_io_channel_unref(chan);
return FALSE;
}
@@ -836,9 +834,10 @@ void start_security_manager(int hdev)
}
chan = g_io_channel_unix_new(dev);
- io_data[hdev].watch_id = g_io_add_watch(chan, G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
- io_security_event, (void *) di);
-
+ g_io_channel_set_close_on_unref(chan, TRUE);
+ io_data[hdev].watch_id = g_io_add_watch_full(chan, 0,
+ G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
+ io_security_event, di, (GDestroyNotify)free);
io_data[hdev].channel = chan;
io_data[hdev].pin_length = -1;
@@ -861,11 +860,8 @@ void stop_security_manager(int hdev)
info("Stopping security manager %d", hdev);
- /* this is a bit sneaky. closing the fd will cause the event
- loop to call us right back with G_IO_NVAL set, at which
- point we will see it and clean things up */
- close(g_io_channel_unix_get_fd(chan));
g_io_remove_watch(io_data[hdev].watch_id);
+ g_io_channel_unref(io_data[hdev].channel);
io_data[hdev].watch_id = -1;
io_data[hdev].channel = NULL;
io_data[hdev].pin_length = -1;