dbus/bus connection.c,1.50,1.51 dispatch.c,1.54,1.55 expirelist.c,1.2,1.3 expirelist.h,1.2,1.3

Havoc Pennington hp@pdx.freedesktop.org
Tue, 28 Oct 2003 15:51:26 -0800


Update of /cvs/dbus/dbus/bus
In directory pdx:/tmp/cvs-serv2577/bus

Modified Files:
	connection.c dispatch.c expirelist.c expirelist.h 
Log Message:
2003-10-28  Havoc Pennington  <hp@redhat.com>

	* bus/expirelist.c (do_expiration_with_current_time): detect
	failure of the expire_func due to OOM

	* bus/connection.c (bus_pending_reply_expired): return FALSE on OOM

	* bus/dispatch.c (check_send_exit_to_service): fix to handle the
	NoReply error that's now created by the bus when the service exits



Index: connection.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/connection.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -d -r1.50 -r1.51
--- connection.c	22 Oct 2003 16:01:08 -0000	1.50
+++ connection.c	28 Oct 2003 23:51:24 -0000	1.51
@@ -80,9 +80,9 @@
   int stamp;               /**< connections->stamp last time we were traversed */
 } BusConnectionData;
 
-static void bus_pending_reply_expired (BusExpireList *list,
-                                       DBusList      *link,
-                                       void          *data);
+static dbus_bool_t bus_pending_reply_expired (BusExpireList *list,
+                                              DBusList      *link,
+                                              void          *data);
 
 static void bus_connection_drop_pending_replies (BusConnections  *connections,
                                                  DBusConnection  *connection);
@@ -1392,7 +1392,7 @@
   return retval;
 }
 
-static void
+static dbus_bool_t
 bus_pending_reply_expired (BusExpireList *list,
                            DBusList      *link,
                            void          *data)
@@ -1414,20 +1414,22 @@
   
   transaction = bus_transaction_new (connections->context);
   if (transaction == NULL)
-    return;
+    return FALSE;
   
   if (!bus_pending_reply_send_no_reply (connections,
                                         transaction,
                                         pending))
     {
       bus_transaction_cancel_and_free (transaction);
-      return;
+      return FALSE;
     }
   
   _dbus_list_remove_link (&connections->pending_replies->items,
                           link);
   bus_pending_reply_free (pending);
   bus_transaction_execute_and_free (transaction);
+
+  return TRUE;
 }
 
 static void

Index: dispatch.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/dispatch.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- dispatch.c	21 Oct 2003 05:46:51 -0000	1.54
+++ dispatch.c	28 Oct 2003 23:51:24 -0000	1.55
@@ -415,16 +415,20 @@
                       const char     *function,
                       int             line)
 {
-  _dbus_warn ("%s:%d received message interface \"%s\" member \"%s\" error name \"%s\" on %p, expecting %s\n",
-              function, line,
-              dbus_message_get_interface (message) ?
-              dbus_message_get_interface (message) : "(unset)",
-              dbus_message_get_member (message) ?
-              dbus_message_get_member (message) : "(unset)",
-              dbus_message_get_error_name (message) ?
-              dbus_message_get_error_name (message) : "(unset)",
-              connection,
-              expected);
+  if (message)
+    _dbus_warn ("%s:%d received message interface \"%s\" member \"%s\" error name \"%s\" on %p, expecting %s\n",
+                function, line,
+                dbus_message_get_interface (message) ?
+                dbus_message_get_interface (message) : "(unset)",
+                dbus_message_get_member (message) ?
+                dbus_message_get_member (message) : "(unset)",
+                dbus_message_get_error_name (message) ?
+                dbus_message_get_error_name (message) : "(unset)",
+                connection,
+                expected);
+  else
+    _dbus_warn ("%s:%d received no message on %p, expecting %s\n",
+                function, line, connection, expected);
 }
 
 #define warn_unexpected(connection, message, expected) \
@@ -1428,12 +1432,6 @@
 
   if (csdd.failed)
     goto out;
-      
-  if (!check_no_leftovers (context))
-    {
-      _dbus_warn ("Messages were left over after verifying results of service exiting\n");
-      goto out;
-    }
 
   retval = TRUE;
   
@@ -1519,6 +1517,13 @@
       message = pop_message_waiting_for_memory (connection);
       _dbus_assert (message != NULL);
 
+      if (dbus_message_get_reply_serial (message) != serial)
+        {
+          warn_unexpected (connection, message,
+                           "error with the correct reply serial");
+          goto out;
+        }
+      
       if (!dbus_message_is_error (message,
                                   DBUS_ERROR_NO_MEMORY))
         {
@@ -1540,8 +1545,45 @@
       if (!check_service_deactivated (context, connection,
                                       service_name, base_service))
         goto out;
-    }
 
+      /* Should now have a NoReply error from the Exit() method
+       * call; it should have come after all the deactivation
+       * stuff.
+       */
+      message = pop_message_waiting_for_memory (connection);
+          
+      if (message == NULL)
+        {
+          warn_unexpected (connection, NULL,
+                           "reply to Exit() method call");
+          goto out;
+        }
+      if (!dbus_message_is_error (message,
+                                  DBUS_ERROR_NO_REPLY))
+        {
+          warn_unexpected (connection, NULL,
+                           "NoReply error from Exit() method call");
+          goto out;
+        }
+
+      if (dbus_message_get_reply_serial (message) != serial)
+        {
+          warn_unexpected (connection, message,
+                           "error with the correct reply serial");
+          goto out;
+        }
+          
+      _dbus_verbose ("Got error %s after test service exited\n",
+                     dbus_message_get_error_name (message));
+      
+      if (!check_no_leftovers (context))
+        {
+          _dbus_warn ("Messages were left over after %s\n",
+                      _DBUS_FUNCTION_NAME);
+          goto out;
+        }
+    }
+  
   retval = TRUE;
   
  out:

Index: expirelist.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/expirelist.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- expirelist.c	14 Oct 2003 05:16:56 -0000	1.2
+++ expirelist.c	28 Oct 2003 23:51:24 -0000	1.3
@@ -143,11 +143,16 @@
           _dbus_verbose ("Expiring an item %p\n", item);
 
           /* If the expire function fails, we just end up expiring
-           * this item next time we walk through the list. Which is in
-           * indeterminate time since we don't know what next_interval
-           * will be.
+           * this item next time we walk through the list. This would
+           * be an indeterminate time normally, so we set up the
+           * next_interval to be "shortly" (just enough to avoid
+           * a busy loop)
            */
-          (* list->expire_func) (list, link, list->data);
+          if (!(* list->expire_func) (list, link, list->data))
+            {
+              next_interval = _dbus_get_oom_wait ();
+              break;
+            }
         }
       else
         {
@@ -205,7 +210,7 @@
   int expire_count;
 } TestExpireItem;
 
-static void
+static dbus_bool_t
 test_expire_func (BusExpireList *list,
                   DBusList      *link,
                   void          *data)
@@ -215,6 +220,8 @@
   t = (TestExpireItem*) link->data;
 
   t->expire_count += 1;
+
+  return TRUE;
 }
 
 static void

Index: expirelist.h
===================================================================
RCS file: /cvs/dbus/dbus/bus/expirelist.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- expirelist.h	14 Oct 2003 05:16:56 -0000	1.2
+++ expirelist.h	28 Oct 2003 23:51:24 -0000	1.3
@@ -31,9 +31,9 @@
 typedef struct BusExpireList BusExpireList;
 typedef struct BusExpireItem BusExpireItem;
 
-typedef void (* BusExpireFunc) (BusExpireList *list,
-                                DBusList      *link,
-                                void          *data);
+typedef dbus_bool_t (* BusExpireFunc) (BusExpireList *list,
+                                       DBusList      *link,
+                                       void          *data);
 
 struct BusExpireList
 {