]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
2003-04-25 Havoc Pennington <hp@redhat.com>
authorHavoc Pennington <hp@redhat.com>
Fri, 25 Apr 2003 20:41:49 +0000 (20:41 +0000)
committerHavoc Pennington <hp@redhat.com>
Fri, 25 Apr 2003 20:41:49 +0000 (20:41 +0000)
* glib/dbus-gmain.c (remove_watch): fix for a crash when watches
were toggled without add/remove, fix from Anders Gustafsson

ChangeLog
dbus/dbus-watch.c
glib/dbus-gmain.c

index 7accabfb93c32370f00746911ef73cc6051c02fb..872305befe2b0e9361d21f3c2f7f54bd037f44e1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2003-04-25  Havoc Pennington  <hp@redhat.com>
+
+       * glib/dbus-gmain.c (remove_watch): fix for a crash when watches
+       were toggled without add/remove, fix from Anders Gustafsson
+
 2003-04-24  Havoc Pennington  <hp@redhat.com>
 
        * test/data/valid-config-files/basic.conf: add <limit> tags to
index 3b9ddc5e4b3c3df9285f27f3a2452195757b8f52..18044e49766a08463f810f971dc1863c737bf3f3 100644 (file)
@@ -261,7 +261,10 @@ _dbus_watch_list_set_functions (DBusWatchList           *watch_list,
         {
           DBusList *next = _dbus_list_get_next_link (&watch_list->watches,
                                                      link);
-      
+
+          _dbus_verbose ("Adding a watch on fd %d using newly-set add watch function\n",
+                         dbus_watch_get_fd (link->data));
+          
           if (!(* add_function) (link->data, data))
             {
               /* remove it all again and return FALSE */
@@ -272,7 +275,10 @@ _dbus_watch_list_set_functions (DBusWatchList           *watch_list,
                 {
                   DBusList *next = _dbus_list_get_next_link (&watch_list->watches,
                                                              link2);
-
+                  
+                  _dbus_verbose ("Removing watch on fd %d using newly-set remove function because initial add failed\n",
+                                 dbus_watch_get_fd (link2->data));
+                  
                   (* remove_function) (link2->data, data);
                   
                   link2 = next;
@@ -289,6 +295,8 @@ _dbus_watch_list_set_functions (DBusWatchList           *watch_list,
 
   if (watch_list->remove_watch_function != NULL)
     {
+      _dbus_verbose ("Removing all pre-existing watches\n");
+      
       _dbus_list_foreach (&watch_list->watches,
                           (DBusForeachFunction) watch_list->remove_watch_function,
                           watch_list->watch_data);
@@ -325,6 +333,9 @@ _dbus_watch_list_add_watch (DBusWatchList *watch_list,
 
   if (watch_list->add_watch_function != NULL)
     {
+      _dbus_verbose ("Adding watch on fd %d\n",
+                     dbus_watch_get_fd (watch));
+      
       if (!(* watch_list->add_watch_function) (watch,
                                                watch_list->watch_data))
         {
@@ -350,10 +361,15 @@ _dbus_watch_list_remove_watch  (DBusWatchList *watch_list,
 {
   if (!_dbus_list_remove (&watch_list->watches, watch))
     _dbus_assert_not_reached ("Nonexistent watch was removed");
-
+  
   if (watch_list->remove_watch_function != NULL)
-    (* watch_list->remove_watch_function) (watch,
-                                           watch_list->watch_data);
+    {
+      _dbus_verbose ("Removing watch on fd %d\n",
+                     dbus_watch_get_fd (watch));
+      
+      (* watch_list->remove_watch_function) (watch,
+                                             watch_list->watch_data);
+    }
   
   _dbus_watch_unref (watch);
 }
@@ -379,8 +395,13 @@ _dbus_watch_list_toggle_watch (DBusWatchList           *watch_list,
   watch->enabled = enabled;
   
   if (watch_list->watch_toggled_function != NULL)
-    (* watch_list->watch_toggled_function) (watch,
-                                            watch_list->watch_data);
+    {
+      _dbus_verbose ("Toggling watch on fd %d to %d\n",
+                     dbus_watch_get_fd (watch), watch->enabled);
+      
+      (* watch_list->watch_toggled_function) (watch,
+                                              watch_list->watch_data);
+    }
 }
 
 /**
@@ -493,6 +514,10 @@ dbus_watch_set_data (DBusWatch        *watch,
                      void             *data,
                      DBusFreeFunction  free_data_function)
 {
+  _dbus_verbose ("Setting watch fd %d data to data = %p function = %p from data = %p function = %p\n",
+                 dbus_watch_get_fd (watch),
+                 data, free_data_function, watch->data, watch->free_data_function);
+  
   if (watch->free_data_function != NULL)
     (* watch->free_data_function) (watch->data);
   
index 15490fbd6b1edf782f75753eb88a65e066b229e2..dd9ea37583aee72b59fefe885d57d1e7e024b796 100644 (file)
@@ -275,6 +275,10 @@ remove_watch (DBusWatch *watch,
   dbus_source->poll_fds = g_list_remove (dbus_source->poll_fds, poll_fd);
   g_hash_table_remove (dbus_source->watches, poll_fd);
   g_source_remove_poll ((GSource *)dbus_source, poll_fd);
+
+  dbus_watch_set_data (watch, NULL, NULL); /* needed due to watch_toggled
+                                            * breaking add/remove symmetry
+                                            */
   
   g_free (poll_fd);
 }