2003-04-02 Havoc Pennington <hp@redhat.com>
authorHavoc Pennington <hp@redhat.com>
Wed, 2 Apr 2003 20:14:52 +0000 (20:14 +0000)
committerHavoc Pennington <hp@redhat.com>
Wed, 2 Apr 2003 20:14:52 +0000 (20:14 +0000)
* bus/connection.c (bus_transaction_send_error_reply): set sender
service for the error, and unref the reply on success

* bus/activation.c: convert to use BusTransaction so OOM can be
handled correctly
(bus_activation_service_created): set sender of the message

ChangeLog
bus/activation.c
bus/activation.h
bus/connection.c
bus/dispatch.c
bus/driver.c
bus/services.c

index ba9cb71..6a819e9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2003-04-02  Havoc Pennington  <hp@redhat.com>
+
+       * bus/connection.c (bus_transaction_send_error_reply): set sender
+       service for the error, and unref the reply on success
+
+       * bus/activation.c: convert to use BusTransaction so OOM can be
+       handled correctly
+       (bus_activation_service_created): set sender of the message
+
 2003-04-01  Havoc Pennington  <hp@redhat.com>
 
        * bus/config-parser.c, bus/bus.c: implement <servicedir> and
index 7f3693a..0dfce3f 100644 (file)
@@ -2,6 +2,7 @@
 /* activation.c  Activation of services
  *
  * Copyright (C) 2003  CodeFactory AB
+ * Copyright (C) 2003  Red Hat, Inc.
  *
  * Licensed under the Academic Free License version 1.2
  * 
@@ -412,9 +413,10 @@ child_setup (void *data)
 }
 
 dbus_bool_t
-bus_activation_service_created (BusActivation *activation,
-                               const char    *service_name,
-                               DBusError     *error)
+bus_activation_service_created (BusActivation  *activation,
+                               const char     *service_name,
+                                BusTransaction *transaction,
+                               DBusError      *error)
 {
   BusPendingActivation *pending_activation;
   DBusMessage *message;
@@ -443,7 +445,8 @@ bus_activation_service_created (BusActivation *activation,
              goto error;
            }
 
-         if (!dbus_message_append_args (message,
+         if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS) ||
+              !dbus_message_append_args (message,
                                         DBUS_TYPE_UINT32, DBUS_ACTIVATION_REPLY_ACTIVATED,
                                         0))
            {
@@ -451,8 +454,8 @@ bus_activation_service_created (BusActivation *activation,
              BUS_SET_OOM (error);
              goto error;
            }
-
-         if (!dbus_connection_send (entry->connection, message, NULL))
+          
+         if (!bus_transaction_send_message (transaction, entry->connection, message))
            {
              dbus_message_unref (message);
              BUS_SET_OOM (error);
@@ -478,6 +481,7 @@ bus_activation_service_created (BusActivation *activation,
 dbus_bool_t
 bus_activation_activate_service (BusActivation  *activation,
                                 DBusConnection *connection,
+                                 BusTransaction *transaction,
                                 DBusMessage    *activation_message,
                                  const char     *service_name,
                                 DBusError      *error)
@@ -514,7 +518,8 @@ bus_activation_activate_service (BusActivation  *activation,
          return FALSE;
        }
 
-      if (!dbus_message_append_args (message,
+      if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS) ||
+          !dbus_message_append_args (message,
                                     DBUS_TYPE_UINT32, DBUS_ACTIVATION_REPLY_ALREADY_ACTIVE, 
                                     0))
        {
@@ -523,7 +528,7 @@ bus_activation_activate_service (BusActivation  *activation,
          return FALSE;
        }
 
-      retval = dbus_connection_send (connection, message, NULL);
+      retval = bus_transaction_send_message (transaction, connection, message);
       dbus_message_unref (message);
       if (!retval)
        BUS_SET_OOM (error);
index 0e9e6ea..a2e174f 100644 (file)
@@ -36,11 +36,13 @@ void           bus_activation_ref              (BusActivation     *activation);
 void           bus_activation_unref            (BusActivation     *activation);
 dbus_bool_t    bus_activation_activate_service (BusActivation     *activation,
                                                 DBusConnection    *connection,
+                                                BusTransaction    *transaction,
                                                 DBusMessage       *activation_message,
                                                 const char        *service_name,
                                                 DBusError         *error);
 dbus_bool_t    bus_activation_service_created  (BusActivation     *activation,
                                                 const char        *service_name,
+                                                BusTransaction    *transaction,
                                                 DBusError         *error);
 
 
index 3d83d96..3c43200 100644 (file)
@@ -1030,11 +1030,14 @@ bus_transaction_send_error_reply (BusTransaction  *transaction,
   if (reply == NULL)
     return FALSE;
 
-  if (!bus_transaction_send_message (transaction, connection, reply))
+  if (!dbus_message_set_sender (reply, DBUS_SERVICE_DBUS) ||
+      !bus_transaction_send_message (transaction, connection, reply))
     {
       dbus_message_unref (reply);
       return FALSE;
     }
 
+  dbus_message_unref (reply);
+  
   return TRUE;
 }
index 52214db..7c65ac4 100644 (file)
@@ -751,6 +751,14 @@ check_hello_message (BusContext     *context,
   _dbus_verbose ("Received %s on %p\n",
                  dbus_message_get_name (message), connection);
 
+  if (!dbus_message_sender_is (message, DBUS_SERVICE_DBUS))
+    {
+      _dbus_warn ("Message has wrong sender %s\n",
+                  dbus_message_get_sender (message) ?
+                  dbus_message_get_sender (message) : "(none)");
+      goto out;
+    }
+  
   if (dbus_message_get_is_error (message))
     {
       if (dbus_message_name_is (message,
@@ -916,6 +924,110 @@ check_hello_connection (BusContext *context)
   return TRUE;
 }
 
+#define NONEXISTENT_SERVICE_NAME "test.this.service.does.not.exist.ewuoiurjdfxcvn"
+
+/* returns TRUE if the correct thing happens,
+ * but the correct thing may include OOM errors.
+ */
+static dbus_bool_t
+check_nonexistent_service_activation (BusContext     *context,
+                                      DBusConnection *connection)
+{
+  DBusMessage *message;
+  dbus_int32_t serial;
+  dbus_bool_t retval;
+  DBusError error;
+  
+  dbus_error_init (&error);
+  
+  message = dbus_message_new (DBUS_SERVICE_DBUS,
+                             DBUS_MESSAGE_ACTIVATE_SERVICE);
+
+  if (message == NULL)
+    return TRUE;
+
+  if (!dbus_message_append_args (message,
+                                 DBUS_TYPE_STRING, NONEXISTENT_SERVICE_NAME,
+                                 DBUS_TYPE_UINT32, 0,
+                                 DBUS_TYPE_INVALID))
+    {
+      dbus_message_unref (message);
+      return TRUE;
+    }
+  
+  if (!dbus_connection_send (connection, message, &serial))
+    {
+      dbus_message_unref (message);
+      return TRUE;
+    }
+
+  dbus_message_unref (message);
+  message = NULL;
+  
+  bus_test_flush_bus (context);
+
+  if (!dbus_connection_get_is_connected (connection))
+    {
+      _dbus_verbose ("connection was disconnected\n");
+      return TRUE;
+    }
+  
+  retval = FALSE;
+  
+  message = dbus_connection_pop_message (connection);
+  if (message == NULL)
+    {
+      _dbus_warn ("Did not receive a reply to %s %d on %p\n",
+                  DBUS_MESSAGE_ACTIVATE_SERVICE, serial, connection);
+      goto out;
+    }
+
+  _dbus_verbose ("Received %s on %p\n",
+                 dbus_message_get_name (message), connection);
+
+  if (dbus_message_get_is_error (message))
+    {
+      if (!dbus_message_sender_is (message, DBUS_SERVICE_DBUS))
+        {
+          _dbus_warn ("Message has wrong sender %s\n",
+                      dbus_message_get_sender (message) ?
+                      dbus_message_get_sender (message) : "(none)");
+          goto out;
+        }
+      
+      if (dbus_message_name_is (message,
+                                DBUS_ERROR_NO_MEMORY))
+        {
+          ; /* good, this is a valid response */
+        }
+      else if (dbus_message_name_is (message,
+                                     DBUS_ERROR_ACTIVATE_SERVICE_NOT_FOUND))
+        {
+          ; /* good, this is expected also */
+        }
+      else
+        {
+          _dbus_warn ("Did not expect error %s\n",
+                      dbus_message_get_name (message));
+          goto out;
+        }
+    }
+  else
+    {
+      _dbus_warn ("Did not expect to successfully activate %s\n",
+                  NONEXISTENT_SERVICE_NAME);
+      goto out;
+    }
+
+  retval = TRUE;
+  
+ out:
+  if (message)
+    dbus_message_unref (message);
+  
+  return retval;
+}
+
 typedef struct
 {
   Check1Func func;
@@ -954,6 +1066,47 @@ check1_try_iterations (BusContext *context,
     _dbus_assert_not_reached ("test failed");
 }
 
+typedef struct
+{
+  Check2Func func;
+  BusContext *context;
+  DBusConnection *connection;
+} Check2Data;
+
+static dbus_bool_t
+check_oom_check2_func (void *data)
+{
+  Check2Data *d = data;
+
+  if (! (* d->func) (d->context, d->connection))
+    return FALSE;
+  
+  if (!check_no_leftovers (d->context))
+    {
+      _dbus_warn ("Messages were left over, should be covered by test suite");
+      return FALSE;
+    }
+
+  return TRUE;
+}
+
+static void
+check2_try_iterations (BusContext     *context,
+                       DBusConnection *connection,
+                       const char     *description,
+                       Check2Func      func)
+{
+  Check2Data d;
+
+  d.func = func;
+  d.context = context;
+  d.connection = connection;
+  
+  if (!_dbus_test_oom_handling (description, check_oom_check2_func,
+                                &d))
+    _dbus_assert_not_reached ("test failed");
+}
+
 dbus_bool_t
 bus_dispatch_test (const DBusString *test_data_dir)
 {
@@ -1000,6 +1153,9 @@ bus_dispatch_test (const DBusString *test_data_dir)
   if (!check_hello_message (context, baz))
     _dbus_assert_not_reached ("hello message failed");
 
+  check2_try_iterations (context, foo, "nonexistent_service_activation",
+                         check_nonexistent_service_activation);
+
   check1_try_iterations (context, "create_and_hello",
                          check_hello_connection);
   
index 8749bc1..0cea1d6 100644 (file)
@@ -645,7 +645,8 @@ bus_driver_handle_activate_service (DBusConnection *connection,
 
   retval = FALSE;
 
-  if (!bus_activation_activate_service (activation, connection, message, name, error))
+  if (!bus_activation_activate_service (activation, connection, transaction,
+                                        message, name, error))
     goto out;
 
   retval = TRUE;
index 8d4221f..3a7a075 100644 (file)
@@ -158,7 +158,7 @@ bus_registry_ensure (BusRegistry               *registry,
     }
 
   if (!bus_activation_service_created (bus_context_get_activation (registry->context),
-                                      service->name, error))
+                                      service->name, transaction, error))
     {
       dbus_free (service->name);
       _dbus_mem_pool_dealloc (registry->service_pool, service);