dbus.c | dbus.c | |||
---|---|---|---|---|
skipping to change at line 33 | skipping to change at line 33 | |||
#include <sys/timerfd.h> | #include <sys/timerfd.h> | |||
#include <errno.h> | #include <errno.h> | |||
#include <unistd.h> | #include <unistd.h> | |||
#include <dbus/dbus.h> | #include <dbus/dbus.h> | |||
#include "dbus.h" | #include "dbus.h" | |||
#include "log.h" | #include "log.h" | |||
#include "strv.h" | #include "strv.h" | |||
#include "cgroup.h" | #include "cgroup.h" | |||
#include "mkdir.h" | #include "mkdir.h" | |||
#include "missing.h" | ||||
#include "dbus-unit.h" | #include "dbus-unit.h" | |||
#include "dbus-job.h" | #include "dbus-job.h" | |||
#include "dbus-manager.h" | #include "dbus-manager.h" | |||
#include "dbus-service.h" | #include "dbus-service.h" | |||
#include "dbus-socket.h" | #include "dbus-socket.h" | |||
#include "dbus-target.h" | #include "dbus-target.h" | |||
#include "dbus-device.h" | #include "dbus-device.h" | |||
#include "dbus-mount.h" | #include "dbus-mount.h" | |||
#include "dbus-automount.h" | #include "dbus-automount.h" | |||
#include "dbus-snapshot.h" | #include "dbus-snapshot.h" | |||
skipping to change at line 447 | skipping to change at line 448 | |||
dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_SIGNAL)) | dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_SIGNAL)) | |||
log_debug("Got D-Bus request on system bus: %s.%s() on %s", | log_debug("Got D-Bus request on system bus: %s.%s() on %s", | |||
dbus_message_get_interface(message), | dbus_message_get_interface(message), | |||
dbus_message_get_member(message), | dbus_message_get_member(message), | |||
dbus_message_get_path(message)); | dbus_message_get_path(message)); | |||
if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconne cted")) { | if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconne cted")) { | |||
log_debug("System D-Bus connection terminated."); | log_debug("System D-Bus connection terminated."); | |||
bus_done_system(m); | bus_done_system(m); | |||
} else if (m->running_as != MANAGER_SYSTEM && | } else if (m->running_as != SYSTEMD_SYSTEM && | |||
dbus_message_is_signal(message, "org.freedesktop.systemd 1.Agent", "Released")) { | dbus_message_is_signal(message, "org.freedesktop.systemd 1.Agent", "Released")) { | |||
const char *cgroup; | const char *cgroup; | |||
if (!dbus_message_get_args(message, &error, | if (!dbus_message_get_args(message, &error, | |||
DBUS_TYPE_STRING, &cgroup, | DBUS_TYPE_STRING, &cgroup, | |||
DBUS_TYPE_INVALID)) | DBUS_TYPE_INVALID)) | |||
log_error("Failed to parse Released message: %s", b us_error_message(&error)); | log_error("Failed to parse Released message: %s", b us_error_message(&error)); | |||
else | else | |||
cgroup_notify_empty(m, cgroup); | cgroup_notify_empty(m, cgroup); | |||
skipping to change at line 483 | skipping to change at line 484 | |||
if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_METHOD_CALL || | if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_METHOD_CALL || | |||
dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_SIGNAL) | dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_SIGNAL) | |||
log_debug("Got D-Bus request: %s.%s() on %s", | log_debug("Got D-Bus request: %s.%s() on %s", | |||
dbus_message_get_interface(message), | dbus_message_get_interface(message), | |||
dbus_message_get_member(message), | dbus_message_get_member(message), | |||
dbus_message_get_path(message)); | dbus_message_get_path(message)); | |||
if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconne cted")) | if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconne cted")) | |||
shutdown_connection(m, connection); | shutdown_connection(m, connection); | |||
else if (m->running_as == MANAGER_SYSTEM && | else if (m->running_as == SYSTEMD_SYSTEM && | |||
dbus_message_is_signal(message, "org.freedesktop.systemd1. Agent", "Released")) { | dbus_message_is_signal(message, "org.freedesktop.systemd1. Agent", "Released")) { | |||
const char *cgroup; | const char *cgroup; | |||
if (!dbus_message_get_args(message, &error, | if (!dbus_message_get_args(message, &error, | |||
DBUS_TYPE_STRING, &cgroup, | DBUS_TYPE_STRING, &cgroup, | |||
DBUS_TYPE_INVALID)) | DBUS_TYPE_INVALID)) | |||
log_error("Failed to parse Released message: %s", b us_error_message(&error)); | log_error("Failed to parse Released message: %s", b us_error_message(&error)); | |||
else | else | |||
cgroup_notify_empty(m, cgroup); | cgroup_notify_empty(m, cgroup); | |||
skipping to change at line 778 | skipping to change at line 779 | |||
dbus_connection_ref(new_connection); | dbus_connection_ref(new_connection); | |||
} | } | |||
static int init_registered_system_bus(Manager *m) { | static int init_registered_system_bus(Manager *m) { | |||
char *id; | char *id; | |||
if (!dbus_connection_add_filter(m->system_bus, system_bus_message_f ilter, m, NULL)) | if (!dbus_connection_add_filter(m->system_bus, system_bus_message_f ilter, m, NULL)) | |||
return log_oom(); | return log_oom(); | |||
if (m->running_as != MANAGER_SYSTEM) { | if (m->running_as != SYSTEMD_SYSTEM) { | |||
DBusError error; | DBusError error; | |||
dbus_error_init(&error); | dbus_error_init(&error); | |||
dbus_bus_add_match(m->system_bus, | dbus_bus_add_match(m->system_bus, | |||
"type='signal'," | "type='signal'," | |||
"interface='org.freedesktop.systemd1.Age nt'," | "interface='org.freedesktop.systemd1.Age nt'," | |||
"member='Released'," | "member='Released'," | |||
"path='/org/freedesktop/systemd1/agent'" , | "path='/org/freedesktop/systemd1/agent'" , | |||
&error); | &error); | |||
skipping to change at line 840 | skipping to change at line 841 | |||
NULL); | NULL); | |||
r = request_name(m); | r = request_name(m); | |||
if (r < 0) | if (r < 0) | |||
return r; | return r; | |||
r = query_name_list(m); | r = query_name_list(m); | |||
if (r < 0) | if (r < 0) | |||
return r; | return r; | |||
if (m->running_as == MANAGER_USER) { | if (m->running_as == SYSTEMD_USER) { | |||
char *id; | char *id; | |||
log_debug("Successfully connected to API D-Bus bus %s as %s ", | log_debug("Successfully connected to API D-Bus bus %s as %s ", | |||
strnull((id = dbus_connection_get_server_id(m->api _bus))), | strnull((id = dbus_connection_get_server_id(m->api _bus))), | |||
strnull(dbus_bus_get_unique_name(m->api_bus))); | strnull(dbus_bus_get_unique_name(m->api_bus))); | |||
dbus_free(id); | dbus_free(id); | |||
} else | } else | |||
log_debug("Successfully initialized API on the system bus") ; | log_debug("Successfully initialized API on the system bus") ; | |||
return 0; | return 0; | |||
} | } | |||
skipping to change at line 891 | skipping to change at line 892 | |||
log_debug("Received name %s in reply to Hello", name); | log_debug("Received name %s in reply to Hello", name); | |||
if (!dbus_bus_set_unique_name(*conn, name)) { | if (!dbus_bus_set_unique_name(*conn, name)) { | |||
log_error("Failed to set unique name"); | log_error("Failed to set unique name"); | |||
r = -1; | r = -1; | |||
break; | break; | |||
} | } | |||
if (conn == &m->system_bus) { | if (conn == &m->system_bus) { | |||
r = init_registered_system_bus(m); | r = init_registered_system_bus(m); | |||
if (r == 0 && m->running_as == MANAGER_SYSTEM) | if (r == 0 && m->running_as == SYSTEMD_SYSTEM) | |||
r = init_registered_api_bus(m); | r = init_registered_api_bus(m); | |||
} else | } else | |||
r = init_registered_api_bus(m); | r = init_registered_api_bus(m); | |||
break; | break; | |||
default: | default: | |||
assert_not_reached("Invalid reply message"); | assert_not_reached("Invalid reply message"); | |||
} | } | |||
dbus_message_unref(reply); | dbus_message_unref(reply); | |||
skipping to change at line 958 | skipping to change at line 959 | |||
return -ENOMEM; | return -ENOMEM; | |||
} | } | |||
static DBusConnection* manager_bus_connect_private(Manager *m, DBusBusType type) { | static DBusConnection* manager_bus_connect_private(Manager *m, DBusBusType type) { | |||
const char *address; | const char *address; | |||
DBusConnection *connection; | DBusConnection *connection; | |||
DBusError error; | DBusError error; | |||
switch (type) { | switch (type) { | |||
case DBUS_BUS_SYSTEM: | case DBUS_BUS_SYSTEM: | |||
address = getenv("DBUS_SYSTEM_BUS_ADDRESS"); | address = secure_getenv("DBUS_SYSTEM_BUS_ADDRESS"); | |||
if (!address || !address[0]) | if (!address || !address[0]) | |||
address = DBUS_SYSTEM_BUS_DEFAULT_ADDRESS; | address = DBUS_SYSTEM_BUS_DEFAULT_ADDRESS; | |||
break; | break; | |||
case DBUS_BUS_SESSION: | case DBUS_BUS_SESSION: | |||
address = getenv("DBUS_SESSION_BUS_ADDRESS"); | address = secure_getenv("DBUS_SESSION_BUS_ADDRESS"); | |||
if (!address || !address[0]) | if (!address || !address[0]) | |||
address = DBUS_SESSION_BUS_DEFAULT_ADDRESS; | address = DBUS_SESSION_BUS_DEFAULT_ADDRESS; | |||
break; | break; | |||
default: | default: | |||
assert_not_reached("Invalid bus type"); | assert_not_reached("Invalid bus type"); | |||
} | } | |||
dbus_error_init(&error); | dbus_error_init(&error); | |||
connection = dbus_connection_open_private(address, &error); | connection = dbus_connection_open_private(address, &error); | |||
skipping to change at line 1021 | skipping to change at line 1022 | |||
return r; | return r; | |||
} | } | |||
static int bus_init_api(Manager *m) { | static int bus_init_api(Manager *m) { | |||
int r; | int r; | |||
if (m->api_bus) | if (m->api_bus) | |||
return 0; | return 0; | |||
if (m->running_as == MANAGER_SYSTEM) { | if (m->running_as == SYSTEMD_SYSTEM) { | |||
m->api_bus = m->system_bus; | m->api_bus = m->system_bus; | |||
/* In this mode there is no distinct connection to the API bus, | /* In this mode there is no distinct connection to the API bus, | |||
* the API is published on the system bus. | * the API is published on the system bus. | |||
* bus_register_cb() is aware of that and will init the API | * bus_register_cb() is aware of that and will init the API | |||
* when the system bus gets registered. | * when the system bus gets registered. | |||
* No need to setup anything here. */ | * No need to setup anything here. */ | |||
return 0; | return 0; | |||
} | } | |||
m->api_bus = manager_bus_connect_private(m, DBUS_BUS_SESSION); | m->api_bus = manager_bus_connect_private(m, DBUS_BUS_SESSION); | |||
skipping to change at line 1068 | skipping to change at line 1069 | |||
NULL | NULL | |||
}; | }; | |||
assert(m); | assert(m); | |||
dbus_error_init(&error); | dbus_error_init(&error); | |||
if (m->private_bus) | if (m->private_bus) | |||
return 0; | return 0; | |||
if (m->running_as == MANAGER_SYSTEM) { | if (m->running_as == SYSTEMD_SYSTEM) { | |||
/* We want the private bus only when running as init */ | /* We want the private bus only when running as init */ | |||
if (getpid() != 1) | if (getpid() != 1) | |||
return 0; | return 0; | |||
unlink("/run/systemd/private"); | unlink("/run/systemd/private"); | |||
m->private_bus = dbus_server_listen("unix:path=/run/systemd /private", &error); | m->private_bus = dbus_server_listen("unix:path=/run/systemd /private", &error); | |||
} else { | } else { | |||
const char *e; | const char *e; | |||
char *p; | char *p; | |||
e = getenv("XDG_RUNTIME_DIR"); | e = secure_getenv("XDG_RUNTIME_DIR"); | |||
if (!e) | if (!e) | |||
return 0; | return 0; | |||
if (asprintf(&p, "unix:path=%s/systemd/private", e) < 0) { | if (asprintf(&p, "unix:path=%s/systemd/private", e) < 0) { | |||
r = log_oom(); | r = log_oom(); | |||
goto fail; | goto fail; | |||
} | } | |||
mkdir_parents_label(p+10, 0755); | mkdir_parents_label(p+10, 0755); | |||
unlink(p+10); | unlink(p+10); | |||
skipping to change at line 1192 | skipping to change at line 1193 | |||
m->queued_message_connection = NULL; | m->queued_message_connection = NULL; | |||
if (m->queued_message) { | if (m->queued_message) { | |||
dbus_message_unref(m->queued_message); | dbus_message_unref(m->queued_message); | |||
m->queued_message = NULL; | m->queued_message = NULL; | |||
} | } | |||
} | } | |||
dbus_connection_set_dispatch_status_function(c, NULL, NULL, NULL); | dbus_connection_set_dispatch_status_function(c, NULL, NULL, NULL); | |||
/* system manager cannot afford to block on DBus */ | /* system manager cannot afford to block on DBus */ | |||
if (m->running_as != MANAGER_SYSTEM) | if (m->running_as != SYSTEMD_SYSTEM) | |||
dbus_connection_flush(c); | dbus_connection_flush(c); | |||
dbus_connection_close(c); | dbus_connection_close(c); | |||
dbus_connection_unref(c); | dbus_connection_unref(c); | |||
} | } | |||
static void bus_done_api(Manager *m) { | static void bus_done_api(Manager *m) { | |||
if (!m->api_bus) | if (!m->api_bus) | |||
return; | return; | |||
if (m->running_as == MANAGER_USER) | if (m->running_as == SYSTEMD_USER) | |||
shutdown_connection(m, m->api_bus); | shutdown_connection(m, m->api_bus); | |||
m->api_bus = NULL; | m->api_bus = NULL; | |||
if (m->queued_message) { | if (m->queued_message) { | |||
dbus_message_unref(m->queued_message); | dbus_message_unref(m->queued_message); | |||
m->queued_message = NULL; | m->queued_message = NULL; | |||
} | } | |||
} | } | |||
static void bus_done_system(Manager *m) { | static void bus_done_system(Manager *m) { | |||
if (!m->system_bus) | if (!m->system_bus) | |||
return; | return; | |||
if (m->running_as == MANAGER_SYSTEM) | if (m->running_as == SYSTEMD_SYSTEM) | |||
bus_done_api(m); | bus_done_api(m); | |||
shutdown_connection(m, m->system_bus); | shutdown_connection(m, m->system_bus); | |||
m->system_bus = NULL; | m->system_bus = NULL; | |||
} | } | |||
static void bus_done_private(Manager *m) { | static void bus_done_private(Manager *m) { | |||
if (!m->private_bus) | if (!m->private_bus) | |||
return; | return; | |||
skipping to change at line 1364 | skipping to change at line 1365 | |||
int bus_broadcast(Manager *m, DBusMessage *message) { | int bus_broadcast(Manager *m, DBusMessage *message) { | |||
bool oom = false; | bool oom = false; | |||
Iterator i; | Iterator i; | |||
DBusConnection *c; | DBusConnection *c; | |||
assert(m); | assert(m); | |||
assert(message); | assert(message); | |||
SET_FOREACH(c, m->bus_connections_for_dispatch, i) | SET_FOREACH(c, m->bus_connections_for_dispatch, i) | |||
if (c != m->system_bus || m->running_as == MANAGER_SYSTEM) | if (c != m->system_bus || m->running_as == SYSTEMD_SYSTEM) | |||
oom = !dbus_connection_send(c, message, NULL); | oom = !dbus_connection_send(c, message, NULL); | |||
SET_FOREACH(c, m->bus_connections, i) | SET_FOREACH(c, m->bus_connections, i) | |||
if (c != m->system_bus || m->running_as == MANAGER_SYSTEM) | if (c != m->system_bus || m->running_as == SYSTEMD_SYSTEM) | |||
oom = !dbus_connection_send(c, message, NULL); | oom = !dbus_connection_send(c, message, NULL); | |||
return oom ? -ENOMEM : 0; | return oom ? -ENOMEM : 0; | |||
} | } | |||
bool bus_has_subscriber(Manager *m) { | bool bus_has_subscriber(Manager *m) { | |||
Iterator i; | Iterator i; | |||
DBusConnection *c; | DBusConnection *c; | |||
assert(m); | assert(m); | |||
skipping to change at line 1439 | skipping to change at line 1440 | |||
if (fd < 0) | if (fd < 0) | |||
return fd; | return fd; | |||
} | } | |||
} | } | |||
return 0; | return 0; | |||
} | } | |||
void bus_broadcast_finished( | void bus_broadcast_finished( | |||
Manager *m, | Manager *m, | |||
usec_t firmware_usec, | ||||
usec_t loader_usec, | ||||
usec_t kernel_usec, | usec_t kernel_usec, | |||
usec_t initrd_usec, | usec_t initrd_usec, | |||
usec_t userspace_usec, | usec_t userspace_usec, | |||
usec_t total_usec) { | usec_t total_usec) { | |||
DBusMessage *message; | DBusMessage *message; | |||
assert(m); | assert(m); | |||
message = dbus_message_new_signal("/org/freedesktop/systemd1", "org .freedesktop.systemd1.Manager", "StartupFinished"); | message = dbus_message_new_signal("/org/freedesktop/systemd1", "org .freedesktop.systemd1.Manager", "StartupFinished"); | |||
if (!message) { | if (!message) { | |||
log_oom(); | log_oom(); | |||
return; | return; | |||
} | } | |||
assert_cc(sizeof(usec_t) == sizeof(uint64_t)); | assert_cc(sizeof(usec_t) == sizeof(uint64_t)); | |||
if (!dbus_message_append_args(message, | if (!dbus_message_append_args(message, | |||
DBUS_TYPE_UINT64, &firmware_usec, | ||||
DBUS_TYPE_UINT64, &loader_usec, | ||||
DBUS_TYPE_UINT64, &kernel_usec, | DBUS_TYPE_UINT64, &kernel_usec, | |||
DBUS_TYPE_UINT64, &initrd_usec, | DBUS_TYPE_UINT64, &initrd_usec, | |||
DBUS_TYPE_UINT64, &userspace_usec, | DBUS_TYPE_UINT64, &userspace_usec, | |||
DBUS_TYPE_UINT64, &total_usec, | DBUS_TYPE_UINT64, &total_usec, | |||
DBUS_TYPE_INVALID)) { | DBUS_TYPE_INVALID)) { | |||
log_oom(); | log_oom(); | |||
goto finish; | goto finish; | |||
} | } | |||
if (bus_broadcast(m, message) < 0) { | if (bus_broadcast(m, message) < 0) { | |||
End of changes. 18 change blocks. | ||||
15 lines changed or deleted | 20 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |