X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fdbus.c;h=d7b80ba01d17c9bbe8d31ad368b179784c349f11;hp=8c969eab630c6879968a38b3e5a36c19d6cab475;hb=2633eb8317623138f585957fcf8337a99fb1528f;hpb=8f6df3fa98ee74eaf5c34dddd272d2e3c10c3c27 diff --git a/src/dbus.c b/src/dbus.c index 8c969eab6..d7b80ba01 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -401,7 +401,7 @@ static DBusHandlerResult api_bus_message_filter(DBusConnection *connection, DBus if (r < 0) { const char *id, *text; - log_warning("D-Bus activation failed for %s: %s", name, strerror(-r)); + log_debug("D-Bus activation failed for %s: %s", name, strerror(-r)); if (!(reply = dbus_message_new_signal("/org/freedesktop/systemd1", "org.freedesktop.systemd1.Activator", "ActivationFailure"))) goto oom; @@ -464,7 +464,9 @@ static DBusHandlerResult system_bus_message_filter(DBusConnection *connection, D log_debug("System D-Bus connection terminated."); bus_done_system(m); - } else if (dbus_message_is_signal(message, "org.freedesktop.systemd1.Agent", "Released")) { + } else if (m->running_as != MANAGER_SYSTEM && + dbus_message_is_signal(message, "org.freedesktop.systemd1.Agent", "Released")) { + const char *cgroup; if (!dbus_message_get_args(message, &error, @@ -498,7 +500,9 @@ static DBusHandlerResult private_bus_message_filter(DBusConnection *connection, if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconnected")) shutdown_connection(m, connection); - else if (dbus_message_is_signal(message, "org.freedesktop.systemd1.Agent", "Released")) { + else if (m->running_as == MANAGER_SYSTEM && + dbus_message_is_signal(message, "org.freedesktop.systemd1.Agent", "Released")) { + const char *cgroup; if (!dbus_message_get_args(message, &error, @@ -507,6 +511,12 @@ static DBusHandlerResult private_bus_message_filter(DBusConnection *connection, log_error("Failed to parse Released message: %s", error.message); else cgroup_notify_empty(m, cgroup); + + /* Forward the message to the system bus, so that user + * instances are notified as well */ + + if (m->system_bus) + dbus_connection_send(m->system_bus, message, NULL); } dbus_error_free(&error); @@ -808,17 +818,19 @@ static int bus_init_system(Manager *m) { goto fail; } - dbus_bus_add_match(m->system_bus, - "type='signal'," - "interface='org.freedesktop.systemd1.Agent'," - "member='Released'," - "path='/org/freedesktop/systemd1/agent'", - &error); - - if (dbus_error_is_set(&error)) { - log_error("Failed to register match: %s", error.message); - r = -EIO; - goto fail; + if (m->running_as != MANAGER_SYSTEM) { + dbus_bus_add_match(m->system_bus, + "type='signal'," + "interface='org.freedesktop.systemd1.Agent'," + "member='Released'," + "path='/org/freedesktop/systemd1/agent'", + &error); + + if (dbus_error_is_set(&error)) { + log_error("Failed to register match: %s", error.message); + r = -EIO; + goto fail; + } } if (m->api_bus != m->system_bus) { @@ -852,7 +864,7 @@ static int bus_init_api(Manager *m) { 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))) { + if (!(m->api_bus = dbus_bus_get_private(m->running_as == MANAGER_USER ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, &error))) { log_debug("Failed to get API D-Bus connection, retrying later: %s", error.message); r = 0; goto fail; @@ -970,7 +982,7 @@ fail: return r; } -int bus_init(Manager *m) { +int bus_init(Manager *m, bool try_bus_connect) { int r; if (set_ensure_allocated(&m->bus_connections, trivial_hash_func, trivial_compare_func) < 0 || @@ -986,14 +998,18 @@ int bus_init(Manager *m) { } if (m->subscribed_data_slot < 0) - if (!dbus_pending_call_allocate_data_slot(&m->subscribed_data_slot)) { + if (!dbus_connection_allocate_data_slot(&m->subscribed_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) + if (try_bus_connect) { + if ((r = bus_init_system(m)) < 0 || + (r = bus_init_api(m)) < 0) + return r; + } + + if ((r = bus_init_private(m)) < 0) return r; return 0; @@ -1098,7 +1114,7 @@ void bus_done(Manager *m) { dbus_pending_call_free_data_slot(&m->name_data_slot); if (m->subscribed_data_slot >= 0) - dbus_pending_call_free_data_slot(&m->subscribed_data_slot); + dbus_connection_free_data_slot(&m->subscribed_data_slot); } static void query_pid_pending_cb(DBusPendingCall *pending, void *userdata) {