summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-04-25 20:41:49 +0000
committerHavoc Pennington <hp@redhat.com>2003-04-25 20:41:49 +0000
commit9c010fbc04a450cc13484682abfbecd31f610305 (patch)
treeb6f8b0cd5b67dbf3b9772956959d616397097ad9
parent3185d7edde8ffc7672aa7d771966b0f1e0158aea (diff)
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
-rw-r--r--ChangeLog5
-rw-r--r--dbus/dbus-watch.c39
-rw-r--r--glib/dbus-gmain.c4
3 files changed, 41 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 7accabfb..872305be 100644
--- 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
diff --git a/dbus/dbus-watch.c b/dbus/dbus-watch.c
index 3b9ddc5e..18044e49 100644
--- a/dbus/dbus-watch.c
+++ b/dbus/dbus-watch.c
@@ -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);
diff --git a/glib/dbus-gmain.c b/glib/dbus-gmain.c
index 15490fbd..dd9ea375 100644
--- a/glib/dbus-gmain.c
+++ b/glib/dbus-gmain.c
@@ -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);
}