[PATCH 3/5] activation: pass additional fields in activation request

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


Since we undconditionally activate services, the activation manager
may not have a definition so pass the Exec and User service fields
in the request as well.

Also pass the activation environment since we may well want to do
session bus activation.
---
 bus/activation.c |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/bus/activation.c b/bus/activation.c
index 7f4eaa7..edd8e33 100644
--- a/bus/activation.c
+++ b/bus/activation.c
@@ -1905,6 +1905,9 @@ bus_activation_activate_service (BusActivation  *activation,
       BusService *service;
       BusRegistry *registry;
       const char *request;
+      const char *user;
+      DBusMessageIter iter, array_iter;
+      char **envp, **e;
 
       if (strcmp (service_name, "org.freedesktop.systemd1") == 0)
           /* systemd itself is missing apparently. That can happen
@@ -1937,10 +1940,16 @@ bus_activation_activate_service (BusActivation  *activation,
       if (!request)
         request = entry->name;
 
+      user = entry->user;
+      if (!user)
+        user = "";
+
       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_STRING, &entry->exec,
+                                     DBUS_TYPE_STRING, &user,
                                      DBUS_TYPE_INVALID))
         {
           _dbus_verbose ("No memory to set args of activation message\n");
@@ -1949,6 +1958,48 @@ bus_activation_activate_service (BusActivation  *activation,
           return FALSE;
         }
 
+      dbus_message_iter_init_append (message, &iter);
+
+      if (!dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
+                                             DBUS_TYPE_STRING_AS_STRING, &array_iter))
+        {
+          _dbus_verbose ("No memory to set args of activation message\n");
+          dbus_message_unref (message);
+          BUS_SET_OOM (error);
+          return FALSE;
+        }
+
+      envp = bus_activation_get_environment (activation);
+      if (envp == NULL)
+        {
+          _dbus_verbose ("No memory to get environment for activation message\n");
+          dbus_message_unref (message);
+          BUS_SET_OOM (error);
+          return FALSE;
+        }
+
+      for (e = envp; *e; e++)
+        {
+          if (!dbus_message_iter_append_basic (&array_iter, DBUS_TYPE_STRING, e))
+            {
+              _dbus_verbose ("No memory to set args of activation message\n");
+              dbus_message_unref (message);
+              dbus_free_string_array (envp);
+              BUS_SET_OOM (error);
+              return FALSE;
+            }
+        }
+
+      dbus_free_string_array (envp);
+
+      if (!dbus_message_iter_close_container (&iter, &array_iter))
+        {
+          _dbus_verbose ("No memory to set args of activation message\n");
+          dbus_message_unref (message);
+          BUS_SET_OOM (error);
+          return FALSE;
+        }
+
       /* Create our transaction */
       activation_transaction = bus_transaction_new (activation->context);
       if (activation_transaction == NULL)
-- 
1.7.1



More information about the dbus mailing list