summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-04-02 20:14:52 +0000
committerHavoc Pennington <hp@redhat.com>2003-04-02 20:14:52 +0000
commite55fd2c6706e41f6933e1656ac3da7527ee2514f (patch)
tree36329f8a7da856381c7538d01cb138e2db81be47
parentcfa261b49dd9cafb172deae3db22dba0c2e54bf9 (diff)
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
-rw-r--r--ChangeLog9
-rw-r--r--bus/activation.c21
-rw-r--r--bus/activation.h2
-rw-r--r--bus/connection.c5
-rw-r--r--bus/dispatch.c156
-rw-r--r--bus/driver.c3
-rw-r--r--bus/services.c2
7 files changed, 187 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index ba9cb712..6a819e97 100644
--- 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
diff --git a/bus/activation.c b/bus/activation.c
index 7f3693a0..0dfce3f8 100644
--- a/bus/activation.c
+++ b/bus/activation.c
@@ -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);
diff --git a/bus/activation.h b/bus/activation.h
index 0e9e6ea3..a2e174f9 100644
--- a/bus/activation.h
+++ b/bus/activation.h
@@ -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);
diff --git a/bus/connection.c b/bus/connection.c
index 3d83d96c..3c43200f 100644
--- a/bus/connection.c
+++ b/bus/connection.c
@@ -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;
}
diff --git a/bus/dispatch.c b/bus/dispatch.c
index 52214dbf..7c65ac42 100644
--- a/bus/dispatch.c
+++ b/bus/dispatch.c
@@ -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);
diff --git a/bus/driver.c b/bus/driver.c
index 8749bc13..0cea1d6f 100644
--- a/bus/driver.c
+++ b/bus/driver.c
@@ -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;
diff --git a/bus/services.c b/bus/services.c
index 8d4221fb..3a7a0756 100644
--- a/bus/services.c
+++ b/bus/services.c
@@ -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);