Re: [PATCH 2/9] rfkill: Cleanup IO watch on exit

2015-01-13 Thread Patrik Flykt

Hi,

On Thu, 2015-01-08 at 11:26 -0500, Hannu Mallat wrote:
 Besides the IO channel for rfkill events, the associated watch also
 needs to be cleaned up on exit.
 ---
  src/rfkill.c | 11 +--
  1 file changed, 9 insertions(+), 2 deletions(-)
 
 diff --git a/src/rfkill.c b/src/rfkill.c
 index 960cfea..b248c26 100644
 --- a/src/rfkill.c
 +++ b/src/rfkill.c
 @@ -154,6 +154,7 @@ static gboolean rfkill_event(GIOChannel *chan, 
 GIOCondition cond, gpointer data)
  }
  
  static GIOChannel *channel = NULL;
 +static guint watch = 0;
  
  int __connman_rfkill_block(enum connman_service_type type, bool block)
  {
 @@ -215,8 +216,9 @@ int __connman_rfkill_init(void)
   /* Process current RFKILL events sent on device open */
   while (rfkill_process(channel) == G_IO_STATUS_NORMAL);
  
 - g_io_add_watch(channel, G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
 - rfkill_event, NULL);
 + watch = g_io_add_watch(channel,
 + G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
 + rfkill_event, NULL);
  
   return 0;
  }
 @@ -228,6 +230,11 @@ void __connman_rfkill_cleanup(void)
   if (!channel)
   return;
  
 + if (watch) {
 + g_source_remove(watch);
 + watch = 0;
 + }
 +
   g_io_channel_shutdown(channel, TRUE, NULL);
   g_io_channel_unref(channel);
  


If the IOChannel variable is not strictly needed, one can always unref
it after adding the IO watcher and keep only the watch variable around;
the IO watch is the one keeping the only reference count on the
IOChannel. Less variables to look after.

Cheers,

Patrik


___
connman mailing list
connman@connman.net
https://lists.connman.net/mailman/listinfo/connman


[PATCH 2/9] rfkill: Cleanup IO watch on exit

2015-01-08 Thread Hannu Mallat
Besides the IO channel for rfkill events, the associated watch also
needs to be cleaned up on exit.
---
 src/rfkill.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/rfkill.c b/src/rfkill.c
index 960cfea..b248c26 100644
--- a/src/rfkill.c
+++ b/src/rfkill.c
@@ -154,6 +154,7 @@ static gboolean rfkill_event(GIOChannel *chan, GIOCondition 
cond, gpointer data)
 }
 
 static GIOChannel *channel = NULL;
+static guint watch = 0;
 
 int __connman_rfkill_block(enum connman_service_type type, bool block)
 {
@@ -215,8 +216,9 @@ int __connman_rfkill_init(void)
/* Process current RFKILL events sent on device open */
while (rfkill_process(channel) == G_IO_STATUS_NORMAL);
 
-   g_io_add_watch(channel, G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
-   rfkill_event, NULL);
+   watch = g_io_add_watch(channel,
+   G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
+   rfkill_event, NULL);
 
return 0;
 }
@@ -228,6 +230,11 @@ void __connman_rfkill_cleanup(void)
if (!channel)
return;
 
+   if (watch) {
+   g_source_remove(watch);
+   watch = 0;
+   }
+
g_io_channel_shutdown(channel, TRUE, NULL);
g_io_channel_unref(channel);
 
-- 
1.9.1

___
connman mailing list
connman@connman.net
https://lists.connman.net/mailman/listinfo/connman