dbus/bus activation.c,1.28,1.29 bus.c,1.42,1.43 connection.c,1.48,1.49 signals.c,1.4,1.5 system.conf.in,1.11,1.12

Havoc Pennington hp@pdx.freedesktop.org
Wed, 15 Oct 2003 23:34:53 -0700


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

Modified Files:
	activation.c bus.c connection.c signals.c system.conf.in 
Log Message:
2003-10-16  Havoc Pennington  <hp@redhat.com>

	* bus/connection.c (bus_pending_reply_expired): either cancel or
	execute, not both
	(bus_connections_check_reply): use unlink, not remove_link, as we
	don't want to free the link; fixes double free mess

	* dbus/dbus-pending-call.c (dbus_pending_call_block): fix in case
	where no reply was received

	* dbus/dbus-connection.c (_dbus_pending_call_complete_and_unlock):
	fix a refcount leak

	* bus/signals.c (match_rule_matches): add special cases for the
	bus driver, so you can match on sender/destination for it.

	* dbus/dbus-sysdeps.c (_dbus_abort): print backtrace if
	DBUS_PRINT_BACKTRACE is set

	* dbus/dbus-internals.c: add pid to assertion failure messages

	* dbus/dbus-connection.c: add message type code to the debug spew

	* glib/dbus-gproxy.c (gproxy_get_match_rule): match rules want
	sender=foo not service=foo

	* dbus/dbus-bus.c (dbus_bus_get): if the activation bus is the
	session bus but DBUS_SESSION_BUS_ADDRESS isn't set, use 
	DBUS_ACTIVATION_ADDRESS instead

	* bus/activation.c: set DBUS_SESSION_BUS_ADDRESS,
	DBUS_SYSTEM_BUS_ADDRESS if appropriate

	* bus/bus.c (bus_context_new): handle OOM copying bus type into
	context struct

	* dbus/dbus-message.c (dbus_message_iter_get_object_path): new function
	(dbus_message_iter_get_object_path_array): new function (half
	finished, disabled for the moment)
	
	* glib/dbus-gproxy.c (dbus_gproxy_end_call): properly handle
	DBUS_MESSAGE_TYPE_ERROR

	* tools/dbus-launch.c (babysit): support DBUS_DEBUG_OUTPUT to
	avoid redirecting stderr to /dev/null
	(babysit): close stdin if not doing the "exit_with_session" thing

	* dbus/dbus-sysdeps.c (_dbus_become_daemon): delete some leftover
	debug code; change DBUS_DEBUG_OUTPUT to only enable stderr, not
	stdout/stdin, so things don't get confused
	
	* bus/system.conf.in: fix to allow replies, I modified .conf
	instead of .conf.in again.



Index: activation.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/activation.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- activation.c	30 Sep 2003 02:32:50 -0000	1.28
+++ activation.c	16 Oct 2003 06:34:51 -0000	1.29
@@ -482,12 +482,25 @@
    */
   if (!_dbus_setenv ("DBUS_ACTIVATION_ADDRESS", activation->server_address))
     _dbus_exit (1);
-
+  
   type = bus_context_get_type (activation->context);
   if (type != NULL)
     {
       if (!_dbus_setenv ("DBUS_BUS_TYPE", type))
         _dbus_exit (1);
+
+      if (strcmp (type, "session") == 0)
+        {
+          if (!_dbus_setenv ("DBUS_SESSION_BUS_ADDRESS",
+                             activation->server_address))
+            _dbus_exit (1);
+        }
+      else if (strcmp (type, "system") == 0)
+        {
+          if (!_dbus_setenv ("DBUS_SYSTEM_BUS_ADDRESS",
+                             activation->server_address))
+            _dbus_exit (1);
+        }
     }
 }
 

Index: bus.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/bus.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- bus.c	14 Oct 2003 22:16:03 -0000	1.42
+++ bus.c	16 Oct 2003 06:34:51 -0000	1.43
@@ -37,6 +37,7 @@
 {
   int refcount;
   char *type;
+  char *bus_env_var;
   char *address;
   char *pidfile;
   DBusLoop *loop;
@@ -398,6 +399,11 @@
 
   /* note that type may be NULL */
   context->type = _dbus_strdup (bus_config_parser_get_type (parser));
+  if (bus_config_parser_get_type (parser) != NULL && context->type == NULL)
+    {
+      BUS_SET_OOM (error);
+      goto failed;
+    }
   
   /* We have to build the address backward, so that
    * <listen> later in the config file have priority

Index: connection.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/connection.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- connection.c	14 Oct 2003 22:16:03 -0000	1.48
+++ connection.c	16 Oct 2003 06:34:51 -0000	1.49
@@ -54,7 +54,7 @@
   BusContext *context;
   DBusHashTable *completed_by_user; /**< Number of completed connections for each UID */
   DBusTimeout *expire_timeout; /**< Timeout for expiring incomplete connections. */
-  int stamp;            /**< Incrementing number */
+  int stamp;                   /**< Incrementing number */
   BusExpireList *pending_replies; /**< List of pending replies */
 };
 
@@ -1340,6 +1340,18 @@
   return TRUE;
 }
 
+static void
+bus_pending_reply_free (BusPendingReply *pending)
+{
+  _dbus_verbose ("Freeing pending reply %p, replier %p receiver %p serial %u\n",
+                 pending,
+                 pending->will_send_reply,
+                 pending->will_get_reply,
+                 pending->reply_serial);
+
+  dbus_free (pending);
+}
+
 static dbus_bool_t
 bus_pending_reply_send_no_reply (BusConnections  *connections,
                                  BusTransaction  *transaction,
@@ -1393,20 +1405,28 @@
    * leave it in the list to try expiring again later when we
    * get more memory.
    */
+
+  _dbus_verbose ("Expiring pending reply %p, replier %p receiver %p serial %u\n",
+                 pending,
+                 pending->will_send_reply,
+                 pending->will_get_reply,
+                 pending->reply_serial);
+  
   transaction = bus_transaction_new (connections->context);
   if (transaction == NULL)
     return;
   
-  if (bus_pending_reply_send_no_reply (connections,
-                                       transaction,
-                                       pending))
+  if (!bus_pending_reply_send_no_reply (connections,
+                                        transaction,
+                                        pending))
     {
-      _dbus_list_remove_link (&connections->pending_replies->items,
-                              link);
-      dbus_free (pending);
       bus_transaction_cancel_and_free (transaction);
+      return;
     }
-
+  
+  _dbus_list_remove_link (&connections->pending_replies->items,
+                          link);
+  bus_pending_reply_free (pending);
   bus_transaction_execute_and_free (transaction);
 }
 
@@ -1418,6 +1438,9 @@
    * do anything with it except check for pointer equality
    */
   DBusList *link;
+
+  _dbus_verbose ("Dropping pending replies that involve connection %p\n",
+                 connection);
   
   link = _dbus_list_get_first_link (&connections->pending_replies->items);
   while (link != NULL)
@@ -1433,16 +1456,27 @@
         {
           /* We don't need to track this pending reply anymore */
 
+          _dbus_verbose ("Dropping pending reply %p, replier %p receiver %p serial %u\n",
+                         pending,
+                         pending->will_send_reply,
+                         pending->will_get_reply,
+                         pending->reply_serial);
+          
           _dbus_list_remove_link (&connections->pending_replies->items,
                                   link);
-          dbus_free (pending);
+          bus_pending_reply_free (pending);
         }
       else if (pending->will_send_reply == connection)
         {
           /* The reply isn't going to be sent, so set things
            * up so it will be expired right away
            */
-
+          _dbus_verbose ("Will expire pending reply %p, replier %p receiver %p serial %u\n",
+                         pending,
+                         pending->will_send_reply,
+                         pending->will_get_reply,
+                         pending->reply_serial);
+          
           pending->will_send_reply = NULL;
           pending->expire_item.added_tv_sec = 0;
           pending->expire_item.added_tv_usec = 0;
@@ -1467,11 +1501,13 @@
 {
   CancelPendingReplyData *d = data;
 
+  _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
+  
   if (!_dbus_list_remove (&d->connections->pending_replies->items,
                           d->pending))
     _dbus_assert_not_reached ("pending reply did not exist to be cancelled");
 
-  dbus_free (d->pending); /* since it's been cancelled */
+  bus_pending_reply_free (d->pending); /* since it's been cancelled */
 }
 
 static void
@@ -1479,6 +1515,8 @@
 {
   CancelPendingReplyData *d = data;
 
+  _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
+  
   /* d->pending should be either freed or still
    * in the list of pending replies (owned by someone
    * else)
@@ -1537,11 +1575,21 @@
       return FALSE;
     }
 
+#ifdef DBUS_ENABLE_VERBOSE_MODE
+  /* so we can see a not-yet-added pending reply */
+  pending->expire_item.added_tv_sec = 1;
+  pending->expire_item.added_tv_usec = 1;
+#endif
+
+  pending->will_get_reply = will_get_reply;
+  pending->will_send_reply = will_send_reply;
+  pending->reply_serial = reply_serial;
+  
   cprd = dbus_new0 (CancelPendingReplyData, 1);
   if (cprd == NULL)
     {
       BUS_SET_OOM (error);
-      dbus_free (pending);
+      bus_pending_reply_free (pending);
       return FALSE;
     }
   
@@ -1550,7 +1598,7 @@
     {
       BUS_SET_OOM (error);
       dbus_free (cprd);
-      dbus_free (pending);
+      bus_pending_reply_free (pending);
       return FALSE;
     }
 
@@ -1562,7 +1610,7 @@
       BUS_SET_OOM (error);
       _dbus_list_remove (&connections->pending_replies->items, pending);
       dbus_free (cprd);
-      dbus_free (pending);
+      bus_pending_reply_free (pending);
       return FALSE;
     }
                                         
@@ -1572,10 +1620,12 @@
   _dbus_get_current_time (&pending->expire_item.added_tv_sec,
                           &pending->expire_item.added_tv_usec);
 
-  pending->will_get_reply = will_get_reply;
-  pending->will_send_reply = will_send_reply;
-  pending->reply_serial = reply_serial;
-
+  _dbus_verbose ("Added pending reply %p, replier %p receiver %p serial %u\n",
+                 pending,
+                 pending->will_send_reply,
+                 pending->will_get_reply,
+                 pending->reply_serial);
+  
   return TRUE;
 }
 
@@ -1590,6 +1640,8 @@
 {
   CheckPendingReplyData *d = data;
 
+  _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
+  
   _dbus_list_prepend_link (&d->connections->pending_replies->items,
                            d->link);
   d->link = NULL;
@@ -1600,11 +1652,16 @@
 {
   CheckPendingReplyData *d = data;
 
+  _dbus_verbose ("%s: d = %p\n", _DBUS_FUNCTION_NAME, d);
+  
   if (d->link != NULL)
     {
       BusPendingReply *pending = d->link->data;
-
-      dbus_free (pending);
+      
+      _dbus_assert (_dbus_list_find_last (&d->connections->pending_replies->items,
+                                          pending) == NULL);
+      
+      bus_pending_reply_free (pending);
       _dbus_list_free_link (d->link);
     }
   
@@ -1641,7 +1698,7 @@
           pending->will_get_reply == receiving_reply &&
           pending->will_send_reply == sending_reply)
         {
-          _dbus_verbose ("Found pending reply\n");
+          _dbus_verbose ("Found pending reply with serial %u\n", reply_serial);
           break;
         }
       
@@ -1676,8 +1733,11 @@
   cprd->link = link;
   cprd->connections = connections;
   
-  _dbus_list_remove_link (&connections->pending_replies->items,
-                          link);
+  _dbus_list_unlink (&connections->pending_replies->items,
+                     link);
+  
+  _dbus_assert (_dbus_list_find_last (&connections->pending_replies->items,
+                                      link->data) == NULL);
 
   return TRUE;
 }
@@ -2075,6 +2135,9 @@
   ch = dbus_new (CancelHook, 1);
   if (ch == NULL)
     return FALSE;
+
+  _dbus_verbose ("     adding cancel hook function = %p data = %p\n",
+                 cancel_function, data);
   
   ch->cancel_function = cancel_function;
   ch->data = data;

Index: signals.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/signals.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- signals.c	10 Oct 2003 03:56:30 -0000	1.4
+++ signals.c	16 Oct 2003 06:34:51 -0000	1.5
@@ -1006,6 +1006,8 @@
   DBusString str;
   BusRegistry *registry;
 
+  _dbus_assert (connection != NULL);
+  
   registry = bus_connection_get_registry (connection);
 
   _dbus_string_init_const (&str, service_name);
@@ -1028,6 +1030,11 @@
    * so FALSE if any of them don't match.
    */
 
+  /* sender/addressed_recipient of #NULL may mean bus driver,
+   * or for addressed_recipient may mean a message with no
+   * specific recipient (i.e. a signal)
+   */
+  
   if (rule->flags & BUS_MATCH_MESSAGE_TYPE)
     {
       _dbus_assert (rule->message_type != DBUS_MESSAGE_TYPE_INVALID);
@@ -1068,8 +1075,17 @@
     {
       _dbus_assert (rule->sender != NULL);
 
-      if (!connection_is_primary_owner (sender, rule->sender))
-        return FALSE;
+      if (sender == NULL)
+        {
+          if (strcmp (rule->sender,
+                      DBUS_SERVICE_ORG_FREEDESKTOP_DBUS) != 0)
+            return FALSE;
+        }
+      else
+        {
+          if (!connection_is_primary_owner (sender, rule->sender))
+            return FALSE;
+        }
     }
 
   if (rule->flags & BUS_MATCH_DESTINATION)
@@ -1078,15 +1094,21 @@
 
       _dbus_assert (rule->destination != NULL);
 
-      if (addressed_recipient == NULL)
-        return FALSE;
-
       destination = dbus_message_get_destination (message);
       if (destination == NULL)
         return FALSE;
 
-      if (!connection_is_primary_owner (addressed_recipient, rule->destination))
-        return FALSE;
+      if (addressed_recipient == NULL)
+        {          
+          if (strcmp (rule->destination,
+                      DBUS_SERVICE_ORG_FREEDESKTOP_DBUS) != 0)
+            return FALSE;
+        }
+      else
+        {
+          if (!connection_is_primary_owner (addressed_recipient, rule->destination))
+            return FALSE;
+        }
     }
 
   if (rule->flags & BUS_MATCH_PATH)

Index: system.conf.in
===================================================================
RCS file: /cvs/dbus/dbus/bus/system.conf.in,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- system.conf.in	30 Sep 2003 02:32:50 -0000	1.11
+++ system.conf.in	16 Oct 2003 06:34:51 -0000	1.12
@@ -44,6 +44,8 @@
          even if they aren't in here -->
     <allow send_destination="org.freedesktop.DBus"/>
     <allow receive_sender="org.freedesktop.DBus"/>
+    <!-- valid replies are always allowed -->
+    <allow requested_reply="true"/>
   </policy>
 
   <!-- Config files are placed here that among other things, punch