[systemd-commits] 3 commits - fixme src/dbus-automount.c src/dbus-automount.h src/dbus.c src/dbus-device.c src/dbus-device.h src/dbus.h src/dbus-job.c src/dbus-manager.c src/dbus-mount.c src/dbus-mount.h src/dbus-path.c src/dbus-path.h src/dbus-service.c src/dbus-service.h src/dbus-snapshot.c src/dbus-snapshot.h src/dbus-socket.c src/dbus-socket.h src/dbus-swap.c src/dbus-swap.h src/dbus-target.c src/dbus-target.h src/dbus-timer.c src/dbus-timer.h src/dbus-unit.c src/install.c src/load-fragment.c src/main.c src/manager.c src/manager.h src/mount.c src/path-lookup.c src/service.c src/service.h src/socket.c src/socket.h src/swap.c src/systemctl.c src/test-engine.c src/unit.c src/unit.h
Lennart Poettering
lennart at kemper.freedesktop.org
Fri Jun 18 19:25:55 PDT 2010
fixme | 8 -
src/dbus-automount.c | 4
src/dbus-automount.h | 2
src/dbus-device.c | 4
src/dbus-device.h | 2
src/dbus-job.c | 17 +-
src/dbus-manager.c | 42 ++---
src/dbus-mount.c | 4
src/dbus-mount.h | 2
src/dbus-path.c | 4
src/dbus-path.h | 2
src/dbus-service.c | 4
src/dbus-service.h | 2
src/dbus-snapshot.c | 6
src/dbus-snapshot.h | 2
src/dbus-socket.c | 4
src/dbus-socket.h | 2
src/dbus-swap.c | 4
src/dbus-swap.h | 2
src/dbus-target.c | 4
src/dbus-target.h | 2
src/dbus-timer.c | 4
src/dbus-timer.h | 2
src/dbus-unit.c | 24 +--
src/dbus.c | 371 ++++++++++++++++++++++++++++++++++++---------------
src/dbus.h | 11 -
src/install.c | 2
src/load-fragment.c | 1
src/main.c | 16 +-
src/manager.c | 24 +--
src/manager.h | 11 -
src/mount.c | 12 -
src/path-lookup.c | 2
src/service.c | 68 +++++++--
src/service.h | 3
src/socket.c | 73 ++++++++--
src/socket.h | 5
src/swap.c | 6
src/systemctl.c | 9 -
src/test-engine.c | 2
src/unit.c | 5
src/unit.h | 2
42 files changed, 519 insertions(+), 257 deletions(-)
New commits:
commit 6cf6bbc2682c6df010d64ea7e49d93affa7282cd
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Jun 19 04:25:28 2010 +0200
socket: enforce limit on number of concurrent connections
diff --git a/fixme b/fixme
index 15e3ef6..a366ea8 100644
--- a/fixme
+++ b/fixme
@@ -1,7 +1,5 @@
* calendar time support in timer
-* enforce max number of concurrent connection limit in sockets.
-
* complete dbus exposure
* make conf parser work more like .desktop parsers
@@ -51,11 +49,13 @@
* follow property change dbus spec
+* make systemd bus activatable (?)
+
* pam module
* selinux
-* make systemd bus activatable
+External:
* systemd-sysvinit as package
@@ -63,8 +63,6 @@
if [ $PPID -ne 1 && mountpoint /cgroup/systemd ] ; then echo "You suck!" ; fi
-* remove MANAGER_SYSTEM
-
Regularly:
* look for close() vs. close_nointr() vs. close_nointr_nofail()
diff --git a/src/load-fragment.c b/src/load-fragment.c
index d6a35f7..b7bb4d7 100644
--- a/src/load-fragment.c
+++ b/src/load-fragment.c
@@ -1516,6 +1516,7 @@ static int load_from_path(Unit *u, const char *path) {
{ "SocketMode", config_parse_mode, &u->socket.socket_mode, "Socket" },
{ "KillMode", config_parse_kill_mode, &u->socket.kill_mode, "Socket" },
{ "Accept", config_parse_bool, &u->socket.accept, "Socket" },
+ { "MaxConnections", config_parse_unsigned, &u->socket.max_connections, "Socket" },
EXEC_CONTEXT_CONFIG_ITEMS(u->socket.exec_context, "Socket"),
{ "What", config_parse_string, &u->mount.parameters_fragment.what, "Mount" },
diff --git a/src/mount.c b/src/mount.c
index c95581f..5c16f86 100644
--- a/src/mount.c
+++ b/src/mount.c
@@ -645,7 +645,7 @@ static void mount_enter_unmounting(Mount *m, bool success) {
return;
fail:
- log_warning("%s failed to run umount exectuable: %s", UNIT(m)->meta.id, strerror(-r));
+ log_warning("%s failed to run 'umount' task: %s", UNIT(m)->meta.id, strerror(-r));
mount_enter_mounted(m, false);
}
@@ -688,7 +688,7 @@ static void mount_enter_mounting(Mount *m) {
return;
fail:
- log_warning("%s failed to run mount exectuable: %s", UNIT(m)->meta.id, strerror(-r));
+ log_warning("%s failed to run 'mount' task: %s", UNIT(m)->meta.id, strerror(-r));
mount_enter_dead(m, false);
}
diff --git a/src/service.c b/src/service.c
index b8687b7..4375cb5 100644
--- a/src/service.c
+++ b/src/service.c
@@ -157,6 +157,16 @@ static void service_close_socket_fd(Service *s) {
s->socket_fd = -1;
}
+static void service_connection_unref(Service *s) {
+ assert(s);
+
+ if (!s->socket)
+ return;
+
+ socket_connection_unref(s->socket);
+ s->socket = NULL;
+}
+
static void service_done(Unit *u) {
Service *s = SERVICE(u);
@@ -190,6 +200,7 @@ static void service_done(Unit *u) {
}
service_close_socket_fd(s);
+ service_connection_unref(s);
unit_unwatch_timer(u, &s->timer_watch);
}
@@ -800,6 +811,11 @@ static int service_verify(Service *s) {
return -EINVAL;
}
+ if (s->exec_command[SERVICE_EXEC_START]->command_next) {
+ log_error("%s has more than one ExecStart setting. Refusing.", UNIT(s)->meta.id);
+ return -EINVAL;
+ }
+
if (s->type == SERVICE_DBUS && !s->bus_name) {
log_error("%s is of type D-Bus but no D-Bus service name has been specified. Refusing.", UNIT(s)->meta.id);
return -EINVAL;
@@ -993,6 +1009,9 @@ static int service_get_sockets(Service *s, Set **_set) {
assert(s);
assert(_set);
+ if (s->socket_fd >= 0)
+ return 0;
+
/* Collects all Socket objects that belong to this
* service. Note that a service might have multiple sockets
* via multiple names. */
@@ -1038,6 +1057,9 @@ static int service_notify_sockets_dead(Service *s) {
assert(s);
+ if (s->socket_fd >= 0)
+ return 0;
+
/* Notifies all our sockets when we die */
if ((r = service_get_sockets(s, &set)) < 0)
return r;
@@ -1107,8 +1129,19 @@ static void service_set_state(Service *s, ServiceState state) {
if (state != SERVICE_START_PRE &&
state != SERVICE_START &&
- !(state == SERVICE_DEAD && UNIT(s)->meta.job))
+ state != SERVICE_START_POST &&
+ state != SERVICE_RUNNING &&
+ state != SERVICE_RELOAD &&
+ state != SERVICE_STOP &&
+ state != SERVICE_STOP_SIGTERM &&
+ state != SERVICE_STOP_SIGKILL &&
+ state != SERVICE_STOP_POST &&
+ state != SERVICE_FINAL_SIGTERM &&
+ state != SERVICE_FINAL_SIGKILL &&
+ !(state == SERVICE_DEAD && UNIT(s)->meta.job)) {
service_close_socket_fd(s);
+ service_connection_unref(s);
+ }
if (old_state != state)
log_debug("%s changed %s -> %s", UNIT(s)->meta.id, service_state_to_string(old_state), service_state_to_string(state));
@@ -1194,6 +1227,9 @@ static int service_collect_fds(Service *s, int **fds, unsigned *n_fds) {
assert(fds);
assert(n_fds);
+ if (s->socket_fd >= 0)
+ return 0;
+
if ((r = service_get_sockets(s, &set)) < 0)
return r;
@@ -1255,7 +1291,7 @@ static int service_spawn(
pid_t pid;
int r;
- int *fds = NULL;
+ int *fds = NULL, *fdsbuf = NULL;
unsigned n_fds = 0;
char **argv = NULL, **env = NULL;
@@ -1263,12 +1299,20 @@ static int service_spawn(
assert(c);
assert(_pid);
- if (pass_fds) {
+ if (pass_fds ||
+ s->exec_context.std_input == EXEC_INPUT_SOCKET ||
+ s->exec_context.std_output == EXEC_OUTPUT_SOCKET ||
+ s->exec_context.std_error == EXEC_OUTPUT_SOCKET) {
+
if (s->socket_fd >= 0) {
fds = &s->socket_fd;
n_fds = 1;
- } else if ((r = service_collect_fds(s, &fds, &n_fds)) < 0)
- goto fail;
+ } else {
+ if ((r = service_collect_fds(s, &fdsbuf, &n_fds)) < 0)
+ goto fail;
+
+ fds = fdsbuf;
+ }
}
if (timeout && s->timeout_usec) {
@@ -1321,12 +1365,8 @@ static int service_spawn(
if (r < 0)
goto fail;
- if (fds) {
- if (s->socket_fd >= 0)
- service_close_socket_fd(s);
- else
- free(fds);
- }
+ if (fdsbuf)
+ free(fdsbuf);
if ((r = unit_watch_pid(UNIT(s), pid)) < 0)
/* FIXME: we need to do something here */
@@ -1756,7 +1796,7 @@ static void service_run_next(Service *s, bool success) {
return;
fail:
- log_warning("%s failed to run spawn next task: %s", UNIT(s)->meta.id, strerror(-r));
+ log_warning("%s failed to run next task: %s", UNIT(s)->meta.id, strerror(-r));
if (s->state == SERVICE_START_PRE)
service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
@@ -2524,7 +2564,7 @@ static void service_bus_query_pid_done(
service_set_main_pid(s, pid);
}
-int service_set_socket_fd(Service *s, int fd) {
+int service_set_socket_fd(Service *s, int fd, Socket *sock) {
assert(s);
assert(fd >= 0);
@@ -2543,6 +2583,8 @@ int service_set_socket_fd(Service *s, int fd) {
s->socket_fd = fd;
s->got_socket_fd = true;
+ s->socket = sock;
+
return 0;
}
diff --git a/src/service.h b/src/service.h
index 7b85771..6c1612d 100644
--- a/src/service.h
+++ b/src/service.h
@@ -137,13 +137,14 @@ struct Service {
RateLimit ratelimit;
int socket_fd;
+ struct Socket *socket;
Watch timer_watch;
};
extern const UnitVTable service_vtable;
-int service_set_socket_fd(Service *s, int fd);
+int service_set_socket_fd(Service *s, int fd, struct Socket *socket);
const char* service_state_to_string(ServiceState i);
ServiceState service_state_from_string(const char *s);
diff --git a/src/socket.c b/src/socket.c
index 874cc91..fdb6f66 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -63,6 +63,8 @@ static void socket_init(Unit *u) {
s->directory_mode = 0755;
s->socket_mode = 0666;
+ s->max_connections = 64;
+
exec_context_init(&s->exec_context);
s->control_command_id = _SOCKET_EXEC_COMMAND_INVALID;
@@ -81,6 +83,7 @@ static void socket_unwatch_control_pid(Socket *s) {
static void socket_done(Unit *u) {
Socket *s = SOCKET(u);
SocketPort *p;
+ Meta *i;
assert(s);
@@ -108,6 +111,14 @@ static void socket_done(Unit *u) {
s->bind_to_device = NULL;
unit_unwatch_timer(u, &s->timer_watch);
+
+ /* Make sure no service instance refers to us anymore. */
+ LIST_FOREACH(units_per_type, i, u->meta.manager->units_per_type[UNIT_SERVICE]) {
+ Service *service = (Service *) i;
+
+ if (service->socket == s)
+ service->socket = NULL;
+ }
}
static bool have_non_accept_socket(Socket *s) {
@@ -141,6 +152,11 @@ static int socket_verify(Socket *s) {
return -EINVAL;
}
+ if (s->accept && s->max_connections <= 0) {
+ log_error("%s's MaxConnection setting too small. Refusing.", UNIT(s)->meta.id);
+ return -EINVAL;
+ }
+
return 0;
}
@@ -307,8 +323,12 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
if (s->accept)
fprintf(f,
- "%sAccepted: %u\n",
- prefix, s->n_accepted);
+ "%sAccepted: %u\n"
+ "%sNConnections: %u\n"
+ "%sMaxConnections: %u\n",
+ prefix, s->n_accepted,
+ prefix, s->n_connections,
+ prefix, s->max_connections);
LIST_FOREACH(port, p, s->ports) {
@@ -734,7 +754,7 @@ static void socket_enter_stop_post(Socket *s, bool success) {
return;
fail:
- log_warning("%s failed to run stop-post executable: %s", s->meta.id, strerror(-r));
+ log_warning("%s failed to run 'stop-post' task: %s", s->meta.id, strerror(-r));
socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
}
@@ -809,7 +829,7 @@ static void socket_enter_stop_pre(Socket *s, bool success) {
return;
fail:
- log_warning("%s failed to run stop-pre executable: %s", s->meta.id, strerror(-r));
+ log_warning("%s failed to run 'stop-pre' task: %s", s->meta.id, strerror(-r));
socket_enter_stop_post(s, false);
}
@@ -844,7 +864,7 @@ static void socket_enter_start_post(Socket *s) {
if ((s->control_command = s->exec_command[SOCKET_EXEC_START_POST])) {
if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0) {
- log_warning("%s failed to run start-post executable: %s", s->meta.id, strerror(-r));
+ log_warning("%s failed to run 'start-post' task: %s", s->meta.id, strerror(-r));
goto fail;
}
@@ -877,7 +897,7 @@ static void socket_enter_start_pre(Socket *s) {
return;
fail:
- log_warning("%s failed to run start-pre exectuable: %s", s->meta.id, strerror(-r));
+ log_warning("%s failed to run 'start-pre' task: %s", s->meta.id, strerror(-r));
socket_enter_dead(s, false);
}
@@ -895,6 +915,12 @@ static void socket_enter_running(Socket *s, int cfd) {
Unit *u;
char *prefix, *instance, *name;
+ if (s->n_connections >= s->max_connections) {
+ log_warning("Too many incoming connections (%u)", s->n_connections);
+ close_nointr_nofail(cfd);
+ return;
+ }
+
if ((r = instance_from_socket(cfd, s->n_accepted++, &instance)) < 0)
goto fail;
@@ -919,11 +945,13 @@ static void socket_enter_running(Socket *s, int cfd) {
if (r < 0)
goto fail;
- if ((r = service_set_socket_fd(SERVICE(u), cfd)) < 0)
+ if ((r = service_set_socket_fd(SERVICE(u), cfd, s)) < 0)
goto fail;
cfd = -1;
+ s->n_connections ++;
+
if ((r = manager_add_job(u->meta.manager, JOB_START, u, JOB_REPLACE, true, NULL)) < 0)
goto fail;
}
@@ -958,7 +986,7 @@ static void socket_run_next(Socket *s, bool success) {
return;
fail:
- log_warning("%s failed to run spawn next executable: %s", s->meta.id, strerror(-r));
+ log_warning("%s failed to run next task: %s", s->meta.id, strerror(-r));
if (s->state == SOCKET_START_POST)
socket_enter_stop_pre(s, false);
@@ -1181,6 +1209,14 @@ static const char *socket_sub_state_to_string(Unit *u) {
return socket_state_to_string(SOCKET(u)->state);
}
+static bool socket_check_gc(Unit *u) {
+ Socket *s = SOCKET(u);
+
+ assert(u);
+
+ return s->n_connections > 0;
+}
+
static void socket_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {
Socket *s = SOCKET(u);
int cfd = -1;
@@ -1375,7 +1411,10 @@ int socket_collect_fds(Socket *s, int **fds, unsigned *n_fds) {
void socket_notify_service_dead(Socket *s) {
assert(s);
- /* The service is dead. Dang. */
+ /* The service is dead. Dang!
+ *
+ * This is strictly for one-instance-for-all-connections
+ * services. */
if (s->state == SOCKET_RUNNING) {
log_debug("%s got notified about service death.", s->meta.id);
@@ -1383,6 +1422,20 @@ void socket_notify_service_dead(Socket *s) {
}
}
+void socket_connection_unref(Socket *s) {
+ assert(s);
+
+ /* The service is dead. Yay!
+ *
+ * This is strictly for one-onstance-per-connection
+ * services. */
+
+ assert(s->n_connections > 0);
+ s->n_connections--;
+
+ log_debug("%s: One connection closed, %u left.", s->meta.id, s->n_connections);
+}
+
static const char* const socket_state_table[_SOCKET_STATE_MAX] = {
[SOCKET_DEAD] = "dead",
[SOCKET_START_PRE] = "start-pre",
@@ -1429,6 +1482,8 @@ const UnitVTable socket_vtable = {
.active_state = socket_active_state,
.sub_state_to_string = socket_sub_state_to_string,
+ .check_gc = socket_check_gc,
+
.fd_event = socket_fd_event,
.sigchld_event = socket_sigchld_event,
.timer_event = socket_timer_event,
diff --git a/src/socket.h b/src/socket.h
index 5a2cd06..31b3870 100644
--- a/src/socket.h
+++ b/src/socket.h
@@ -103,6 +103,8 @@ struct Socket {
bool accept;
unsigned n_accepted;
+ unsigned n_connections;
+ unsigned max_connections;
bool failure;
Watch timer_watch;
@@ -118,6 +120,9 @@ void socket_notify_service_dead(Socket *s);
* any of the sockets of this socket */
int socket_add_one_mount_link(Socket *s, Mount *m);
+/* Called from the service code when a per-connection service ended */
+void socket_connection_unref(Socket *s);
+
extern const UnitVTable socket_vtable;
const char* socket_state_to_string(SocketState i);
commit a3d4e06dfa234bf2a9398c8e534b705b68aa50a1
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Jun 19 03:15:59 2010 +0200
manager: get rid of destinction between running_as=system and running_as=init, as there is little value in it and we cannot really test this
diff --git a/src/dbus-manager.c b/src/dbus-manager.c
index 7818257..b3e42fc 100644
--- a/src/dbus-manager.c
+++ b/src/dbus-manager.c
@@ -608,7 +608,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Exit")) {
- if (m->running_as == MANAGER_INIT)
+ if (m->running_as == MANAGER_SYSTEM)
return bus_send_error_reply(m, connection, message, NULL, -ENOTSUP);
if (!(reply = dbus_message_new_method_return(message)))
diff --git a/src/dbus.c b/src/dbus.c
index a34c7dc..74b1c37 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -761,7 +761,7 @@ static int bus_init_system(Manager *m) {
if (m->system_bus)
return 0;
- if (m->running_as != MANAGER_SESSION && m->api_bus)
+ if (m->running_as == MANAGER_SYSTEM && m->api_bus)
m->system_bus = m->api_bus;
else {
if (!(m->system_bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error))) {
@@ -819,7 +819,7 @@ static int bus_init_api(Manager *m) {
if (m->api_bus)
return 0;
- if (m->running_as != MANAGER_SESSION && m->system_bus)
+ if (m->running_as == MANAGER_SYSTEM && m->system_bus)
m->api_bus = m->system_bus;
else {
if (!(m->api_bus = dbus_bus_get_private(m->running_as == MANAGER_SESSION ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, &error))) {
@@ -914,7 +914,7 @@ static int bus_init_private(Manager *m) {
return 0;
/* We want the private bus only when running as init */
- if (m->running_as != MANAGER_INIT)
+ if (m->running_as != MANAGER_SYSTEM)
return 0;
if (!(m->private_bus = dbus_server_listen("unix:abstract=/org/freedesktop/systemd1/private", &error))) {
@@ -1348,11 +1348,11 @@ int bus_broadcast(Manager *m, DBusMessage *message) {
assert(message);
SET_FOREACH(c, m->bus_connections_for_dispatch, i)
- if (c != m->system_bus || m->running_as != MANAGER_SESSION)
+ if (c != m->system_bus || m->running_as == MANAGER_SYSTEM)
oom = !dbus_connection_send(c, message, NULL);
SET_FOREACH(c, m->bus_connections, i)
- if (c != m->system_bus || m->running_as != MANAGER_SESSION)
+ if (c != m->system_bus || m->running_as == MANAGER_SYSTEM)
oom = !dbus_connection_send(c, message, NULL);
return oom ? -ENOMEM : 0;
diff --git a/src/install.c b/src/install.c
index e30f623..e59e108 100644
--- a/src/install.c
+++ b/src/install.c
@@ -535,7 +535,7 @@ int main(int argc, char *argv[]) {
goto finish;
}
- if ((r = lookup_paths_init(&paths, arg_where == WHERE_SYSTEM ? MANAGER_INIT : MANAGER_SESSION)) < 0) {
+ if ((r = lookup_paths_init(&paths, arg_where == WHERE_SYSTEM ? MANAGER_SYSTEM : MANAGER_SESSION)) < 0) {
log_error("Failed to determine lookup paths: %s", strerror(-r));
goto finish;
}
diff --git a/src/main.c b/src/main.c
index 21b4174..f00d43a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -526,7 +526,7 @@ static int parse_argv(int argc, char *argv[]) {
* ignore and unconditionally read from
* /proc/cmdline. However, we need to ignore those arguments
* here. */
- if (running_as != MANAGER_INIT && optind < argc) {
+ if (running_as != MANAGER_SYSTEM && optind < argc) {
log_error("Excess arguments.");
return -EINVAL;
}
@@ -540,7 +540,7 @@ static int help(void) {
"Starts up and maintains the system or a session.\n\n"
" -h --help Show this help\n"
" --unit=UNIT Set default unit\n"
- " --running-as=AS Set running as (init, system, session)\n"
+ " --running-as=AS Set running as (system, session)\n"
" --test Determine startup sequence, dump it and exit\n"
" --dump-configuration-items Dump understood unit configuration items\n"
" --confirm-spawn Ask for confirmation when spawning processes\n"
@@ -631,7 +631,7 @@ int main(int argc, char *argv[]) {
log_set_max_level(LOG_DEBUG);
if (getpid() == 1) {
- running_as = MANAGER_INIT;
+ running_as = MANAGER_SYSTEM;
log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
} else {
running_as = MANAGER_SESSION;
@@ -653,7 +653,7 @@ int main(int argc, char *argv[]) {
/* If we are init, we can block sigkill. Yay. */
ignore_signals(SIGNALS_IGNORE, -1);
- if (running_as != MANAGER_SESSION)
+ if (running_as == MANAGER_SYSTEM)
if (parse_proc_cmdline() < 0)
goto finish;
@@ -690,12 +690,12 @@ int main(int argc, char *argv[]) {
/* Set up PATH unless it is already set */
setenv("PATH",
"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
- running_as == MANAGER_INIT);
+ running_as == MANAGER_SYSTEM);
/* Move out of the way, so that we won't block unmounts */
assert_se(chdir("/") == 0);
- if (running_as != MANAGER_SESSION) {
+ if (running_as == MANAGER_SYSTEM) {
/* Become a session leader if we aren't one yet. */
setsid();
@@ -708,7 +708,7 @@ int main(int argc, char *argv[]) {
/* Reset the console, but only if this is really init and we
* are freshly booted */
- if (running_as != MANAGER_SESSION && action == ACTION_RUN) {
+ if (running_as == MANAGER_SYSTEM && action == ACTION_RUN) {
console_setup(getpid() == 1 && !serialization);
make_null_stdio();
}
@@ -723,7 +723,7 @@ int main(int argc, char *argv[]) {
log_debug("systemd running in %s mode.", manager_running_as_to_string(running_as));
- if (running_as == MANAGER_INIT) {
+ if (running_as == MANAGER_SYSTEM) {
kmod_setup();
hostname_setup();
loopback_setup();
diff --git a/src/manager.c b/src/manager.c
index 456241f..e211eca 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -177,7 +177,7 @@ static int manager_setup_signals(Manager *m) {
if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->signal_watch.fd, &ev) < 0)
return -errno;
- if (m->running_as == MANAGER_INIT)
+ if (m->running_as == MANAGER_SYSTEM)
return enable_special_signals(m);
return 0;
@@ -1780,7 +1780,7 @@ static int manager_process_signal_fd(Manager *m) {
break;
case SIGTERM:
- if (m->running_as == MANAGER_INIT) {
+ if (m->running_as == MANAGER_SYSTEM) {
/* This is for compatibility with the
* original sysvinit */
m->exit_code = MANAGER_REEXECUTE;
@@ -1790,7 +1790,7 @@ static int manager_process_signal_fd(Manager *m) {
/* Fall through */
case SIGINT:
- if (m->running_as == MANAGER_INIT) {
+ if (m->running_as == MANAGER_SYSTEM) {
manager_start_target(m, SPECIAL_CTRL_ALT_DEL_TARGET, JOB_REPLACE);
break;
}
@@ -1804,14 +1804,14 @@ static int manager_process_signal_fd(Manager *m) {
break;
case SIGWINCH:
- if (m->running_as == MANAGER_INIT)
+ if (m->running_as == MANAGER_SYSTEM)
manager_start_target(m, SPECIAL_KBREQUEST_TARGET, JOB_REPLACE);
/* This is a nop on non-init */
break;
case SIGPWR:
- if (m->running_as == MANAGER_INIT)
+ if (m->running_as == MANAGER_SYSTEM)
manager_start_target(m, SPECIAL_SIGPWR_TARGET, JOB_REPLACE);
/* This is a nop on non-init */
@@ -2105,7 +2105,7 @@ void manager_write_utmp_reboot(Manager *m) {
if (m->utmp_reboot_written)
return;
- if (m->running_as != MANAGER_INIT)
+ if (m->running_as != MANAGER_SYSTEM)
return;
if (!manager_utmp_good(m))
@@ -2131,7 +2131,7 @@ void manager_write_utmp_runlevel(Manager *m, Unit *u) {
if (u->meta.type != UNIT_TARGET)
return;
- if (m->running_as != MANAGER_INIT)
+ if (m->running_as != MANAGER_SYSTEM)
return;
if (!manager_utmp_good(m))
@@ -2337,7 +2337,6 @@ finish:
}
static const char* const manager_running_as_table[_MANAGER_RUNNING_AS_MAX] = {
- [MANAGER_INIT] = "init",
[MANAGER_SYSTEM] = "system",
[MANAGER_SESSION] = "session"
};
diff --git a/src/manager.h b/src/manager.h
index 2a04bc7..6e74773 100644
--- a/src/manager.h
+++ b/src/manager.h
@@ -46,9 +46,8 @@ typedef enum ManagerExitCode {
} ManagerExitCode;
typedef enum ManagerRunningAs {
- MANAGER_INIT, /* root and pid=1 */
- MANAGER_SYSTEM, /* root and pid!=1 */
- MANAGER_SESSION, /* non-root, for a session */
+ MANAGER_SYSTEM,
+ MANAGER_SESSION,
_MANAGER_RUNNING_AS_MAX,
_MANAGER_RUNNING_AS_INVALID = -1
} ManagerRunningAs;
diff --git a/src/mount.c b/src/mount.c
index 94f1929..c95581f 100644
--- a/src/mount.c
+++ b/src/mount.c
@@ -254,7 +254,7 @@ static int mount_add_target_links(Mount *m) {
if ((r = manager_load_unit(UNIT(m)->meta.manager, target, NULL, &tu)) < 0)
return r;
- if (automount && m->meta.manager->running_as != MANAGER_SESSION) {
+ if (automount && m->meta.manager->running_as == MANAGER_SYSTEM) {
Unit *am;
if ((r = unit_load_related_unit(UNIT(m), ".automount", &am)) < 0)
@@ -268,7 +268,7 @@ static int mount_add_target_links(Mount *m) {
} else {
if (!noauto && handle)
- if (user || m->meta.manager->running_as != MANAGER_SESSION)
+ if (user || m->meta.manager->running_as == MANAGER_SYSTEM)
if ((r = unit_add_dependency(tu, UNIT_WANTS, UNIT(m), true)) < 0)
return r;
@@ -341,9 +341,7 @@ static int mount_load(Unit *u) {
what = m->parameters_proc_self_mountinfo.what;
if (what)
- if ((r = unit_add_node_link(u, what,
- (u->meta.manager->running_as == MANAGER_INIT ||
- u->meta.manager->running_as == MANAGER_SYSTEM))) < 0)
+ if ((r = unit_add_node_link(u, what, u->meta.manager->running_as == MANAGER_SYSTEM)) < 0)
return r;
if ((r = mount_add_mount_links(m)) < 0)
diff --git a/src/path-lookup.c b/src/path-lookup.c
index 093e04d..4160d55 100644
--- a/src/path-lookup.c
+++ b/src/path-lookup.c
@@ -187,7 +187,7 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as) {
return -ENOMEM;
}
- if (running_as == MANAGER_INIT) {
+ if (running_as == MANAGER_SYSTEM) {
/* /etc/init.d/ compatibility does not matter to users */
if ((e = getenv("SYSTEMD_SYSVINIT_PATH")))
diff --git a/src/swap.c b/src/swap.c
index 5b3073b..501a1d9 100644
--- a/src/swap.c
+++ b/src/swap.c
@@ -116,7 +116,7 @@ static int swap_add_target_links(Swap *s) {
if ((r = manager_load_unit(s->meta.manager, SPECIAL_SWAP_TARGET, NULL, &tu)) < 0)
return r;
- if (!p->noauto && p->handle && s->meta.manager->running_as != MANAGER_SESSION)
+ if (!p->noauto && p->handle && s->meta.manager->running_as == MANAGER_SYSTEM)
if ((r = unit_add_dependency(tu, UNIT_WANTS, UNIT(s), true)) < 0)
return r;
@@ -180,9 +180,7 @@ static int swap_load(Unit *u) {
if ((r = unit_set_description(u, s->what)) < 0)
return r;
- if ((r = unit_add_node_link(u, s->what,
- (u->meta.manager->running_as == MANAGER_INIT ||
- u->meta.manager->running_as == MANAGER_SYSTEM))) < 0)
+ if ((r = unit_add_node_link(u, s->what, u->meta.manager->running_as == MANAGER_SYSTEM)) < 0)
return r;
if ((r = swap_add_mount_links(s)) < 0)
diff --git a/src/test-engine.c b/src/test-engine.c
index eb17f58..60c6aa2 100644
--- a/src/test-engine.c
+++ b/src/test-engine.c
@@ -33,7 +33,7 @@ int main(int argc, char *argv[]) {
assert_se(set_unit_path("test2") >= 0);
- assert_se(manager_new(MANAGER_INIT, false, &m) >= 0);
+ assert_se(manager_new(MANAGER_SYSTEM, false, &m) >= 0);
printf("Load1:\n");
assert_se(manager_load_unit(m, "a.service", NULL, &a) >= 0);
diff --git a/src/unit.c b/src/unit.c
index c12c2a7..c546035 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -542,7 +542,7 @@ int unit_add_exec_dependencies(Unit *u, ExecContext *c) {
if ((r = unit_add_dependency_by_name(u, UNIT_AFTER, SPECIAL_LOGGER_SOCKET, NULL, true)) < 0)
return r;
- if (u->meta.manager->running_as != MANAGER_SESSION)
+ if (u->meta.manager->running_as == MANAGER_SYSTEM)
if ((r = unit_add_dependency_by_name(u, UNIT_REQUIRES, SPECIAL_LOGGER_SOCKET, NULL, true)) < 0)
return r;
commit 5e8d1c9a9f15b7453474dc4879bdb4021c3f50a1
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Jun 19 03:04:04 2010 +0200
dbus: to make sure that systemd stays controllable during early bootup, register our services on our own micro usb server in addition to the bus
diff --git a/fixme b/fixme
index b5b8e63..15e3ef6 100644
--- a/fixme
+++ b/fixme
@@ -59,12 +59,12 @@
* systemd-sysvinit as package
-* abstract namespace dbus socket
-
* patch /etc/init.d/functions with:
if [ $PPID -ne 1 && mountpoint /cgroup/systemd ] ; then echo "You suck!" ; fi
+* remove MANAGER_SYSTEM
+
Regularly:
* look for close() vs. close_nointr() vs. close_nointr_nofail()
diff --git a/src/dbus-automount.c b/src/dbus-automount.c
index 285f666..61732f9 100644
--- a/src/dbus-automount.c
+++ b/src/dbus-automount.c
@@ -38,12 +38,12 @@
const char bus_automount_interface[] = BUS_AUTOMOUNT_INTERFACE;
-DBusHandlerResult bus_automount_message_handler(Unit *u, DBusMessage *message) {
+DBusHandlerResult bus_automount_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
const BusProperty properties[] = {
BUS_UNIT_PROPERTIES,
{ "org.freedesktop.systemd1.Automount", "Where", bus_property_append_string, "s", u->automount.where },
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, message, INTROSPECTION, properties);
+ return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, properties);
}
diff --git a/src/dbus-automount.h b/src/dbus-automount.h
index 5e0ee51..77c887e 100644
--- a/src/dbus-automount.h
+++ b/src/dbus-automount.h
@@ -26,7 +26,7 @@
#include "unit.h"
-DBusHandlerResult bus_automount_message_handler(Unit *u, DBusMessage *message);
+DBusHandlerResult bus_automount_message_handler(Unit *u, DBusConnection *c, DBusMessage *message);
extern const char bus_automount_interface[];
diff --git a/src/dbus-device.c b/src/dbus-device.c
index 0610ab8..168c8c8 100644
--- a/src/dbus-device.c
+++ b/src/dbus-device.c
@@ -38,12 +38,12 @@
const char bus_device_interface[] = BUS_DEVICE_INTERFACE;
-DBusHandlerResult bus_device_message_handler(Unit *u, DBusMessage *message) {
+DBusHandlerResult bus_device_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
const BusProperty properties[] = {
BUS_UNIT_PROPERTIES,
{ "org.freedesktop.systemd1.Device", "SysFSPath", bus_property_append_string, "s", u->device.sysfs },
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, message, INTROSPECTION, properties);
+ return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, properties);
}
diff --git a/src/dbus-device.h b/src/dbus-device.h
index 55bb8f5..dc717f1 100644
--- a/src/dbus-device.h
+++ b/src/dbus-device.h
@@ -26,7 +26,7 @@
#include "unit.h"
-DBusHandlerResult bus_device_message_handler(Unit *u, DBusMessage *message);
+DBusHandlerResult bus_device_message_handler(Unit *u, DBusConnection *c, DBusMessage *message);
extern const char bus_device_interface[];
diff --git a/src/dbus-job.c b/src/dbus-job.c
index 7346252..48b1588 100644
--- a/src/dbus-job.c
+++ b/src/dbus-job.c
@@ -78,7 +78,7 @@ static int bus_job_append_unit(Manager *m, DBusMessageIter *i, const char *prope
return 0;
}
-static DBusHandlerResult bus_job_message_dispatch(Job *j, DBusMessage *message) {
+static DBusHandlerResult bus_job_message_dispatch(Job *j, DBusConnection *connection, DBusMessage *message) {
const BusProperty properties[] = {
{ "org.freedesktop.systemd1.Job", "Id", bus_property_append_uint32, "u", &j->id },
{ "org.freedesktop.systemd1.Job", "State", bus_job_append_state, "s", &j->state },
@@ -88,7 +88,6 @@ static DBusHandlerResult bus_job_message_dispatch(Job *j, DBusMessage *message)
};
DBusMessage *reply = NULL;
- Manager *m = j->manager;
if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Job", "Cancel")) {
if (!(reply = dbus_message_new_method_return(message)))
@@ -97,10 +96,10 @@ static DBusHandlerResult bus_job_message_dispatch(Job *j, DBusMessage *message)
job_free(j);
} else
- return bus_default_message_handler(j->manager, message, INTROSPECTION, properties);
+ return bus_default_message_handler(j->manager, connection, message, INTROSPECTION, properties);
if (reply) {
- if (!dbus_connection_send(m->api_bus, reply, NULL))
+ if (!dbus_connection_send(connection, reply, NULL))
goto oom;
dbus_message_unref(reply);
@@ -115,7 +114,7 @@ oom:
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
-static DBusHandlerResult bus_job_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {
+static DBusHandlerResult bus_job_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {
Manager *m = data;
Job *j;
int r;
@@ -137,10 +136,10 @@ static DBusHandlerResult bus_job_message_handler(DBusConnection *connection, DB
if (r == -ENOENT)
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- return bus_send_error_reply(m, message, NULL, r);
+ return bus_send_error_reply(m, connection, message, NULL, r);
}
- return bus_job_message_dispatch(j, message);
+ return bus_job_message_dispatch(j, connection, message);
}
const DBusObjectPathVTable bus_job_vtable = {
@@ -183,7 +182,7 @@ void bus_job_send_change_signal(Job *j) {
goto oom;
}
- if (!dbus_connection_send(j->manager->api_bus, m, NULL))
+ if (bus_broadcast(j->manager, m) < 0)
goto oom;
free(p);
@@ -228,7 +227,7 @@ void bus_job_send_removed_signal(Job *j, bool success) {
DBUS_TYPE_INVALID))
goto oom;
- if (!dbus_connection_send(j->manager->api_bus, m, NULL))
+ if (bus_broadcast(j->manager, m) < 0)
goto oom;
free(p);
diff --git a/src/dbus-manager.c b/src/dbus-manager.c
index d4c9e8f..7818257 100644
--- a/src/dbus-manager.c
+++ b/src/dbus-manager.c
@@ -185,7 +185,7 @@ static int bus_manager_append_n_jobs(Manager *m, DBusMessageIter *i, const char
return 0;
}
-static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {
+static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {
Manager *m = data;
const BusProperty properties[] = {
@@ -226,10 +226,10 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection
&error,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, message, &error, -EINVAL);
+ return bus_send_error_reply(m, connection, message, &error, -EINVAL);
if (!(u = manager_get_unit(m, name)))
- return bus_send_error_reply(m, message, NULL, -ENOENT);
+ return bus_send_error_reply(m, connection, message, NULL, -ENOENT);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
@@ -252,10 +252,10 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection
&error,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, message, &error, -EINVAL);
+ return bus_send_error_reply(m, connection, message, &error, -EINVAL);
if ((r = manager_load_unit(m, name, NULL, &u)) < 0)
- return bus_send_error_reply(m, message, NULL, r);
+ return bus_send_error_reply(m, connection, message, NULL, r);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
@@ -286,10 +286,10 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection
&error,
DBUS_TYPE_UINT32, &id,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, message, &error, -EINVAL);
+ return bus_send_error_reply(m, connection, message, &error, -EINVAL);
if (!(j = manager_get_job(m, id)))
- return bus_send_error_reply(m, message, NULL, -ENOENT);
+ return bus_send_error_reply(m, connection, message, NULL, -ENOENT);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
@@ -449,7 +449,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection
r = set_put(m->subscribed, client);
if (r < 0)
- return bus_send_error_reply(m, message, NULL, r);
+ return bus_send_error_reply(m, connection, message, NULL, r);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
@@ -458,7 +458,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection
char *client;
if (!(client = set_remove(m->subscribed, (char*) dbus_message_get_sender(message))))
- return bus_send_error_reply(m, message, NULL, -ENOENT);
+ return bus_send_error_reply(m, connection, message, NULL, -ENOENT);
free(client);
@@ -504,13 +504,13 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection
DBUS_TYPE_STRING, &name,
DBUS_TYPE_BOOLEAN, &cleanup,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, message, &error, -EINVAL);
+ return bus_send_error_reply(m, connection, message, &error, -EINVAL);
if (name && name[0] == 0)
name = NULL;
if ((r = snapshot_create(m, name, cleanup, &s)) < 0)
- return bus_send_error_reply(m, message, NULL, r);
+ return bus_send_error_reply(m, connection, message, NULL, r);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
@@ -609,7 +609,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Exit")) {
if (m->running_as == MANAGER_INIT)
- return bus_send_error_reply(m, message, NULL, -ENOTSUP);
+ return bus_send_error_reply(m, connection, message, NULL, -ENOTSUP);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
@@ -623,7 +623,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection
if (r == -ENOMEM)
goto oom;
- return bus_send_error_reply(m, message, NULL, r);
+ return bus_send_error_reply(m, connection, message, NULL, r);
}
e = strv_env_merge(2, m->environment, l);
@@ -647,7 +647,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection
if (r == -ENOMEM)
goto oom;
- return bus_send_error_reply(m, message, NULL, r);
+ return bus_send_error_reply(m, connection, message, NULL, r);
}
e = strv_env_delete(m->environment, 1, l);
@@ -663,7 +663,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection
m->environment = e;
} else
- return bus_default_message_handler(m, message, NULL, properties);
+ return bus_default_message_handler(m, connection, message, NULL, properties);
if (job_type != _JOB_TYPE_INVALID) {
@@ -678,19 +678,19 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection
DBUS_TYPE_STRING, &name,
DBUS_TYPE_STRING, &smode,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, message, &error, -EINVAL);
+ return bus_send_error_reply(m, connection, message, &error, -EINVAL);
if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID)
- return bus_send_error_reply(m, message, NULL, -EINVAL);
+ return bus_send_error_reply(m, connection, message, NULL, -EINVAL);
if ((r = manager_load_unit(m, name, NULL, &u)) < 0)
- return bus_send_error_reply(m, message, NULL, r);
+ return bus_send_error_reply(m, connection, message, NULL, r);
if (job_type == JOB_START && u->meta.only_by_dependency)
- return bus_send_error_reply(m, message, NULL, -EPERM);
+ return bus_send_error_reply(m, connection, message, NULL, -EPERM);
if ((r = manager_add_job(m, job_type, u, mode, true, &j)) < 0)
- return bus_send_error_reply(m, message, NULL, r);
+ return bus_send_error_reply(m, connection, message, NULL, r);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
diff --git a/src/dbus-mount.c b/src/dbus-mount.c
index cccfa60..0f417e7 100644
--- a/src/dbus-mount.c
+++ b/src/dbus-mount.c
@@ -120,7 +120,7 @@ static int bus_mount_append_type(Manager *n, DBusMessageIter *i, const char *pro
return 0;
}
-DBusHandlerResult bus_mount_message_handler(Unit *u, DBusMessage *message) {
+DBusHandlerResult bus_mount_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
const BusProperty properties[] = {
BUS_UNIT_PROPERTIES,
{ "org.freedesktop.systemd1.Mount", "Where", bus_property_append_string, "s", u->mount.where },
@@ -135,5 +135,5 @@ DBusHandlerResult bus_mount_message_handler(Unit *u, DBusMessage *message) {
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, message, INTROSPECTION, properties);
+ return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, properties);
}
diff --git a/src/dbus-mount.h b/src/dbus-mount.h
index 6d8d1a9..53522f7 100644
--- a/src/dbus-mount.h
+++ b/src/dbus-mount.h
@@ -26,7 +26,7 @@
#include "unit.h"
-DBusHandlerResult bus_mount_message_handler(Unit *u, DBusMessage *message);
+DBusHandlerResult bus_mount_message_handler(Unit *u, DBusConnection *c, DBusMessage *message);
extern const char bus_mount_interface[];
diff --git a/src/dbus-path.c b/src/dbus-path.c
index ed1dc26..7589f5b 100644
--- a/src/dbus-path.c
+++ b/src/dbus-path.c
@@ -41,12 +41,12 @@
const char bus_path_interface[] = BUS_PATH_INTERFACE;
-DBusHandlerResult bus_path_message_handler(Unit *u, DBusMessage *message) {
+DBusHandlerResult bus_path_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
const BusProperty properties[] = {
BUS_UNIT_PROPERTIES,
{ "org.freedesktop.systemd1.Path", "Unit", bus_property_append_string, "s", &u->path.unit->meta.id },
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, message, INTROSPECTION, properties);
+ return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, properties);
}
diff --git a/src/dbus-path.h b/src/dbus-path.h
index 15f5869..261d845 100644
--- a/src/dbus-path.h
+++ b/src/dbus-path.h
@@ -26,7 +26,7 @@
#include "unit.h"
-DBusHandlerResult bus_path_message_handler(Unit *u, DBusMessage *message);
+DBusHandlerResult bus_path_message_handler(Unit *u, DBusConnection *c, DBusMessage *message);
extern const char bus_path_interface[];
diff --git a/src/dbus-service.c b/src/dbus-service.c
index f70a772..283932c 100644
--- a/src/dbus-service.c
+++ b/src/dbus-service.c
@@ -58,7 +58,7 @@ const char bus_service_interface[] = BUS_SERVICE_INTERFACE;
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_type, service_type, ServiceType);
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_restart, service_restart, ServiceRestart);
-DBusHandlerResult bus_service_message_handler(Unit *u, DBusMessage *message) {
+DBusHandlerResult bus_service_message_handler(Unit *u, DBusConnection *connection, DBusMessage *message) {
const BusProperty properties[] = {
BUS_UNIT_PROPERTIES,
{ "org.freedesktop.systemd1.Service", "Type", bus_service_append_type, "s", &u->service.type },
@@ -81,5 +81,5 @@ DBusHandlerResult bus_service_message_handler(Unit *u, DBusMessage *message) {
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, message, INTROSPECTION, properties);
+ return bus_default_message_handler(u->meta.manager, connection, message, INTROSPECTION, properties);
}
diff --git a/src/dbus-service.h b/src/dbus-service.h
index ab1e02f..cfbdab3 100644
--- a/src/dbus-service.h
+++ b/src/dbus-service.h
@@ -26,7 +26,7 @@
#include "unit.h"
-DBusHandlerResult bus_service_message_handler(Unit *u, DBusMessage *message);
+DBusHandlerResult bus_service_message_handler(Unit *u, DBusConnection *c, DBusMessage *message);
extern const char bus_service_interface[];
diff --git a/src/dbus-snapshot.c b/src/dbus-snapshot.c
index 15e51f0..5ba5d7c 100644
--- a/src/dbus-snapshot.c
+++ b/src/dbus-snapshot.c
@@ -39,7 +39,7 @@
const char bus_snapshot_interface[] = BUS_SNAPSHOT_INTERFACE;
-DBusHandlerResult bus_snapshot_message_handler(Unit *u, DBusMessage *message) {
+DBusHandlerResult bus_snapshot_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
const BusProperty properties[] = {
BUS_UNIT_PROPERTIES,
{ "org.freedesktop.systemd1.Snapshot", "Cleanup", bus_property_append_bool, "b", &u->snapshot.cleanup },
@@ -59,10 +59,10 @@ DBusHandlerResult bus_snapshot_message_handler(Unit *u, DBusMessage *message) {
goto oom;
} else
- return bus_default_message_handler(u->meta.manager, message, INTROSPECTION, properties);
+ return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, properties);
if (reply) {
- if (!dbus_connection_send(u->meta.manager->api_bus, reply, NULL))
+ if (!dbus_connection_send(c, reply, NULL))
goto oom;
dbus_message_unref(reply);
diff --git a/src/dbus-snapshot.h b/src/dbus-snapshot.h
index bf5a4d4..60b3720 100644
--- a/src/dbus-snapshot.h
+++ b/src/dbus-snapshot.h
@@ -26,7 +26,7 @@
#include "unit.h"
-DBusHandlerResult bus_snapshot_message_handler(Unit *u, DBusMessage *message);
+DBusHandlerResult bus_snapshot_message_handler(Unit *u, DBusConnection *c, DBusMessage *message);
extern const char bus_snapshot_interface[];
diff --git a/src/dbus-socket.c b/src/dbus-socket.c
index 426af2b..a5474c9 100644
--- a/src/dbus-socket.c
+++ b/src/dbus-socket.c
@@ -52,7 +52,7 @@ const char bus_socket_interface[] = BUS_SOCKET_INTERFACE;
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_socket_append_bind_ipv6_only, socket_address_bind_ipv6_only, SocketAddressBindIPv6Only);
-DBusHandlerResult bus_socket_message_handler(Unit *u, DBusMessage *message) {
+DBusHandlerResult bus_socket_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
const BusProperty properties[] = {
BUS_UNIT_PROPERTIES,
{ "org.freedesktop.systemd1.Socket", "BindIPv6Only", bus_socket_append_bind_ipv6_only, "s", &u->socket.bind_ipv6_only },
@@ -69,5 +69,5 @@ DBusHandlerResult bus_socket_message_handler(Unit *u, DBusMessage *message) {
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, message, INTROSPECTION, properties);
+ return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, properties);
}
diff --git a/src/dbus-socket.h b/src/dbus-socket.h
index ab06322..79a1546 100644
--- a/src/dbus-socket.h
+++ b/src/dbus-socket.h
@@ -26,7 +26,7 @@
#include "unit.h"
-DBusHandlerResult bus_socket_message_handler(Unit *u, DBusMessage *message);
+DBusHandlerResult bus_socket_message_handler(Unit *u, DBusConnection *c, DBusMessage *message);
extern const char bus_socket_interface[];
diff --git a/src/dbus-swap.c b/src/dbus-swap.c
index f6f8685..676ec5c 100644
--- a/src/dbus-swap.c
+++ b/src/dbus-swap.c
@@ -66,7 +66,7 @@ static int bus_swap_append_priority(Manager *m, DBusMessageIter *i, const char *
return 0;
}
-DBusHandlerResult bus_swap_message_handler(Unit *u, DBusMessage *message) {
+DBusHandlerResult bus_swap_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
const BusProperty properties[] = {
BUS_UNIT_PROPERTIES,
{ "org.freedesktop.systemd1.Swap", "What", bus_property_append_string, "s", u->swap.what },
@@ -74,5 +74,5 @@ DBusHandlerResult bus_swap_message_handler(Unit *u, DBusMessage *message) {
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, message, INTROSPECTION, properties);
+ return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, properties);
}
diff --git a/src/dbus-swap.h b/src/dbus-swap.h
index cbd1591..a3d418c 100644
--- a/src/dbus-swap.h
+++ b/src/dbus-swap.h
@@ -27,7 +27,7 @@
#include "unit.h"
-DBusHandlerResult bus_swap_message_handler(Unit *u, DBusMessage *message);
+DBusHandlerResult bus_swap_message_handler(Unit *u, DBusConnection *c, DBusMessage *message);
extern const char bus_swap_interface[];
diff --git a/src/dbus-target.c b/src/dbus-target.c
index 45f0d31..fb84430 100644
--- a/src/dbus-target.c
+++ b/src/dbus-target.c
@@ -37,11 +37,11 @@
const char bus_target_interface[] = BUS_TARGET_INTERFACE;
-DBusHandlerResult bus_target_message_handler(Unit *u, DBusMessage *message) {
+DBusHandlerResult bus_target_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
const BusProperty properties[] = {
BUS_UNIT_PROPERTIES,
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, message, INTROSPECTION, properties);
+ return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, properties);
}
diff --git a/src/dbus-target.h b/src/dbus-target.h
index d118441..af2dc62 100644
--- a/src/dbus-target.h
+++ b/src/dbus-target.h
@@ -26,7 +26,7 @@
#include "unit.h"
-DBusHandlerResult bus_target_message_handler(Unit *u, DBusMessage *message);
+DBusHandlerResult bus_target_message_handler(Unit *u, DBusConnection *c, DBusMessage *message);
extern const char bus_target_interface[];
diff --git a/src/dbus-timer.c b/src/dbus-timer.c
index d572907..68bd8a4 100644
--- a/src/dbus-timer.c
+++ b/src/dbus-timer.c
@@ -41,12 +41,12 @@
const char bus_timer_interface[] = BUS_TIMER_INTERFACE;
-DBusHandlerResult bus_timer_message_handler(Unit *u, DBusMessage *message) {
+DBusHandlerResult bus_timer_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
const BusProperty properties[] = {
BUS_UNIT_PROPERTIES,
{ "org.freedesktop.systemd1.Timer", "Unit", bus_property_append_string, "s", &u->timer.unit->meta.id },
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, message, INTROSPECTION, properties);
+ return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, properties);
}
diff --git a/src/dbus-timer.h b/src/dbus-timer.h
index 250e818..562d449 100644
--- a/src/dbus-timer.h
+++ b/src/dbus-timer.h
@@ -26,7 +26,7 @@
#include "unit.h"
-DBusHandlerResult bus_timer_message_handler(Unit *u, DBusMessage *message);
+DBusHandlerResult bus_timer_message_handler(Unit *u, DBusConnection *c, DBusMessage *message);
extern const char bus_timer_interface[];
diff --git a/src/dbus-unit.c b/src/dbus-unit.c
index 8e35377..17ca7bd 100644
--- a/src/dbus-unit.c
+++ b/src/dbus-unit.c
@@ -255,7 +255,7 @@ int bus_unit_append_cgroups(Manager *m, DBusMessageIter *i, const char *property
DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_unit_append_kill_mode, kill_mode, KillMode);
-static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusMessage *message) {
+static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *connection, DBusMessage *message) {
DBusMessage *reply = NULL;
Manager *m = u->meta.manager;
DBusError error;
@@ -273,7 +273,7 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusMessage *message
else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "Restart"))
job_type = JOB_RESTART;
else if (UNIT_VTABLE(u)->bus_message_handler)
- return UNIT_VTABLE(u)->bus_message_handler(u, message);
+ return UNIT_VTABLE(u)->bus_message_handler(u, connection, message);
else
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
@@ -284,20 +284,20 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusMessage *message
int r;
if (job_type == JOB_START && u->meta.only_by_dependency)
- return bus_send_error_reply(m, message, NULL, -EPERM);
+ return bus_send_error_reply(m, connection, message, NULL, -EPERM);
if (!dbus_message_get_args(
message,
&error,
DBUS_TYPE_STRING, &smode,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, message, &error, -EINVAL);
+ return bus_send_error_reply(m, connection, message, &error, -EINVAL);
if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID)
- return bus_send_error_reply(m, message, NULL, -EINVAL);
+ return bus_send_error_reply(m, connection, message, NULL, -EINVAL);
if ((r = manager_add_job(m, job_type, u, mode, true, &j)) < 0)
- return bus_send_error_reply(m, message, NULL, r);
+ return bus_send_error_reply(m, connection, message, NULL, r);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
@@ -315,7 +315,7 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusMessage *message
free(path);
if (reply) {
- if (!dbus_connection_send(m->api_bus, reply, NULL))
+ if (!dbus_connection_send(connection, reply, NULL))
goto oom;
dbus_message_unref(reply);
@@ -334,7 +334,7 @@ oom:
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
-static DBusHandlerResult bus_unit_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {
+static DBusHandlerResult bus_unit_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {
Manager *m = data;
Unit *u;
int r;
@@ -356,10 +356,10 @@ static DBusHandlerResult bus_unit_message_handler(DBusConnection *connection, D
if (r == -ENOENT)
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- return bus_send_error_reply(m, message, NULL, r);
+ return bus_send_error_reply(m, connection, message, NULL, r);
}
- return bus_unit_message_dispatch(u, message);
+ return bus_unit_message_dispatch(u, connection, message);
}
const DBusObjectPathVTable bus_unit_vtable = {
@@ -402,7 +402,7 @@ void bus_unit_send_change_signal(Unit *u) {
goto oom;
}
- if (!dbus_connection_send(u->meta.manager->api_bus, m, NULL))
+ if (bus_broadcast(u->meta.manager, m) < 0)
goto oom;
free(p);
@@ -445,7 +445,7 @@ void bus_unit_send_removed_signal(Unit *u) {
DBUS_TYPE_INVALID))
goto oom;
- if (!dbus_connection_send(u->meta.manager->api_bus, m, NULL))
+ if (bus_broadcast(u->meta.manager, m) < 0)
goto oom;
free(p);
diff --git a/src/dbus.c b/src/dbus.c
index a4e350c..a34c7dc 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -43,6 +43,8 @@
#include "dbus-timer.h"
#include "dbus-path.h"
+#define CONNECTIONS_MAX 52
+
static const char bus_properties_interface[] = BUS_PROPERTIES_INTERFACE;
static const char bus_introspectable_interface[] = BUS_INTROSPECTABLE_INTERFACE;
@@ -66,33 +68,24 @@ const char *const bus_interface_table[] = {
};
static const char *error_to_dbus(int error);
+static void bus_done_api(Manager *m);
+static void bus_done_system(Manager *m);
+static void bus_done_private(Manager *m);
-static void api_bus_dispatch_status(DBusConnection *bus, DBusDispatchStatus status, void *data) {
- Manager *m = data;
-
- assert(bus);
- assert(m);
-
- if (!m->api_bus)
- return;
-
- assert(m->api_bus == bus);
-
- m->request_api_bus_dispatch = status != DBUS_DISPATCH_COMPLETE;
-}
-
-static void system_bus_dispatch_status(DBusConnection *bus, DBusDispatchStatus status, void *data) {
+static void bus_dispatch_status(DBusConnection *bus, DBusDispatchStatus status, void *data) {
Manager *m = data;
assert(bus);
assert(m);
- if (!m->system_bus)
- return;
-
- assert(m->system_bus == bus);
+ /* We maintain two sets, one for those connections where we
+ * requested a dispatch, and another where we didn't. And then,
+ * we move the connections between the two sets. */
- m->request_system_bus_dispatch = status != DBUS_DISPATCH_COMPLETE;
+ if (status == DBUS_DISPATCH_COMPLETE)
+ set_move_one(m->bus_connections, m->bus_connections_for_dispatch, bus);
+ else
+ set_move_one(m->bus_connections_for_dispatch, m->bus_connections, bus);
}
static uint32_t bus_flags_to_events(DBusWatch *bus_watch) {
@@ -472,7 +465,30 @@ static DBusHandlerResult system_bus_message_filter(DBusConnection *connection, D
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
+static DBusHandlerResult private_bus_message_filter(DBusConnection *connection, DBusMessage *message, void *data) {
+ Manager *m = data;
+
+ assert(connection);
+ assert(message);
+ assert(m);
+
+ /* log_debug("Got D-Bus request: %s.%s() on %s", */
+ /* dbus_message_get_interface(message), */
+ /* dbus_message_get_member(message), */
+ /* dbus_message_get_path(message)); */
+
+ if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconnected")) {
+ set_remove(m->bus_connections, connection);
+ set_remove(m->bus_connections_for_dispatch, connection);
+ dbus_connection_unref(connection);
+ }
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
unsigned bus_dispatch(Manager *m) {
+ DBusConnection *c;
+
assert(m);
if (m->queued_message) {
@@ -480,23 +496,17 @@ unsigned bus_dispatch(Manager *m) {
* dispatch any D-Bus messages, so that we won't end
* up wanting to queue another message. */
- if (!dbus_connection_send(m->api_bus, m->queued_message, NULL))
- return 0;
+ if (m->api_bus)
+ if (!dbus_connection_send(m->api_bus, m->queued_message, NULL))
+ return 0;
dbus_message_unref(m->queued_message);
m->queued_message = NULL;
}
- if (m->request_api_bus_dispatch) {
- if (dbus_connection_dispatch(m->api_bus) == DBUS_DISPATCH_COMPLETE)
- m->request_api_bus_dispatch = false;
-
- return 1;
- }
-
- if (m->request_system_bus_dispatch) {
- if (dbus_connection_dispatch(m->system_bus) == DBUS_DISPATCH_COMPLETE)
- m->request_system_bus_dispatch = false;
+ if ((c = set_first(m->bus_connections_for_dispatch))) {
+ if (dbus_connection_dispatch(c) == DBUS_DISPATCH_COMPLETE)
+ set_move_one(m->bus_connections, m->bus_connections_for_dispatch, c);
return 1;
}
@@ -689,13 +699,57 @@ static int bus_setup_loop(Manager *m, DBusConnection *bus) {
dbus_connection_set_exit_on_disconnect(bus, FALSE);
if (!dbus_connection_set_watch_functions(bus, bus_add_watch, bus_remove_watch, bus_toggle_watch, m, NULL) ||
- !dbus_connection_set_timeout_functions(bus, bus_add_timeout, bus_remove_timeout, bus_toggle_timeout, m, NULL))
+ !dbus_connection_set_timeout_functions(bus, bus_add_timeout, bus_remove_timeout, bus_toggle_timeout, m, NULL)) {
+ log_error("Not enough memory");
return -ENOMEM;
+ }
+ if (set_put(m->bus_connections_for_dispatch, bus) < 0) {
+ log_error("Not enough memory");
+ return -ENOMEM;
+ }
+
+ dbus_connection_set_dispatch_status_function(bus, bus_dispatch_status, m, NULL);
return 0;
}
-int bus_init_system(Manager *m) {
+static dbus_bool_t allow_only_root(DBusConnection *connection, unsigned long uid, void *data) {
+ return uid == 0;
+}
+
+static void bus_new_connection(
+ DBusServer *server,
+ DBusConnection *new_connection,
+ void *data) {
+
+ Manager *m = data;
+
+ assert(m);
+
+ if (set_size(m->bus_connections) >= CONNECTIONS_MAX) {
+ log_error("Too many concurrent connections.");
+ return;
+ }
+
+ dbus_connection_set_unix_user_function(new_connection, allow_only_root, NULL, NULL);
+
+ if (bus_setup_loop(m, new_connection) < 0)
+ return;
+
+ if (!dbus_connection_register_object_path(new_connection, "/org/freedesktop/systemd1", &bus_manager_vtable, m) ||
+ !dbus_connection_register_fallback(new_connection, "/org/freedesktop/systemd1/unit", &bus_unit_vtable, m) ||
+ !dbus_connection_register_fallback(new_connection, "/org/freedesktop/systemd1/job", &bus_job_vtable, m) ||
+ !dbus_connection_add_filter(new_connection, private_bus_message_filter, m, NULL)) {
+ log_error("Not enough memory.");
+ return;
+ }
+
+ log_debug("Accepted connection on private bus.");
+
+ dbus_connection_ref(new_connection);
+}
+
+static int bus_init_system(Manager *m) {
DBusError error;
char *id;
int r;
@@ -712,22 +766,18 @@ int bus_init_system(Manager *m) {
else {
if (!(m->system_bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error))) {
log_debug("Failed to get system D-Bus connection, retrying later: %s", error.message);
- dbus_error_free(&error);
- return 0;
+ r = 0;
+ goto fail;
}
- dbus_connection_set_dispatch_status_function(m->system_bus, system_bus_dispatch_status, m, NULL);
- m->request_system_bus_dispatch = true;
-
- if ((r = bus_setup_loop(m, m->system_bus)) < 0) {
- bus_done_system(m);
- return r;
- }
+ if ((r = bus_setup_loop(m, m->system_bus)) < 0)
+ goto fail;
}
if (!dbus_connection_add_filter(m->system_bus, system_bus_message_filter, m, NULL)) {
- bus_done_system(m);
- return -ENOMEM;
+ log_error("Not enough memory");
+ r = -EIO;
+ goto fail;
}
dbus_bus_add_match(m->system_bus,
@@ -739,9 +789,8 @@ int bus_init_system(Manager *m) {
if (dbus_error_is_set(&error)) {
log_error("Failed to register match: %s", error.message);
- dbus_error_free(&error);
- bus_done_system(m);
- return -ENOMEM;
+ r = -EIO;
+ goto fail;
}
log_debug("Successfully connected to system D-Bus bus %s as %s",
@@ -750,9 +799,15 @@ int bus_init_system(Manager *m) {
dbus_free(id);
return 0;
+
+fail:
+ bus_done_system(m);
+ dbus_error_free(&error);
+
+ return r;
}
-int bus_init_api(Manager *m) {
+static int bus_init_api(Manager *m) {
DBusError error;
char *id;
int r;
@@ -764,34 +819,26 @@ int bus_init_api(Manager *m) {
if (m->api_bus)
return 0;
- if (m->name_data_slot < 0)
- if (!dbus_pending_call_allocate_data_slot(&m->name_data_slot))
- return -ENOMEM;
-
if (m->running_as != MANAGER_SESSION && m->system_bus)
m->api_bus = m->system_bus;
else {
if (!(m->api_bus = dbus_bus_get_private(m->running_as == MANAGER_SESSION ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, &error))) {
log_debug("Failed to get API D-Bus connection, retrying later: %s", error.message);
- dbus_error_free(&error);
- return 0;
+ r = 0;
+ goto fail;
}
- dbus_connection_set_dispatch_status_function(m->api_bus, api_bus_dispatch_status, m, NULL);
- m->request_api_bus_dispatch = true;
-
- if ((r = bus_setup_loop(m, m->api_bus)) < 0) {
- bus_done_api(m);
- return r;
- }
+ if ((r = bus_setup_loop(m, m->api_bus)) < 0)
+ goto fail;
}
if (!dbus_connection_register_object_path(m->api_bus, "/org/freedesktop/systemd1", &bus_manager_vtable, m) ||
!dbus_connection_register_fallback(m->api_bus, "/org/freedesktop/systemd1/unit", &bus_unit_vtable, m) ||
!dbus_connection_register_fallback(m->api_bus, "/org/freedesktop/systemd1/job", &bus_job_vtable, m) ||
!dbus_connection_add_filter(m->api_bus, api_bus_message_filter, m, NULL)) {
- bus_done_api(m);
- return -ENOMEM;
+ log_error("Not enough memory");
+ r = -ENOMEM;
+ goto fail;
}
/* Get NameOwnerChange messages */
@@ -805,9 +852,8 @@ int bus_init_api(Manager *m) {
if (dbus_error_is_set(&error)) {
log_error("Failed to register match: %s", error.message);
- dbus_error_free(&error);
- bus_done_api(m);
- return -ENOMEM;
+ r = -EIO;
+ goto fail;
}
/* Get activation requests */
@@ -821,20 +867,15 @@ int bus_init_api(Manager *m) {
if (dbus_error_is_set(&error)) {
log_error("Failed to register match: %s", error.message);
- dbus_error_free(&error);
- bus_done_api(m);
- return -ENOMEM;
+ r = -EIO;
+ goto fail;
}
- if ((r = request_name(m)) < 0) {
- bus_done_api(m);
- return r;
- }
+ if ((r = request_name(m)) < 0)
+ goto fail;
- if ((r = query_name_list(m)) < 0) {
- bus_done_api(m);
- return r;
- }
+ if ((r = query_name_list(m)) < 0)
+ goto fail;
log_debug("Successfully connected to API D-Bus bus %s as %s",
strnull((id = dbus_connection_get_server_id(m->api_bus))),
@@ -842,23 +883,106 @@ int bus_init_api(Manager *m) {
dbus_free(id);
if (!m->subscribed)
- if (!(m->subscribed = set_new(string_hash_func, string_compare_func)))
+ if (!(m->subscribed = set_new(string_hash_func, string_compare_func))) {
+ log_error("Not enough memory");
+ r = -ENOMEM;
+ goto fail;
+ }
+
+ return 0;
+
+fail:
+ bus_done_api(m);
+ dbus_error_free(&error);
+
+ return r;
+}
+
+static int bus_init_private(Manager *m) {
+ DBusError error;
+ int r;
+ const char *const external_only[] = {
+ "EXTERNAL",
+ NULL
+ };
+
+ assert(m);
+
+ dbus_error_init(&error);
+
+ if (m->private_bus)
+ return 0;
+
+ /* We want the private bus only when running as init */
+ if (m->running_as != MANAGER_INIT)
+ return 0;
+
+ if (!(m->private_bus = dbus_server_listen("unix:abstract=/org/freedesktop/systemd1/private", &error))) {
+ log_error("Failed to create private D-Bus server: %s", error.message);
+ r = -EIO;
+ goto fail;
+ }
+
+ if (!dbus_server_set_auth_mechanisms(m->private_bus, (const char**) external_only) ||
+ !dbus_server_set_watch_functions(m->private_bus, bus_add_watch, bus_remove_watch, bus_toggle_watch, m, NULL) ||
+ !dbus_server_set_timeout_functions(m->private_bus, bus_add_timeout, bus_remove_timeout, bus_toggle_timeout, m, NULL)) {
+ log_error("Not enough memory");
+ r = -ENOMEM;
+ goto fail;
+ }
+
+ dbus_server_set_new_connection_function(m->private_bus, bus_new_connection, m, NULL);
+
+ log_debug("Successfully create private D-Bus server.");
+
+ return 0;
+
+fail:
+ bus_done_private(m);
+ dbus_error_free(&error);
+
+ return r;
+}
+
+int bus_init(Manager *m) {
+ int r;
+
+ if (set_ensure_allocated(&m->bus_connections, trivial_hash_func, trivial_compare_func) < 0 ||
+ set_ensure_allocated(&m->bus_connections_for_dispatch, trivial_hash_func, trivial_compare_func) < 0) {
+ log_error("Not enough memory");
+ return -ENOMEM;
+ }
+
+ if (m->name_data_slot < 0)
+ if (!dbus_pending_call_allocate_data_slot(&m->name_data_slot)) {
+ log_error("Not enough memory");
return -ENOMEM;
+ }
+
+ if ((r = bus_init_system(m)) < 0 ||
+ (r = bus_init_api(m)) < 0 ||
+ (r = bus_init_private(m)) < 0)
+ return r;
return 0;
}
-void bus_done_api(Manager *m) {
+static void shutdown_connection(DBusConnection *c) {
+ dbus_connection_set_dispatch_status_function(c, NULL, NULL, NULL);
+ dbus_connection_flush(c);
+ dbus_connection_close(c);
+ dbus_connection_unref(c);
+}
+
+static void bus_done_api(Manager *m) {
assert(m);
if (m->api_bus) {
if (m->system_bus == m->api_bus)
m->system_bus = NULL;
- dbus_connection_set_dispatch_status_function(m->api_bus, NULL, NULL, NULL);
- dbus_connection_flush(m->api_bus);
- dbus_connection_close(m->api_bus);
- dbus_connection_unref(m->api_bus);
+ set_remove(m->bus_connections, m->api_bus);
+ shutdown_connection(m->api_bus);
m->api_bus = NULL;
}
@@ -872,30 +996,54 @@ void bus_done_api(Manager *m) {
m->subscribed = NULL;
}
- if (m->name_data_slot >= 0)
- dbus_pending_call_free_data_slot(&m->name_data_slot);
-
if (m->queued_message) {
dbus_message_unref(m->queued_message);
m->queued_message = NULL;
}
}
-void bus_done_system(Manager *m) {
+static void bus_done_system(Manager *m) {
assert(m);
if (m->system_bus == m->api_bus)
bus_done_api(m);
if (m->system_bus) {
- dbus_connection_set_dispatch_status_function(m->system_bus, NULL, NULL, NULL);
- dbus_connection_flush(m->system_bus);
- dbus_connection_close(m->system_bus);
- dbus_connection_unref(m->system_bus);
+ set_remove(m->bus_connections, m->system_bus);
+ shutdown_connection(m->system_bus);
m->system_bus = NULL;
}
}
+static void bus_done_private(Manager *m) {
+
+ if (m->private_bus) {
+ dbus_server_disconnect(m->private_bus);
+ dbus_server_unref(m->private_bus);
+ m->private_bus = NULL;
+ }
+}
+
+void bus_done(Manager *m) {
+ DBusConnection *c;
+
+ bus_done_api(m);
+ bus_done_system(m);
+ bus_done_private(m);
+
+ while ((c = set_steal_first(m->bus_connections)))
+ shutdown_connection(c);
+
+ while ((c = set_steal_first(m->bus_connections_for_dispatch)))
+ shutdown_connection(c);
+
+ set_free(m->bus_connections);
+ set_free(m->bus_connections_for_dispatch);
+
+ if (m->name_data_slot >= 0)
+ dbus_pending_call_free_data_slot(&m->name_data_slot);
+}
+
static void query_pid_pending_cb(DBusPendingCall *pending, void *userdata) {
Manager *m = userdata;
DBusMessage *reply;
@@ -992,7 +1140,7 @@ oom:
return -ENOMEM;
}
-DBusHandlerResult bus_default_message_handler(Manager *m, DBusMessage *message, const char*introspection, const BusProperty *properties) {
+DBusHandlerResult bus_default_message_handler(Manager *m, DBusConnection *c, DBusMessage *message, const char*introspection, const BusProperty *properties) {
DBusError error;
DBusMessage *reply = NULL;
int r;
@@ -1020,7 +1168,7 @@ DBusHandlerResult bus_default_message_handler(Manager *m, DBusMessage *message,
DBUS_TYPE_STRING, &interface,
DBUS_TYPE_STRING, &property,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, message, &error, -EINVAL);
+ return bus_send_error_reply(m, c, message, &error, -EINVAL);
for (p = properties; p->property; p++)
if (streq(p->interface, interface) && streq(p->property, property))
@@ -1043,7 +1191,7 @@ DBusHandlerResult bus_default_message_handler(Manager *m, DBusMessage *message,
goto oom;
dbus_message_unref(reply);
- return bus_send_error_reply(m, message, NULL, r);
+ return bus_send_error_reply(m, c, message, NULL, r);
}
if (!dbus_message_iter_close_container(&iter, &sub))
@@ -1060,7 +1208,7 @@ DBusHandlerResult bus_default_message_handler(Manager *m, DBusMessage *message,
&error,
DBUS_TYPE_STRING, &interface,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, message, &error, -EINVAL);
+ return bus_send_error_reply(m, c, message, &error, -EINVAL);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
@@ -1085,7 +1233,7 @@ DBusHandlerResult bus_default_message_handler(Manager *m, DBusMessage *message,
goto oom;
dbus_message_unref(reply);
- return bus_send_error_reply(m, message, NULL, r);
+ return bus_send_error_reply(m, c, message, NULL, r);
}
if (!dbus_message_iter_close_container(&sub2, &sub3) ||
@@ -1100,7 +1248,7 @@ DBusHandlerResult bus_default_message_handler(Manager *m, DBusMessage *message,
}
if (reply) {
- if (!dbus_connection_send(m->api_bus, reply, NULL))
+ if (!dbus_connection_send(c, reply, NULL))
goto oom;
dbus_message_unref(reply);
@@ -1156,7 +1304,7 @@ static const char *error_to_dbus(int error) {
return DBUS_ERROR_FAILED;
}
-DBusHandlerResult bus_send_error_reply(Manager *m, DBusMessage *message, DBusError *bus_error, int error) {
+DBusHandlerResult bus_send_error_reply(Manager *m, DBusConnection *c, DBusMessage *message, DBusError *bus_error, int error) {
DBusMessage *reply = NULL;
const char *name, *text;
@@ -1171,7 +1319,7 @@ DBusHandlerResult bus_send_error_reply(Manager *m, DBusMessage *message, DBusErr
if (!(reply = dbus_message_new_error(message, name, text)))
goto oom;
- if (!dbus_connection_send(m->api_bus, reply, NULL))
+ if (!dbus_connection_send(c, reply, NULL))
goto oom;
dbus_message_unref(reply);
@@ -1191,6 +1339,25 @@ oom:
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
+int bus_broadcast(Manager *m, DBusMessage *message) {
+ bool oom = false;
+ Iterator i;
+ DBusConnection *c;
+
+ assert(m);
+ assert(message);
+
+ SET_FOREACH(c, m->bus_connections_for_dispatch, i)
+ if (c != m->system_bus || m->running_as != MANAGER_SESSION)
+ oom = !dbus_connection_send(c, message, NULL);
+
+ SET_FOREACH(c, m->bus_connections, i)
+ if (c != m->system_bus || m->running_as != MANAGER_SESSION)
+ oom = !dbus_connection_send(c, message, NULL);
+
+ return oom ? -ENOMEM : 0;
+}
+
int bus_property_append_string(Manager *m, DBusMessageIter *i, const char *property, void *data) {
const char *t = data;
diff --git a/src/dbus.h b/src/dbus.h
index 264bdff..af837f2 100644
--- a/src/dbus.h
+++ b/src/dbus.h
@@ -56,10 +56,8 @@ typedef struct BusProperty {
" </method>\n" \
" </interface>\n"
-int bus_init_system(Manager *m);
-int bus_init_api(Manager *m);
-void bus_done_system(Manager *m);
-void bus_done_api(Manager *m);
+int bus_init(Manager *m);
+void bus_done(Manager *m);
unsigned bus_dispatch(Manager *m);
@@ -68,9 +66,10 @@ void bus_timeout_event(Manager *m, Watch *w, int events);
int bus_query_pid(Manager *m, const char *name);
-DBusHandlerResult bus_default_message_handler(Manager *m, DBusMessage *message, const char* introspection, const BusProperty *properties);
+DBusHandlerResult bus_default_message_handler(Manager *m, DBusConnection *c, DBusMessage *message, const char* introspection, const BusProperty *properties);
+DBusHandlerResult bus_send_error_reply(Manager *m, DBusConnection *c, DBusMessage *message, DBusError *bus_error, int error);
-DBusHandlerResult bus_send_error_reply(Manager *m, DBusMessage *message, DBusError *bus_error, int error);
+int bus_broadcast(Manager *m, DBusMessage *message);
int bus_property_append_string(Manager *m, DBusMessageIter *i, const char *property, void *data);
int bus_property_append_strv(Manager *m, DBusMessageIter *i, const char *property, void *data);
diff --git a/src/manager.c b/src/manager.c
index dee6109..456241f 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -243,8 +243,7 @@ int manager_new(ManagerRunningAs running_as, bool confirm_spawn, Manager **_m) {
goto fail;
/* Try to connect to the busses, if possible. */
- if ((r = bus_init_system(m)) < 0 ||
- (r = bus_init_api(m)) < 0)
+ if ((r = bus_init(m)) < 0)
goto fail;
if (asprintf(&p, "%s/%s", m->cgroup_mount_point, m->cgroup_hierarchy) < 0) {
@@ -424,8 +423,7 @@ void manager_free(Manager *m) {
* around */
manager_shutdown_cgroup(m, m->exit_code != MANAGER_REEXECUTE);
- bus_done_api(m);
- bus_done_system(m);
+ bus_done(m);
hashmap_free(m->units);
hashmap_free(m->jobs);
@@ -1826,8 +1824,7 @@ static int manager_process_signal_fd(Manager *m) {
if (!u || UNIT_IS_ACTIVE_OR_RELOADING(unit_active_state(u))) {
log_info("Trying to reconnect to bus...");
- bus_init_system(m);
- bus_init_api(m);
+ bus_init(m);
}
if (!u || !UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(u))) {
diff --git a/src/manager.h b/src/manager.h
index 6c3434e..2a04bc7 100644
--- a/src/manager.h
+++ b/src/manager.h
@@ -154,6 +154,9 @@ struct Manager {
/* Data specific to the D-Bus subsystem */
DBusConnection *api_bus, *system_bus;
+ DBusServer *private_bus;
+ Set *bus_connections, *bus_connections_for_dispatch;
+
Set *subscribed;
DBusMessage *queued_message; /* This is used during reloading:
* before the reload we queue the
@@ -188,9 +191,6 @@ struct Manager {
bool dispatching_run_queue:1;
bool dispatching_dbus_queue:1;
- bool request_api_bus_dispatch:1;
- bool request_system_bus_dispatch:1;
-
bool utmp_reboot_written:1;
bool confirm_spawn:1;
diff --git a/src/systemctl.c b/src/systemctl.c
index 444ddf3..429d6a7 100644
--- a/src/systemctl.c
+++ b/src/systemctl.c
@@ -1751,7 +1751,6 @@ static int shutdown_parse_argv(int argc, char *argv[]) {
optind = argc;
return 1;
-
}
static int telinit_parse_argv(int argc, char *argv[]) {
@@ -2262,7 +2261,13 @@ int main(int argc, char*argv[]) {
goto finish;
}
- if ((bus = dbus_bus_get(arg_session ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, &error)))
+ /* If we are root, then let's not go via the bus */
+ if (geteuid() == 0 && !arg_session)
+ bus = dbus_connection_open("unix:abstract=/org/freedesktop/systemd1/private", &error);
+ else
+ bus = dbus_bus_get(arg_session ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, &error);
+
+ if (bus)
dbus_connection_set_exit_on_disconnect(bus, FALSE);
switch (arg_action) {
diff --git a/src/unit.c b/src/unit.c
index 327444b..c12c2a7 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -1030,8 +1030,7 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) {
/* The bus just might have become available,
* hence try to connect to it, if we aren't
* yet connected. */
- bus_init_system(u->meta.manager);
- bus_init_api(u->meta.manager);
+ bus_init(u->meta.manager);
}
if (unit_has_name(u, SPECIAL_SYSLOG_SERVICE))
diff --git a/src/unit.h b/src/unit.h
index 3397d47..c5be858 100644
--- a/src/unit.h
+++ b/src/unit.h
@@ -296,7 +296,7 @@ struct UnitVTable {
void (*bus_query_pid_done)(Unit *u, const char *name, pid_t pid);
/* Called for each message received on the bus */
- DBusHandlerResult (*bus_message_handler)(Unit *u, DBusMessage *message);
+ DBusHandlerResult (*bus_message_handler)(Unit *u, DBusConnection *c, DBusMessage *message);
/* This is called for each unit type and should be used to
* enumerate existing devices and load them. However,
More information about the systemd-commits
mailing list