[PATCH 2/5] activation: always perform activation with the manager

Scott James Remnant scott at netsplit.com
Sun Jan 2 14:46:54 PST 2011


If there is an application manager, unconditionally activate using
it; if there is no ActivationRequest= member of the service file,
pass the name of the service to be activated instead.
---
 bus/activation.c |  152 +++++++++++++++++++++++++++--------------------------
 1 files changed, 77 insertions(+), 75 deletions(-)

diff --git a/bus/activation.c b/bus/activation.c
index 70ecff8..7f4eaa7 100644
--- a/bus/activation.c
+++ b/bus/activation.c
@@ -1900,91 +1900,91 @@ bus_activation_activate_service (BusActivation  *activation,
 
   if (bus_context_get_systemd_activation (activation->context))
     {
+      BusTransaction *activation_transaction;
+      DBusString service_string;
+      BusService *service;
+      BusRegistry *registry;
+      const char *request;
+
       if (strcmp (service_name, "org.freedesktop.systemd1") == 0)
           /* systemd itself is missing apparently. That can happen
              only during early startup. Let's just wait until systemd
              connects to us and do nothing. */
         return TRUE;
 
-      if (entry->activation_request)
+      /* Enqueue an activation request message. This is implemented
+         as a directed signal, not a method call, for three reasons:
+         1) we don't expect a response on success, where we just
+         expect a name appearing on the bus; 2) at this time the
+         systemd service might not yet have connected, so we
+         wouldn't know the message serial at this point to set up
+         a pending call; 3) it is ugly if the bus suddenly becomes
+         the caller of a remote method. */
+
+      message = dbus_message_new_signal (DBUS_PATH_DBUS,
+                                         "org.freedesktop.systemd1.Activator",
+                                         "ActivationRequest");
+      if (!message)
         {
-          BusTransaction *activation_transaction;
-          DBusString service_string;
-          BusService *service;
-          BusRegistry *registry;
-
-          /* OK, we have a systemd service configured for this entry,
-             hence let's enqueue an activation request message. This
-             is implemented as a directed signal, not a method call,
-             for three reasons: 1) we don't expect a response on
-             success, where we just expect a name appearing on the
-             bus; 2) at this time the systemd service might not yet
-             have connected, so we wouldn't know the message serial at
-             this point to set up a pending call; 3) it is ugly if the
-             bus suddenly becomes the caller of a remote method. */
-
-          message = dbus_message_new_signal (DBUS_PATH_DBUS,
-                                             "org.freedesktop.systemd1.Activator",
-                                             "ActivationRequest");
-          if (!message)
-            {
-              _dbus_verbose ("No memory to create activation message\n");
-              BUS_SET_OOM (error);
-              return FALSE;
-            }
-
-          if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS) ||
-              !dbus_message_set_destination (message, "org.freedesktop.systemd1") ||
-              !dbus_message_append_args (message,
-                                         DBUS_TYPE_STRING, &entry->activation_request,
-                                         DBUS_TYPE_INVALID))
-            {
-              _dbus_verbose ("No memory to set args of activation message\n");
-              dbus_message_unref (message);
-              BUS_SET_OOM (error);
-              return FALSE;
-            }
+          _dbus_verbose ("No memory to create activation message\n");
+          BUS_SET_OOM (error);
+          return FALSE;
+        }
 
-          /* Create our transaction */
-          activation_transaction = bus_transaction_new (activation->context);
-          if (activation_transaction == NULL)
-            {
-              _dbus_verbose ("No memory to create activation transaction\n");
-              dbus_message_unref (message);
-              BUS_SET_OOM (error);
-              return FALSE;
-            }
+      /* Activation can be performed by bus name, or by a request named
+         in the service file. */
+      request = entry->activation_request;
+      if (!request)
+        request = entry->name;
+
+      if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS) ||
+          !dbus_message_set_destination (message, "org.freedesktop.systemd1") ||
+          !dbus_message_append_args (message,
+                                     DBUS_TYPE_STRING, &request,
+                                     DBUS_TYPE_INVALID))
+        {
+          _dbus_verbose ("No memory to set args of activation message\n");
+          dbus_message_unref (message);
+          BUS_SET_OOM (error);
+          return FALSE;
+        }
 
-          /* Check whether systemd is already connected */
-          registry = bus_connection_get_registry (connection);
-          _dbus_string_init_const (&service_string, "org.freedesktop.systemd1");
-          service = bus_registry_lookup (registry, &service_string);
+      /* Create our transaction */
+      activation_transaction = bus_transaction_new (activation->context);
+      if (activation_transaction == NULL)
+        {
+          _dbus_verbose ("No memory to create activation transaction\n");
+          dbus_message_unref (message);
+          BUS_SET_OOM (error);
+          return FALSE;
+        }
 
-          if (service != NULL)
-            /* Wonderful, systemd is connected, let's just send the msg */
-            retval = bus_dispatch_matches (activation_transaction, NULL, bus_service_get_primary_owners_connection (service),
-                                           message, error);
-          else
-            /* systemd is not around, let's "activate" it. */
-            retval = bus_activation_activate_service (activation, connection, activation_transaction, TRUE,
-                                                      message, "org.freedesktop.systemd1", error);
+      /* Check whether systemd is already connected */
+      registry = bus_connection_get_registry (connection);
+      _dbus_string_init_const (&service_string, "org.freedesktop.systemd1");
+      service = bus_registry_lookup (registry, &service_string);
 
-          dbus_message_unref (message);
+      if (service != NULL)
+        /* Wonderful, systemd is connected, let's just send the msg */
+        retval = bus_dispatch_matches (activation_transaction, NULL, bus_service_get_primary_owners_connection (service),
+                                       message, error);
+      else
+        /* systemd is not around, let's "activate" it. */
+        retval = bus_activation_activate_service (activation, connection, activation_transaction, TRUE,
+                                                  message, "org.freedesktop.systemd1", error);
 
-          if (!retval)
-            {
-              _DBUS_ASSERT_ERROR_IS_SET (error);
-              _dbus_verbose ("failed to send activation message: %s\n", error->name);
-              bus_transaction_cancel_and_free (activation_transaction);
-              return FALSE;
-            }
+      dbus_message_unref (message);
 
-          bus_transaction_execute_and_free (activation_transaction);
-          return TRUE;
+      if (!retval)
+        {
+          _DBUS_ASSERT_ERROR_IS_SET (error);
+          _dbus_verbose ("failed to send activation message: %s\n", error->name);
+          bus_transaction_cancel_and_free (activation_transaction);
+          return FALSE;
         }
 
-      /* OK, we have no configured systemd service, hence let's
-         proceed with traditional activation. */
+      bus_transaction_execute_and_free (activation_transaction);
+      return TRUE;
     }
 
   /* use command as system and session different */
@@ -2150,22 +2150,22 @@ dbus_activation_systemd_failure (BusActivation *activation,
                                  DBusMessage   *message)
 {
   DBusError error;
-  const char *code, *str, *unit = NULL;
+  const char *code, *str, *request = NULL;
 
   dbus_error_init(&error);
 
   /* This is called whenever the systemd activator sent us a
      response. We'll invalidate all pending activations that match the
-     unit name. */
+     request. */
 
   if (dbus_message_get_args (message, &error,
-                             DBUS_TYPE_STRING, &unit,
+                             DBUS_TYPE_STRING, &request,
                              DBUS_TYPE_STRING, &code,
                              DBUS_TYPE_STRING, &str,
                              DBUS_TYPE_INVALID))
     dbus_set_error(&error, code, str);
 
-  if (unit)
+  if (request)
     {
       DBusHashIter iter;
 
@@ -2176,7 +2176,9 @@ dbus_activation_systemd_failure (BusActivation *activation,
         {
           BusPendingActivation *p = _dbus_hash_iter_get_value (&iter);
 
-          if (p->activation_request && strcmp (p->activation_request, unit) == 0)
+          if (p->activation_request && strcmp (p->activation_request, request) == 0)
+            pending_activation_failed(p, &error);
+          if (!p->activation_request && strcmp (p->service_name, request) == 0)
             pending_activation_failed(p, &error);
         }
     }
-- 
1.7.1



More information about the dbus mailing list