[PATCH 1/5] activation: allow for more variation than just "systemd"

Scott James Remnant scott at netsplit.com
Wed Dec 22 07:27:03 PST 2010


Implementing systemd_activation as a bool means we'd end up with
dozens of bools here if every init daemon decided to take over
bus activation.

Turn it into an enum instead.
---
 bus/activation.c |    2 +-
 bus/bus.c        |   16 ++++++++--------
 bus/bus.h        |   12 +++++++++---
 bus/main.c       |    8 ++++----
 4 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/bus/activation.c b/bus/activation.c
index ee5efa8..7d15910 100644
--- a/bus/activation.c
+++ b/bus/activation.c
@@ -1898,7 +1898,7 @@ bus_activation_activate_service (BusActivation  *activation,
   if (activated)
     return TRUE;
 
-  if (bus_context_get_systemd_activation (activation->context))
+  if (bus_context_get_activation_type (activation->context) == ACTIVATION_SYSTEMD)
     {
       if (strcmp (service_name, "org.freedesktop.systemd1") == 0)
           /* systemd itself is missing apparently. That can happen
diff --git a/bus/bus.c b/bus/bus.c
index e8276af..8a5532a 100644
--- a/bus/bus.c
+++ b/bus/bus.c
@@ -51,6 +51,7 @@ struct BusContext
   char *pidfile;
   char *user;
   char *log_prefix;
+  ActivationType activation_type;
   DBusLoop *loop;
   DBusList *servers;
   BusConnections *connections;
@@ -63,7 +64,6 @@ struct BusContext
   unsigned int syslog : 1;
   unsigned int keep_umask : 1;
   unsigned int allow_anonymous : 1;
-  unsigned int systemd_activation : 1;
 };
 
 static dbus_int32_t server_data_slot = -1;
@@ -280,7 +280,7 @@ static dbus_bool_t
 process_config_first_time_only (BusContext       *context,
 				BusConfigParser  *parser,
                                 const DBusString *address,
-                                dbus_bool_t      systemd_activation,
+                                ActivationType    activation_type,
 				DBusError        *error)
 {
   DBusString log_prefix;
@@ -297,7 +297,7 @@ process_config_first_time_only (BusContext       *context,
   retval = FALSE;
   auth_mechanisms = NULL;
 
-  context->systemd_activation = systemd_activation;
+  context->activation_type = activation_type;
 
   /* Check for an existing pid file. Of course this is a race;
    * we'd have to use fcntl() locks on the pid file to
@@ -678,7 +678,7 @@ bus_context_new (const DBusString *config_file,
                  DBusPipe         *print_addr_pipe,
                  DBusPipe         *print_pid_pipe,
                  const DBusString *address,
-                 dbus_bool_t      systemd_activation,
+                 ActivationType   activation_type,
                  DBusError        *error)
 {
   DBusString log_prefix;
@@ -733,12 +733,12 @@ bus_context_new (const DBusString *config_file,
       goto failed;
     }
 
-  if (!process_config_first_time_only (context, parser, address, systemd_activation, error))
+  if (!process_config_first_time_only (context, parser, address, activation_type, error))
     {
       _DBUS_ASSERT_ERROR_IS_SET (error);
       goto failed;
     }
-  if (!process_config_every_time (context, parser, FALSE, error))
+   if (!process_config_every_time (context, parser, FALSE, error))
     {
       _DBUS_ASSERT_ERROR_IS_SET (error);
       goto failed;
@@ -1112,9 +1112,9 @@ bus_context_get_servicehelper (BusContext *context)
 }
 
 dbus_bool_t
-bus_context_get_systemd_activation (BusContext *context)
+bus_context_get_activation_type (BusContext *context)
 {
-  return context->systemd_activation;
+  return context->activation_type;
 }
 
 BusRegistry*
diff --git a/bus/bus.h b/bus/bus.h
index ebef17c..b4ea9e6 100644
--- a/bus/bus.h
+++ b/bus/bus.h
@@ -71,15 +71,21 @@ typedef enum
   FORK_NEVER
 } ForceForkSetting;
 
+typedef enum
+{
+  ACTIVATION_DEFAULT,
+  ACTIVATION_SYSTEMD
+} ActivationType;
+
 BusContext*       bus_context_new                                (const DBusString *config_file,
                                                                   ForceForkSetting  force_fork,
                                                                   DBusPipe         *print_addr_pipe,
                                                                   DBusPipe         *print_pid_pipe,
                                                                   const DBusString *address,
-                                                                  dbus_bool_t      systemd_activation,
+                                                                  ActivationType    activation_type,
                                                                   DBusError        *error);
 dbus_bool_t       bus_context_reload_config                      (BusContext       *context,
-								  DBusError        *error);
+                                                                  DBusError        *error);
 void              bus_context_shutdown                           (BusContext       *context);
 BusContext*       bus_context_ref                                (BusContext       *context);
 void              bus_context_unref                              (BusContext       *context);
@@ -88,7 +94,7 @@ dbus_bool_t       bus_context_get_id                             (BusContext
 const char*       bus_context_get_type                           (BusContext       *context);
 const char*       bus_context_get_address                        (BusContext       *context);
 const char*       bus_context_get_servicehelper                  (BusContext       *context);
-dbus_bool_t       bus_context_get_systemd_activation             (BusContext       *context);
+ActivationType    bus_context_get_activation_type                (BusContext       *context);
 BusRegistry*      bus_context_get_registry                       (BusContext       *context);
 BusConnections*   bus_context_get_connections                    (BusContext       *context);
 BusActivation*    bus_context_get_activation                     (BusContext       *context);
diff --git a/bus/main.c b/bus/main.c
index 53038db..f158d0f 100644
--- a/bus/main.c
+++ b/bus/main.c
@@ -274,7 +274,7 @@ main (int argc, char **argv)
   dbus_bool_t print_pid;
   dbus_bool_t is_session_bus;
   int force_fork;
-  dbus_bool_t systemd_activation;
+  ActivationType activation_type;
 
   if (!_dbus_string_init (&config_file))
     return 1;
@@ -292,7 +292,7 @@ main (int argc, char **argv)
   print_pid = FALSE;
   is_session_bus = FALSE;
   force_fork = FORK_FOLLOW_CONFIG_FILE;
-  systemd_activation = FALSE;
+  activation_type = ACTIVATION_DEFAULT;
 
   prev_arg = NULL;
   i = 1;
@@ -313,7 +313,7 @@ main (int argc, char **argv)
       else if (strcmp (arg, "--fork") == 0)
         force_fork = FORK_ALWAYS;
       else if (strcmp (arg, "--systemd-activation") == 0)
-        systemd_activation = TRUE;
+        activation_type = ACTIVATION_SYSTEMD;
       else if (strcmp (arg, "--system") == 0)
         {
           check_two_config_files (&config_file, "system");
@@ -492,7 +492,7 @@ main (int argc, char **argv)
   context = bus_context_new (&config_file, force_fork,
                              &print_addr_pipe, &print_pid_pipe,
                              _dbus_string_get_length(&address) > 0 ? &address : NULL,
-                             systemd_activation,
+                             activation_type,
                              &error);
   _dbus_string_free (&config_file);
   if (context == NULL)
-- 
1.7.1



More information about the dbus mailing list