[PATCH 5/5] activation: change activation parameter to be a bus name
Scott James Remnant
scott at netsplit.com
Sun Jan 2 14:46:57 PST 2011
Rather than hardcoding the activation manager's bus name and
using a flag on the command-line, take the bus name that we
wish to use.
---
bus/activation.c | 25 ++++++++++++++-----------
bus/bus.c | 25 ++++++++++++++++---------
bus/bus.h | 4 ++--
bus/dbus.service.in | 2 +-
bus/main.c | 47 +++++++++++++++++++++++++++++++++++++++++------
5 files changed, 74 insertions(+), 29 deletions(-)
diff --git a/bus/activation.c b/bus/activation.c
index 74058f6..0a0793f 100644
--- a/bus/activation.c
+++ b/bus/activation.c
@@ -1665,6 +1665,7 @@ bus_activation_activate_service (BusActivation *activation,
DBusMessage *message;
DBusString service_str;
const char *servicehelper;
+ const char *activation_manager;
char **argv;
char **envp = NULL;
int argc;
@@ -1898,7 +1899,8 @@ bus_activation_activate_service (BusActivation *activation,
if (activated)
return TRUE;
- if (bus_context_get_systemd_activation (activation->context))
+ activation_manager = bus_context_get_activation_manager (activation->context);
+ if (activation_manager != NULL)
{
BusTransaction *activation_transaction;
DBusString service_string;
@@ -1909,9 +1911,9 @@ bus_activation_activate_service (BusActivation *activation,
DBusMessageIter iter, array_iter;
char **envp, **e;
- 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
+ if (strcmp (service_name, activation_manager) == 0)
+ /* activation manager itself is missing apparently. That can
+ happen only during early startup. Let's just wait until it
connects to us and do nothing. */
return TRUE;
@@ -1919,7 +1921,7 @@ bus_activation_activate_service (BusActivation *activation,
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
+ activation manager 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. */
@@ -1945,7 +1947,7 @@ bus_activation_activate_service (BusActivation *activation,
user = "";
if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS) ||
- !dbus_message_set_destination (message, "org.freedesktop.systemd1") ||
+ !dbus_message_set_destination (message, activation_manager) ||
!dbus_message_append_args (message,
DBUS_TYPE_STRING, &request,
DBUS_TYPE_STRING, &entry->exec,
@@ -2010,19 +2012,20 @@ bus_activation_activate_service (BusActivation *activation,
return FALSE;
}
- /* Check whether systemd is already connected */
+ /* Check whether activation manager is already connected */
registry = bus_connection_get_registry (connection);
- _dbus_string_init_const (&service_string, "org.freedesktop.systemd1");
+ _dbus_string_init_const (&service_string, activation_manager);
service = bus_registry_lookup (registry, &service_string);
if (service != NULL)
- /* Wonderful, systemd is connected, let's just send the msg */
+ /* Wonderful, activation manager 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. */
+ /* activation manager is not around, let's "activate" it. */
retval = bus_activation_activate_service (activation, connection, activation_transaction, TRUE,
- message, "org.freedesktop.systemd1", error);
+ message, activation_manager, error);
dbus_message_unref (message);
diff --git a/bus/bus.c b/bus/bus.c
index e8276af..6881393 100644
--- a/bus/bus.c
+++ b/bus/bus.c
@@ -48,6 +48,7 @@ struct BusContext
char *type;
char *servicehelper;
char *address;
+ char *activation_manager;
char *pidfile;
char *user;
char *log_prefix;
@@ -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,
+ const DBusString *activation_manager,
DBusError *error)
{
DBusString log_prefix;
@@ -297,8 +297,6 @@ process_config_first_time_only (BusContext *context,
retval = FALSE;
auth_mechanisms = NULL;
- context->systemd_activation = systemd_activation;
-
/* Check for an existing pid file. Of course this is a race;
* we'd have to use fcntl() locks on the pid file to
* avoid that. But we want to check for the pid file
@@ -348,6 +346,15 @@ process_config_first_time_only (BusContext *context,
if (bus_config_parser_get_type (parser) != NULL && context->type == NULL)
goto oom;
+ /* activation manager may be NULL */
+ if (activation_manager && _dbus_string_get_length (activation_manager) > 0)
+ {
+ if (!_dbus_string_copy_data (activation_manager, &context->activation_manager))
+ goto oom;
+ }
+ else
+ context->activation_manager = NULL;
+
user = bus_config_parser_get_user (parser);
if (user != NULL)
{
@@ -678,7 +685,7 @@ bus_context_new (const DBusString *config_file,
DBusPipe *print_addr_pipe,
DBusPipe *print_pid_pipe,
const DBusString *address,
- dbus_bool_t systemd_activation,
+ const DBusString *activation_manager,
DBusError *error)
{
DBusString log_prefix;
@@ -733,7 +740,7 @@ 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_manager, error))
{
_DBUS_ASSERT_ERROR_IS_SET (error);
goto failed;
@@ -1111,10 +1118,10 @@ bus_context_get_servicehelper (BusContext *context)
return context->servicehelper;
}
-dbus_bool_t
-bus_context_get_systemd_activation (BusContext *context)
+const char*
+bus_context_get_activation_manager (BusContext *context)
{
- return context->systemd_activation;
+ return context->activation_manager;
}
BusRegistry*
diff --git a/bus/bus.h b/bus/bus.h
index ebef17c..15c978d 100644
--- a/bus/bus.h
+++ b/bus/bus.h
@@ -76,7 +76,7 @@ BusContext* bus_context_new (const DBusStri
DBusPipe *print_addr_pipe,
DBusPipe *print_pid_pipe,
const DBusString *address,
- dbus_bool_t systemd_activation,
+ const DBusString *activation_manager,
DBusError *error);
dbus_bool_t bus_context_reload_config (BusContext *context,
DBusError *error);
@@ -88,7 +88,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);
+const char* bus_context_get_activation_manager (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/dbus.service.in b/bus/dbus.service.in
index 399306f..6fc7427 100644
--- a/bus/dbus.service.in
+++ b/bus/dbus.service.in
@@ -6,5 +6,5 @@ After=syslog.target
[Service]
ExecStartPre=@EXPANDED_BINDIR@/dbus-uuidgen --ensure
ExecStartPre=-/bin/rm -f @DBUS_SYSTEM_PID_FILE@
-ExecStart=@EXPANDED_BINDIR@/dbus-daemon --system --address=systemd: --nofork --systemd-activation
+ExecStart=@EXPANDED_BINDIR@/dbus-daemon --system --address=systemd: --nofork --activation-manager=org.freedesktop.systemd1
ExecReload=@EXPANDED_BINDIR@/dbus-send --print-reply --system --type=method_call --dest=org.freedesktop.DBus / org.freedesktop.DBus.ReloadConfig
diff --git a/bus/main.c b/bus/main.c
index 53038db..4a238f6 100644
--- a/bus/main.c
+++ b/bus/main.c
@@ -75,7 +75,7 @@ signal_handler (int sig)
static void
usage (void)
{
- fprintf (stderr, DBUS_DAEMON_NAME " [--version] [--session] [--system] [--config-file=FILE] [--print-address[=DESCRIPTOR]] [--print-pid[=DESCRIPTOR]] [--fork] [--nofork] [--introspect] [--address=ADDRESS] [--systemd-activation]\n");
+ fprintf (stderr, DBUS_DAEMON_NAME " [--version] [--session] [--system] [--config-file=FILE] [--print-address[=DESCRIPTOR]] [--print-pid[=DESCRIPTOR]] [--fork] [--nofork] [--introspect] [--address=ADDRESS] [--activation-manager=NAME]\n");
exit (1);
}
@@ -163,6 +163,18 @@ check_two_pid_descriptors (const DBusString *pid_fd,
}
}
+static void
+check_two_activation_managers (const DBusString *activation_manager,
+ const char *extra_arg)
+{
+ if (_dbus_string_get_length (activation_manager) > 0)
+ {
+ fprintf (stderr, "--%s specified but activation manager %s already requested\n",
+ extra_arg, _dbus_string_get_const_data (activation_manager));
+ exit (1);
+ }
+}
+
static dbus_bool_t
handle_reload_watch (DBusWatch *watch,
unsigned int flags,
@@ -266,6 +278,7 @@ main (int argc, char **argv)
DBusString address;
DBusString addr_fd;
DBusString pid_fd;
+ DBusString activation_manager;
const char *prev_arg;
DBusPipe print_addr_pipe;
DBusPipe print_pid_pipe;
@@ -274,7 +287,6 @@ main (int argc, char **argv)
dbus_bool_t print_pid;
dbus_bool_t is_session_bus;
int force_fork;
- dbus_bool_t systemd_activation;
if (!_dbus_string_init (&config_file))
return 1;
@@ -288,11 +300,13 @@ main (int argc, char **argv)
if (!_dbus_string_init (&pid_fd))
return 1;
+ if (!_dbus_string_init (&activation_manager))
+ return 1;
+
print_address = FALSE;
print_pid = FALSE;
is_session_bus = FALSE;
force_fork = FORK_FOLLOW_CONFIG_FILE;
- systemd_activation = FALSE;
prev_arg = NULL;
i = 1;
@@ -312,8 +326,6 @@ main (int argc, char **argv)
force_fork = FORK_NEVER;
else if (strcmp (arg, "--fork") == 0)
force_fork = FORK_ALWAYS;
- else if (strcmp (arg, "--systemd-activation") == 0)
- systemd_activation = TRUE;
else if (strcmp (arg, "--system") == 0)
{
check_two_config_files (&config_file, "system");
@@ -424,6 +436,28 @@ main (int argc, char **argv)
}
else if (strcmp (arg, "--print-pid") == 0)
print_pid = TRUE; /* and we'll get the next arg if appropriate */
+ else if (strstr (arg, "--activation-manager=") == arg)
+ {
+ const char *manager;
+
+ check_two_activation_managers (&activation_manager, "activation-manager");
+
+ manager = strchr (arg, '=');
+ ++manager;
+
+ if (!_dbus_string_append (&activation_manager, manager))
+ exit (1);
+ }
+ else if (prev_arg &&
+ strcmp (prev_arg, "--activation-manager") == 0)
+ {
+ check_two_activation_managers (&activation_manager, "activation-manager");
+
+ if (!_dbus_string_append (&activation_manager, arg))
+ exit (1);
+ }
+ else if (strcmp (arg, "--activation-manager") == 0)
+ ; /* wait for next arg */
else
usage ();
@@ -492,9 +526,10 @@ 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_manager,
&error);
_dbus_string_free (&config_file);
+ _dbus_string_free (&activation_manager);
if (context == NULL)
{
_dbus_warn ("Failed to start message bus: %s\n",
--
1.7.1
More information about the dbus
mailing list