Copyright 2010 Lennart Poettering
systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
+ Lesser General Public License for more details.
- You should have received a copy of the GNU General Public License
+ You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "strv.h"
#include "cgroup.h"
#include "mkdir.h"
+#include "missing.h"
#include "dbus-unit.h"
#include "dbus-job.h"
#include "dbus-manager.h"
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)) {
- log_error("Not enough memory");
- return -ENOMEM;
- }
+ !dbus_connection_set_timeout_functions(bus, bus_add_timeout, bus_remove_timeout, bus_toggle_timeout, m, NULL))
+ return log_oom();
- if (set_put(m->bus_connections_for_dispatch, bus) < 0) {
- log_error("Not enough memory");
- return -ENOMEM;
- }
+ if (set_put(m->bus_connections_for_dispatch, bus) < 0)
+ return log_oom();
dbus_connection_set_dispatch_status_function(bus, bus_dispatch_status, m, NULL);
return 0;
!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.");
+ log_oom();
return;
}
static int init_registered_system_bus(Manager *m) {
char *id;
- if (!dbus_connection_add_filter(m->system_bus, system_bus_message_filter, m, NULL)) {
- log_error("Not enough memory");
- return -ENOMEM;
- }
+ if (!dbus_connection_add_filter(m->system_bus, system_bus_message_filter, m, NULL))
+ return log_oom();
if (m->running_as != MANAGER_SYSTEM) {
DBusError error;
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)) {
- log_error("Not enough memory");
- return -ENOMEM;
- }
+ !dbus_connection_add_filter(m->api_bus, api_bus_message_filter, m, NULL))
+ return log_oom();
/* Get NameOwnerChange messages */
dbus_bus_add_match(m->api_bus,
switch (type) {
case DBUS_BUS_SYSTEM:
- address = getenv("DBUS_SYSTEM_BUS_ADDRESS");
+ address = secure_getenv("DBUS_SYSTEM_BUS_ADDRESS");
if (!address || !address[0])
address = DBUS_SYSTEM_BUS_DEFAULT_ADDRESS;
break;
case DBUS_BUS_SESSION:
- address = getenv("DBUS_SESSION_BUS_ADDRESS");
+ address = secure_getenv("DBUS_SESSION_BUS_ADDRESS");
if (!address || !address[0])
address = DBUS_SESSION_BUS_DEFAULT_ADDRESS;
break;
const char *e;
char *p;
- e = getenv("XDG_RUNTIME_DIR");
+ e = secure_getenv("XDG_RUNTIME_DIR");
if (!e)
return 0;
if (asprintf(&p, "unix:path=%s/systemd/private", e) < 0) {
- log_error("Not enough memory");
- r = -ENOMEM;
+ r = log_oom();
goto fail;
}
- mkdir_parents(p+10, 0755);
+ mkdir_parents_label(p+10, 0755);
unlink(p+10);
m->private_bus = dbus_server_listen(p, &error);
free(p);
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;
+ r = log_oom();
goto fail;
}
return 0;
oom:
- log_error("Not enough memory");
- return -ENOMEM;
+ return log_oom();
}
static void shutdown_connection(Manager *m, DBusConnection *c) {
Job *j;
Iterator i;
- HASHMAP_FOREACH(j, m->jobs, i)
- if (j->bus == c) {
- free(j->bus_client);
- j->bus_client = NULL;
-
- j->bus = NULL;
+ HASHMAP_FOREACH(j, m->jobs, i) {
+ JobBusClient *cl, *nextcl;
+ LIST_FOREACH_SAFE(client, cl, nextcl, j->bus_client_list) {
+ if (cl->bus == c) {
+ LIST_REMOVE(JobBusClient, client, j->bus_client_list, cl);
+ free(cl);
+ }
}
+ }
set_remove(m->bus_connections, c);
set_remove(m->bus_connections_for_dispatch, c);
void bus_broadcast_finished(
Manager *m,
+ usec_t firmware_usec,
+ usec_t loader_usec,
usec_t kernel_usec,
usec_t initrd_usec,
usec_t userspace_usec,
message = dbus_message_new_signal("/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartupFinished");
if (!message) {
- log_error("Out of memory.");
+ log_oom();
return;
}
assert_cc(sizeof(usec_t) == sizeof(uint64_t));
if (!dbus_message_append_args(message,
+ DBUS_TYPE_UINT64, &firmware_usec,
+ DBUS_TYPE_UINT64, &loader_usec,
DBUS_TYPE_UINT64, &kernel_usec,
DBUS_TYPE_UINT64, &initrd_usec,
DBUS_TYPE_UINT64, &userspace_usec,
DBUS_TYPE_UINT64, &total_usec,
DBUS_TYPE_INVALID)) {
- log_error("Out of memory.");
+ log_oom();
goto finish;
}
if (bus_broadcast(m, message) < 0) {
- log_error("Out of memory.");
+ log_oom();
goto finish;
}