dbus.c revision 969987ea93a7fdcd2c87b551eb0adf0bd9338b32
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt This file is part of systemd.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Copyright 2010 Lennart Poettering
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt systemd is free software; you can redistribute it and/or modify it
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt under the terms of the GNU Lesser General Public License as published by
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt the Free Software Foundation; either version 2.1 of the License, or
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt (at your option) any later version.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt systemd is distributed in the hope that it will be useful, but
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt WITHOUT ANY WARRANTY; without even the implied warranty of
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Lesser General Public License for more details.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt You should have received a copy of the GNU Lesser General Public License
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt along with systemd; If not, see <http://www.gnu.org/licenses/>.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic void destroy_bus(Manager *m, sd_bus **bus);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt /* If we cannot get rid of this message we won't dispatch any
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * D-Bus messages, so that we won't end up wanting to queue
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * another message. */
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = sd_bus_send(m->queued_message_bus, m->queued_message, NULL);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_warning("Failed to send queued message: %s", strerror(-r));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt m->queued_message = sd_bus_message_unref(m->queued_message);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt m->queued_message_bus = sd_bus_unref(m->queued_message_bus);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic int signal_agent_released(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = sd_bus_message_read(message, "s", &cgroup);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (m->running_as == SYSTEMD_SYSTEM && m->system_bus) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt /* If we are running as system manager, forward the
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * message to the system bus */
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = sd_bus_send(m->system_bus, message, NULL);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_warning("Failed to forward Released message: %s", strerror(-r));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic int signal_disconnected(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_debug("Got disconnect on private connection.");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic int signal_name_owner_changed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = sd_bus_message_read(message, "sss", &name, &old_owner, &new_owner);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic int signal_activation_request(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *ret_error) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = sd_bus_message_read(message, "s", &name);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (manager_unit_inactive_or_pending(m, SPECIAL_DBUS_SERVICE) ||
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt manager_unit_inactive_or_pending(m, SPECIAL_DBUS_SOCKET)) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = sd_bus_error_setf(&error, BUS_ERROR_SHUTTING_DOWN, "Refusing activation, D-Bus is shutting down.");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = manager_load_unit(m, name, NULL, &error, &u);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = sd_bus_error_setf(&error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Operation refused, %u may be requested by dependency only.", u->id);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = manager_add_job(m, JOB_START, u, JOB_REPLACE, true, &error, NULL);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt /* Successfully queued, that's it for us */
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt log_debug("D-Bus activation failed for %s: %s", name, bus_error_message(&error, r));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = sd_bus_message_new_signal(bus, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Activator", "ActivationFailure", &reply);
e80afdb3e4a1239ce0bffa4215d6a227caf3d833Michal Schmidt r = sd_bus_message_append(reply, "sss", name, error.name, error.message);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = sd_bus_send_to(bus, reply, "org.freedesktop.DBus", NULL);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt log_error("Failed to respond with to bus activation request: %s", strerror(-r));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic int selinux_filter(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt /* Our own method calls are all protected individually with
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * selinux checks, but the built-in interfaces need to be
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * protected too. */
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (sd_bus_message_is_method_call(message, "org.freedesktop.DBus.Properties", "Set"))
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt else if (sd_bus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", NULL) ||
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt sd_bus_message_is_method_call(message, "org.freedesktop.DBus.Properties", NULL) ||
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt sd_bus_message_is_method_call(message, "org.freedesktop.DBus.ObjectManager", NULL) ||
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt sd_bus_message_is_method_call(message, "org.freedesktop.DBus.Peer", NULL))
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (object_path_startswith("/org/freedesktop/systemd1", path)) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = selinux_access_check(bus, message, verb, error);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt if (streq_ptr(path, "/org/freedesktop/systemd1/unit/self")) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = manager_get_job_from_dbus_path(m, path, &j);
435fc3176520a58f1c20ccb983c9fb40b30a1471Martin Pitt manager_load_unit_from_dbus_path(m, path, NULL, &u);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = selinux_unit_access_check(u, bus, message, verb, error);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidtstatic int bus_job_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = manager_get_job_from_dbus_path(m, path, &j);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidtstatic Unit *find_unit(Manager *m, sd_bus *bus, const char *path) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt if (streq_ptr(path, "/org/freedesktop/systemd1/unit/self")) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = manager_load_unit_from_dbus_path(m, path, NULL, &u);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidtstatic int bus_unit_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidtstatic int bus_unit_interface_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (!streq_ptr(interface, UNIT_VTABLE(u)->bus_interface))
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic int bus_unit_cgroup_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (!streq_ptr(interface, UNIT_VTABLE(u)->bus_interface))
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidtstatic int bus_cgroup_context_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt if (!streq_ptr(interface, UNIT_VTABLE(u)->bus_interface))
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidtstatic int bus_exec_context_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
e1323fbfbe8a574f28b704f2df8ce7f99e3a28f5Michal Schmidt if (!streq_ptr(interface, UNIT_VTABLE(u)->bus_interface))
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic int bus_kill_context_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (!streq_ptr(interface, UNIT_VTABLE(u)->bus_interface))
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic int bus_job_enumerate(sd_bus *bus, const char *path, char ***nodes, void *userdata) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt unsigned k = 0;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidtstatic int bus_unit_enumerate(sd_bus *bus, const char *path, char ***nodes, void *userdata) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt unsigned k = 0;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic int bus_setup_api_vtables(Manager *m, sd_bus *bus) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = sd_bus_add_filter(bus, selinux_filter, m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_error("Failed to add SELinux access filter: %s", strerror(-r));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = sd_bus_add_object_vtable(bus, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", bus_manager_vtable, m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_error("Failed to register Manager vtable: %s", strerror(-r));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = sd_bus_add_fallback_vtable(bus, "/org/freedesktop/systemd1/job", "org.freedesktop.systemd1.Job", bus_job_vtable, bus_job_find, m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_error("Failed to register Job vtable: %s", strerror(-r));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = sd_bus_add_node_enumerator(bus, "/org/freedesktop/systemd1/job", bus_job_enumerate, m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_error("Failed to add job enumerator: %s", strerror(-r));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = sd_bus_add_fallback_vtable(bus, "/org/freedesktop/systemd1/unit", "org.freedesktop.systemd1.Unit", bus_unit_vtable, bus_unit_find, m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_error("Failed to register Unit vtable: %s", strerror(-r));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = sd_bus_add_node_enumerator(bus, "/org/freedesktop/systemd1/unit", bus_unit_enumerate, m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_error("Failed to add job enumerator: %s", strerror(-r));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt for (t = 0; t < _UNIT_TYPE_MAX; t++) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = sd_bus_add_fallback_vtable(bus, "/org/freedesktop/systemd1/unit", unit_vtable[t]->bus_interface, unit_vtable[t]->bus_vtable, bus_unit_interface_find, m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_error("Failed to register type specific vtable for %s: %s", unit_vtable[t]->bus_interface, strerror(-r));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (unit_vtable[t]->cgroup_context_offset > 0) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = sd_bus_add_fallback_vtable(bus, "/org/freedesktop/systemd1/unit", unit_vtable[t]->bus_interface, bus_unit_cgroup_vtable, bus_unit_cgroup_find, m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_error("Failed to register control group unit vtable for %s: %s", unit_vtable[t]->bus_interface, strerror(-r));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = sd_bus_add_fallback_vtable(bus, "/org/freedesktop/systemd1/unit", unit_vtable[t]->bus_interface, bus_cgroup_vtable, bus_cgroup_context_find, m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_error("Failed to register control group vtable for %s: %s", unit_vtable[t]->bus_interface, strerror(-r));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (unit_vtable[t]->exec_context_offset > 0) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = sd_bus_add_fallback_vtable(bus, "/org/freedesktop/systemd1/unit", unit_vtable[t]->bus_interface, bus_exec_vtable, bus_exec_context_find, m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_error("Failed to register execute vtable for %s: %s", unit_vtable[t]->bus_interface, strerror(-r));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (unit_vtable[t]->kill_context_offset > 0) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = sd_bus_add_fallback_vtable(bus, "/org/freedesktop/systemd1/unit", unit_vtable[t]->bus_interface, bus_kill_vtable, bus_kill_context_find, m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_error("Failed to register kill vtable for %s: %s", unit_vtable[t]->bus_interface, strerror(-r));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic int bus_setup_disconnected_match(Manager *m, sd_bus *bus) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt "type='signal',"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt "interface='org.freedesktop.DBus.Local',"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt "member='Disconnected'",
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_error("Failed to register match for Disconnected message: %s", strerror(-r));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidtstatic int bus_on_connection(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt nfd = accept4(fd, NULL, NULL, SOCK_NONBLOCK|SOCK_CLOEXEC);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt log_warning("Failed to accept private connection, ignoring: %m");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (set_size(m->private_buses) >= CONNECTIONS_MAX) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_warning("Too many concurrent connections, refusing");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = set_ensure_allocated(&m->private_buses, trivial_hash_func, trivial_compare_func);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_warning("Failed to allocate new private connection bus: %s", strerror(-r));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt log_warning("Failed to set fd on new connection bus: %s", strerror(-r));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt log_warning("Incoming private connection from unprivileged client, refusing: %s", strerror(-r));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt log_warning("Failed to enable server support for new connection bus: %s", strerror(-r));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt log_warning("Failed to start new connection bus: %s", strerror(-r));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = sd_bus_attach_event(bus, m->event, SD_EVENT_PRIORITY_NORMAL);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt log_warning("Failed to attach new connection bus to event loop: %s", strerror(-r));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt /* When we run as system instance we get the Released
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt * signal via a direct connection */
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt "type='signal',"
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen "interface='org.freedesktop.systemd1.Agent',"
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen "member='Released',"
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt log_warning("Failed to register Released match on new connection bus: %s", strerror(-r));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt log_warning("Failed to set up API vtables on new connection bus: %s", strerror(-r));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt log_warning("Failed to add new conenction bus to set: %s", strerror(-r));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt log_debug("Accepted new private connection.");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic int bus_list_names(Manager *m, sd_bus *bus) {
ce79279bff6e7a1a17070509a039ab635796f129Michal Schmidt _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt "org.freedesktop.DBus",
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt "org.freedesktop.DBus",
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt log_error("Failed to get initial list of names: %s", bus_error_message(&error, r));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = sd_bus_message_enter_container(reply, 'a', "s");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt /* This is a bit hacky, we say the owner of the name is the
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt * name itself, because we don't want the extra traffic to
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt * figure out the real owner. */
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt while ((r = sd_bus_message_read(reply, "s", &name)) > 0)
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt manager_dispatch_bus_name_owner_changed(m, name, NULL, name);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic int bus_setup_api(Manager *m, sd_bus *bus) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt "type='signal',"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt "sender='org.freedesktop.DBus',"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt "interface='org.freedesktop.DBus',"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt "member='NameOwnerChanged'",
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_warning("Failed to subscribe to NameOwnerChanged signal: %s", strerror(-r));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt "type='signal',"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt "sender='org.freedesktop.DBus',"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt "interface='org.freedesktop.systemd1.Activator',"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt "member='ActivationRequest'",
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_warning("Failed to subscribe to activation signal: %s", strerror(-r));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt /* Allow replacing of our name, to ease implementation of
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * reexecution, where we keep the old connection open until
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * after the new connection is set up and the name installed
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt * to allow clients to synchronously wait for reexecution to
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = sd_bus_request_name(bus,"org.freedesktop.systemd1", SD_BUS_NAME_ALLOW_REPLACEMENT|SD_BUS_NAME_REPLACE_EXISTING);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_error("Failed to register name: %s", strerror(-r));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_debug("Successfully connected to API bus.");
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt /* The API and system bus is the same if we are running in system mode */
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt if (m->running_as == SYSTEMD_SYSTEM && m->system_bus)
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_debug("Failed to connect to API bus, retrying later...");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = sd_bus_attach_event(bus, m->event, SD_EVENT_PRIORITY_NORMAL);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_error("Failed to attach API bus to event loop: %s", strerror(-r));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt log_error("Failed to set up API bus: %s", strerror(-r));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic int bus_setup_system(Manager *m, sd_bus *bus) {
assert(m);
r = sd_bus_add_match(
bus,
"interface='org.freedesktop.systemd1.Agent',"
"path='/org/freedesktop/systemd1/agent'",
if (m->system_bus)
sd_event_source *s;
assert(m);
if (m->private_listen_fd >= 0)
return -EHOSTDOWN;
if (fd < 0) {
return -errno;
return -errno;
return -errno;
m->private_listen_event_source = s;
if (try_bus_connect) {
r = bus_init_system(m);
r = bus_init_api(m);
r = bus_init_private(m);
Iterator i;
Job *j;
assert(m);
if (!*bus)
if (m->queued_message)
sd_bus *b;
assert(m);
if (m->api_bus)
if (m->system_bus)
destroy_bus(m, &b);
if (m->private_listen_event_source)
if (m->private_listen_fd >= 0) {
Iterator i;
sd_bus *b;
int fd;
assert(m);
if (m->api_bus) {
if (fd >= 0) {
if (fd < 0)
return fd;
if (fd >= 0) {
if (fd < 0)
return fd;
assert(m);
assert(f);
assert(m);