dbus-manager.c revision ffc227c9568eb0a12dc750761d1e5d68ea125aad
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
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
Lesser General Public License for more details.
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 <errno.h>
#include <unistd.h>
#include "dbus.h"
#include "log.h"
#include "dbus-manager.h"
#include "strv.h"
#include "bus-errors.h"
#include "build.h"
#include "dbus-common.h"
#include "install.h"
#include "selinux-access.h"
#include "watchdog.h"
#include "hwclock.h"
#include "path-util.h"
#include "dbus-unit.h"
#define BUS_MANAGER_INTERFACE_BEGIN \
" <interface name=\"org.freedesktop.systemd1.Manager\">\n"
#define BUS_MANAGER_INTERFACE_METHODS \
" <method name=\"GetUnit\">\n" \
" <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"GetUnitByPID\">\n" \
" <arg name=\"pid\" type=\"u\" direction=\"in\"/>\n" \
" <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"LoadUnit\">\n" \
" <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"StartUnit\">\n" \
" <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"StartUnitReplace\">\n" \
" <arg name=\"old_unit\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"new_unit\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"StopUnit\">\n" \
" <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"ReloadUnit\">\n" \
" <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"RestartUnit\">\n" \
" <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"TryRestartUnit\">\n" \
" <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"ReloadOrRestartUnit\">\n" \
" <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"ReloadOrTryRestartUnit\">\n" \
" <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"KillUnit\">\n" \
" <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"who\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"signal\" type=\"i\" direction=\"in\"/>\n" \
" </method>\n" \
" <method name=\"ResetFailedUnit\">\n" \
" <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
" </method>\n" \
" <method name=\"GetJob\">\n" \
" <arg name=\"id\" type=\"u\" direction=\"in\"/>\n" \
" <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"ClearJobs\"/>\n" \
" <method name=\"ResetFailed\"/>\n" \
" <method name=\"ListUnits\">\n" \
" <arg name=\"units\" type=\"a(ssssssouso)\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"ListJobs\">\n" \
" <arg name=\"jobs\" type=\"a(usssoo)\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"Subscribe\"/>\n" \
" <method name=\"Unsubscribe\"/>\n" \
" <method name=\"Dump\">\n" \
" <arg name=\"dump\" type=\"s\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"CreateSnapshot\">\n" \
" <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"cleanup\" type=\"b\" direction=\"in\"/>\n" \
" <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"Reload\"/>\n" \
" <method name=\"Reexecute\"/>\n" \
" <method name=\"Exit\"/>\n" \
" <method name=\"Reboot\"/>\n" \
" <method name=\"PowerOff\"/>\n" \
" <method name=\"Halt\"/>\n" \
" <method name=\"KExec\"/>\n" \
" <method name=\"SwitchRoot\">\n" \
" <arg name=\"new_root\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"init\" type=\"s\" direction=\"in\"/>\n" \
" </method>\n" \
" <method name=\"SetEnvironment\">\n" \
" <arg name=\"names\" type=\"as\" direction=\"in\"/>\n" \
" </method>\n" \
" <method name=\"UnsetEnvironment\">\n" \
" <arg name=\"names\" type=\"as\" direction=\"in\"/>\n" \
" </method>\n" \
" <method name=\"UnsetAndSetEnvironment\">\n" \
" <arg name=\"unset\" type=\"as\" direction=\"in\"/>\n" \
" <arg name=\"set\" type=\"as\" direction=\"in\"/>\n" \
" </method>\n" \
" <method name=\"ListUnitFiles\">\n" \
" <arg name=\"files\" type=\"a(ss)\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"GetUnitFileState\">\n" \
" <arg name=\"file\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"state\" type=\"s\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"EnableUnitFiles\">\n" \
" <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
" <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
" <arg name=\"force\" type=\"b\" direction=\"in\"/>\n" \
" <arg name=\"carries_install_info\" type=\"b\" direction=\"out\"/>\n" \
" <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"DisableUnitFiles\">\n" \
" <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
" <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
" <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"ReenableUnitFiles\">\n" \
" <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
" <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
" <arg name=\"force\" type=\"b\" direction=\"in\"/>\n" \
" <arg name=\"carries_install_info\" type=\"b\" direction=\"out\"/>\n" \
" <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"LinkUnitFiles\">\n" \
" <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
" <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
" <arg name=\"force\" type=\"b\" direction=\"in\"/>\n" \
" <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"PresetUnitFiles\">\n" \
" <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
" <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
" <arg name=\"force\" type=\"b\" direction=\"in\"/>\n" \
" <arg name=\"carries_install_info\" type=\"b\" direction=\"out\"/>\n" \
" <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"MaskUnitFiles\">\n" \
" <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
" <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
" <arg name=\"force\" type=\"b\" direction=\"in\"/>\n" \
" <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
" </method>\n" \
" <method name=\"UnmaskUnitFiles\">\n" \
" <arg name=\"files\" type=\"as\" direction=\"in\"/>\n" \
" <arg name=\"runtime\" type=\"b\" direction=\"in\"/>\n" \
" <arg name=\"changes\" type=\"a(sss)\" direction=\"out\"/>\n" \
" </method>\n"
#define BUS_MANAGER_INTERFACE_SIGNALS \
" <signal name=\"UnitNew\">\n" \
" <arg name=\"id\" type=\"s\"/>\n" \
" <arg name=\"unit\" type=\"o\"/>\n" \
" </signal>\n" \
" <signal name=\"UnitRemoved\">\n" \
" <arg name=\"id\" type=\"s\"/>\n" \
" <arg name=\"unit\" type=\"o\"/>\n" \
" </signal>\n" \
" <signal name=\"JobNew\">\n" \
" <arg name=\"id\" type=\"u\"/>\n" \
" <arg name=\"job\" type=\"o\"/>\n" \
" <arg name=\"unit\" type=\"s\"/>\n" \
" </signal>\n" \
" <signal name=\"JobRemoved\">\n" \
" <arg name=\"id\" type=\"u\"/>\n" \
" <arg name=\"job\" type=\"o\"/>\n" \
" <arg name=\"unit\" type=\"s\"/>\n" \
" <arg name=\"result\" type=\"s\"/>\n" \
" </signal>" \
" <signal name=\"StartupFinished\">\n" \
" <arg name=\"firmware\" type=\"t\"/>\n" \
" <arg name=\"loader\" type=\"t\"/>\n" \
" <arg name=\"kernel\" type=\"t\"/>\n" \
" <arg name=\"initrd\" type=\"t\"/>\n" \
" <arg name=\"userspace\" type=\"t\"/>\n" \
" <arg name=\"total\" type=\"t\"/>\n" \
" </signal>" \
" <signal name=\"UnitFilesChanged\"/>\n"
#define BUS_MANAGER_INTERFACE_PROPERTIES_GENERAL \
" <property name=\"Version\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"Distribution\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"Features\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"Tainted\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"FirmwareTimestamp\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"FirmwareTimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"LoaderTimestamp\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"LoaderTimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"KernelTimestamp\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"KernelTimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"InitRDTimestamp\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"InitRDTimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"UserspaceTimestamp\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"UserspaceTimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"FinishTimestamp\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"FinishTimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"LogLevel\" type=\"s\" access=\"readwrite\"/>\n" \
" <property name=\"LogTarget\" type=\"s\" access=\"readwrite\"/>\n" \
" <property name=\"NNames\" type=\"u\" access=\"read\"/>\n" \
" <property name=\"NJobs\" type=\"u\" access=\"read\"/>\n" \
" <property name=\"NInstalledJobs\" type=\"u\" access=\"read\"/>\n" \
" <property name=\"NFailedJobs\" type=\"u\" access=\"read\"/>\n" \
" <property name=\"Progress\" type=\"d\" access=\"read\"/>\n" \
" <property name=\"Environment\" type=\"as\" access=\"read\"/>\n" \
" <property name=\"ConfirmSpawn\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"ShowStatus\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"UnitPath\" type=\"as\" access=\"read\"/>\n" \
" <property name=\"ControlGroupHierarchy\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"DefaultControllers\" type=\"as\" access=\"read\"/>\n" \
" <property name=\"DefaultStandardOutput\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"DefaultStandardError\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"RuntimeWatchdogUSec\" type=\"s\" access=\"readwrite\"/>\n" \
" <property name=\"ShutdownWatchdogUSec\" type=\"s\" access=\"readwrite\"/>\n"
#define BUS_MANAGER_INTERFACE_END \
" </interface>\n"
#define BUS_MANAGER_INTERFACE \
#define INTROSPECTION_BEGIN \
"<node>\n" \
#define INTROSPECTION_END \
"</node>\n"
#define INTERFACES_LIST \
"org.freedesktop.systemd1.Manager\0"
const char *t;
assert(i);
assert(m);
if (m->taint_usr)
e = stpcpy(e, "split-usr:");
if (readlink_malloc("/etc/mtab", &p) < 0)
e = stpcpy(e, "mtab-not-symlink:");
else
free(p);
e = stpcpy(e, "cgroups-missing:");
if (hwclock_is_localtime() > 0)
e = stpcpy(e, "local-hwclock:");
/* remove the last ':' */
if (e != buf)
e[-1] = 0;
t = buf;
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t))
return -ENOMEM;
return 0;
}
const char *t;
assert(i);
t = log_target_to_string(log_get_target());
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t))
return -ENOMEM;
return 0;
}
const char *t;
assert(i);
dbus_message_iter_get_basic(i, &t);
return log_set_target_from_string(t);
}
const char *t;
assert(i);
t = log_level_to_string(log_get_max_level());
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t))
return -ENOMEM;
return 0;
}
const char *t;
assert(i);
dbus_message_iter_get_basic(i, &t);
return log_set_max_level_from_string(t);
}
uint32_t u;
assert(i);
assert(m);
u = hashmap_size(m->units);
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT32, &u))
return -ENOMEM;
return 0;
}
uint32_t u;
assert(i);
assert(m);
u = hashmap_size(m->jobs);
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT32, &u))
return -ENOMEM;
return 0;
}
double d;
assert(i);
assert(m);
if (dual_timestamp_is_set(&m->finish_timestamp))
d = 1.0;
else
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_DOUBLE, &d))
return -ENOMEM;
return 0;
}
static DBusMessage *message_from_file_changes(
DBusMessage *m,
unsigned n_changes,
int carries_install_info) {
unsigned i;
if (!reply)
return NULL;
if (carries_install_info >= 0) {
dbus_bool_t b;
b = !!carries_install_info;
goto oom;
}
goto oom;
for (i = 0; i < n_changes; i++) {
goto oom;
}
goto oom;
return reply;
oom:
return NULL;
}
static int bus_manager_send_unit_files_changed(Manager *m) {
DBusMessage *s;
int r;
s = dbus_message_new_signal("/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitFilesChanged");
if (!s)
return -ENOMEM;
r = bus_broadcast(m, s);
return r;
}
static int bus_manager_set_runtime_watchdog_usec(DBusMessageIter *i, const char *property, void *data) {
assert(i);
dbus_message_iter_get_basic(i, t);
return watchdog_set_timeout(t);
}
static const char systemd_property_string[] =
PACKAGE_STRING "\0"
DISTRIBUTION "\0"
static const BusProperty bus_systemd_properties[] = {
{ NULL, }
};
static const BusProperty bus_manager_properties[] = {
{ "FirmwareTimestamp", bus_property_append_uint64, "t", offsetof(Manager, firmware_timestamp.realtime) },
{ "FirmwareTimestampMonotonic", bus_property_append_uint64,"t", offsetof(Manager, firmware_timestamp.monotonic)},
{ "LoaderTimestamp", bus_property_append_uint64, "t", offsetof(Manager, loader_timestamp.realtime) },
{ "LoaderTimestampMonotonic", bus_property_append_uint64, "t", offsetof(Manager, loader_timestamp.monotonic) },
{ "KernelTimestamp", bus_property_append_uint64, "t", offsetof(Manager, kernel_timestamp.realtime) },
{ "KernelTimestampMonotonic", bus_property_append_uint64, "t", offsetof(Manager, kernel_timestamp.monotonic) },
{ "InitRDTimestamp", bus_property_append_uint64, "t", offsetof(Manager, initrd_timestamp.realtime) },
{ "InitRDTimestampMonotonic", bus_property_append_uint64, "t", offsetof(Manager, initrd_timestamp.monotonic) },
{ "UserspaceTimestamp", bus_property_append_uint64, "t", offsetof(Manager, userspace_timestamp.realtime)},
{ "UserspaceTimestampMonotonic", bus_property_append_uint64,"t",offsetof(Manager, userspace_timestamp.monotonic)},
{ "FinishTimestamp", bus_property_append_uint64, "t", offsetof(Manager, finish_timestamp.realtime) },
{ "FinishTimestampMonotonic", bus_property_append_uint64, "t", offsetof(Manager, finish_timestamp.monotonic) },
{ "ControlGroupHierarchy", bus_property_append_string, "s", offsetof(Manager, cgroup_hierarchy), true },
{ "DefaultControllers", bus_property_append_strv, "as", offsetof(Manager, default_controllers), true },
{ "DefaultStandardOutput", bus_manager_append_exec_output, "s", offsetof(Manager, default_std_output) },
{ "DefaultStandardError", bus_manager_append_exec_output, "s", offsetof(Manager, default_std_error) },
{ "RuntimeWatchdogUSec", bus_property_append_usec, "t", offsetof(Manager, runtime_watchdog), false, bus_manager_set_runtime_watchdog_usec },
{ "ShutdownWatchdogUSec", bus_property_append_usec, "t", offsetof(Manager, shutdown_watchdog), false, bus_property_set_usec },
{ NULL, }
};
static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {
int r;
bool reload_if_possible = false;
const char *member;
assert(m);
const char *name;
Unit *u;
if (!dbus_message_get_args(
&error,
u = manager_get_unit(m, name);
if (!u) {
}
if (!reply)
goto oom;
path = unit_dbus_path(u);
if (!path)
goto oom;
if (!dbus_message_append_args(
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetUnitByPID")) {
Unit *u;
if (!dbus_message_get_args(
&error,
if (!u) {
dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "No unit for PID %lu is loaded.", (unsigned long) pid);
}
if (!reply)
goto oom;
path = unit_dbus_path(u);
if (!reply)
goto oom;
if (!dbus_message_append_args(
goto oom;
const char *name;
Unit *u;
if (!dbus_message_get_args(
&error,
if (r < 0)
if (!reply)
goto oom;
path = unit_dbus_path(u);
if (!path)
goto oom;
if (!dbus_message_append_args(
goto oom;
else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "StartUnitReplace"))
else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "TryRestartUnit"))
else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ReloadOrRestartUnit")) {
reload_if_possible = true;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ReloadOrTryRestartUnit")) {
reload_if_possible = true;
Unit *u;
if (!dbus_message_get_args(
&error,
else {
if (who < 0)
}
u = manager_get_unit(m, name);
if (!u) {
}
if (r < 0)
goto oom;
Job *j;
if (!dbus_message_get_args(
&error,
j = manager_get_job(m, id);
if (!j) {
}
if (!reply)
goto oom;
path = job_dbus_path(j);
if (!path)
goto oom;
if (!dbus_message_append_args(
goto oom;
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ResetFailed")) {
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ResetFailedUnit")) {
const char *name;
Unit *u;
if (!dbus_message_get_args(
&error,
u = manager_get_unit(m, name);
if (!u) {
}
if (!reply)
goto oom;
Iterator i;
Unit *u;
const char *k;
if (!reply)
goto oom;
goto oom;
HASHMAP_FOREACH_KEY(u, k, m->units, i) {
Unit *f;
if (k != u->id)
continue;
goto oom;
description = unit_description(u);
f = unit_following(u);
u_path = unit_dbus_path(u);
if (!u_path)
goto oom;
if (u->job) {
goto oom;
}
} else {
job_id = 0;
sjob_type = "";
}
if (u->job)
goto oom;
}
if (u->job)
goto oom;
}
goto oom;
Iterator i;
Job *j;
if (!reply)
goto oom;
goto oom;
HASHMAP_FOREACH(j, m->jobs, i) {
goto oom;
j_path = job_dbus_path(j);
if (!j_path)
goto oom;
if (!u_path) {
goto oom;
}
goto oom;
}
goto oom;
}
goto oom;
char *client;
Set *s;
s = BUS_CONNECTION_SUBSCRIBED(m, connection);
if (!s) {
if (!s)
goto oom;
set_free(s);
goto oom;
}
}
if (!client)
goto oom;
if (r < 0) {
}
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Unsubscribe")) {
char *client;
client = set_remove(BUS_CONNECTION_SUBSCRIBED(m, connection), (char*) bus_message_get_sender_with_fallback(message));
if (!client) {
}
if (!reply)
goto oom;
FILE *f;
if (!reply)
goto oom;
if (!f)
goto oom;
manager_dump_units(m, f, NULL);
manager_dump_jobs(m, f, NULL);
if (ferror(f)) {
fclose(f);
goto oom;
}
fclose(f);
goto oom;
}
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "CreateSnapshot")) {
const char *name;
Snapshot *s;
if (!dbus_message_get_args(
&error,
if (r < 0)
if (!reply)
goto oom;
if (!path)
goto oom;
if (!dbus_message_append_args(
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect")) {
char *introspection = NULL;
FILE *f;
Iterator i;
Unit *u;
Job *j;
const char *k;
if (!reply)
goto oom;
/* We roll our own introspection code here, instead of
* relying on bus_default_message_handler() because we
* need to generate our introspection string
* dynamically. */
if (!f)
goto oom;
fputs(INTROSPECTION_BEGIN, f);
HASHMAP_FOREACH_KEY(u, k, m->units, i) {
char *p;
if (k != u->id)
continue;
p = bus_path_escape(k);
if (!p) {
fclose(f);
goto oom;
}
fprintf(f, "<node name=\"unit/%s\"/>", p);
free(p);
}
HASHMAP_FOREACH(j, m->jobs, i)
fputs(INTROSPECTION_END, f);
if (ferror(f)) {
fclose(f);
goto oom;
}
fclose(f);
if (!introspection)
goto oom;
goto oom;
}
assert(!m->queued_message);
/* Instead of sending the reply back right away, we
* just remember that we need to and then send it
* after the reload is finished. That way the caller
* knows when the reload finished. */
if (!m->queued_message)
goto oom;
m->exit_code = MANAGER_RELOAD;
/* We don't send a reply back here, the client should
* just wait for us disconnecting. */
m->exit_code = MANAGER_REEXECUTE;
if (m->running_as == SYSTEMD_SYSTEM) {
dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Exit is only supported for user service managers.");
}
if (!reply)
goto oom;
m->exit_code = MANAGER_EXIT;
if (m->running_as != SYSTEMD_SYSTEM) {
}
if (!reply)
goto oom;
m->exit_code = MANAGER_REBOOT;
if (m->running_as != SYSTEMD_SYSTEM) {
dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Powering off is only supported for system managers.");
}
if (!reply)
goto oom;
m->exit_code = MANAGER_POWEROFF;
if (m->running_as != SYSTEMD_SYSTEM) {
}
if (!reply)
goto oom;
m->exit_code = MANAGER_HALT;
if (m->running_as != SYSTEMD_SYSTEM) {
}
if (!reply)
goto oom;
m->exit_code = MANAGER_KEXEC;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "SwitchRoot")) {
const char *switch_root, *switch_root_init;
char *u, *v;
int k;
if (!dbus_message_get_args(
&error,
if (m->running_as != SYSTEMD_SYSTEM) {
dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Switching root is only supported for system managers.");
}
/* Safety check */
if (isempty(switch_root_init))
else {
char *p;
if (!p)
goto oom;
free(p);
}
if (k < 0)
u = strdup(switch_root);
if (!u)
goto oom;
if (!isempty(switch_root_init)) {
v = strdup(switch_root_init);
if (!v) {
free(u);
goto oom;
}
} else
v = NULL;
free(m->switch_root);
free(m->switch_root_init);
m->switch_root = u;
m->switch_root_init = v;
if (!reply)
goto oom;
m->exit_code = MANAGER_SWITCH_ROOT;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "SetEnvironment")) {
r = bus_parse_strv(message, &l);
if (r == -ENOMEM)
goto oom;
if (r < 0)
strv_free(l);
if (!e)
goto oom;
if (!reply) {
strv_free(e);
goto oom;
}
strv_free(m->environment);
m->environment = e;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "UnsetEnvironment")) {
r = bus_parse_strv(message, &l);
if (r == -ENOMEM)
goto oom;
if (r < 0)
strv_free(l);
if (!e)
goto oom;
strv_free(e);
goto oom;
}
strv_free(m->environment);
m->environment = e;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "UnsetAndSetEnvironment")) {
goto oom;
if (r == -ENOMEM)
goto oom;
if (r < 0)
if (!dbus_message_iter_next(&iter)) {
}
if (r < 0) {
if (r == -ENOMEM)
goto oom;
}
if (!e) {
goto oom;
}
strv_free(e);
if (!f)
goto oom;
strv_free(f);
goto oom;
}
strv_free(m->environment);
m->environment = f;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ListUnitFiles")) {
Hashmap *h;
Iterator i;
if (!reply)
goto oom;
if (!h)
goto oom;
r = unit_file_get_list(m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER, NULL, h);
if (r < 0) {
}
goto oom;
}
HASHMAP_FOREACH(item, h, i) {
const char *state;
goto oom;
}
}
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetUnitFileState")) {
const char *name;
const char *s;
if (!dbus_message_get_args(
&error,
state = unit_file_get_state(m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER, NULL, name);
if (state < 0)
assert(s);
if (!reply)
goto oom;
if (!dbus_message_append_args(
DBUS_TYPE_STRING, &s,
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "EnableUnitFiles") ||
char **l = NULL;
unsigned n_changes = 0;
int carries_install_info = -1;
goto oom;
r = bus_parse_strv_iter(&iter, &l);
if (r < 0) {
if (r == -ENOMEM)
goto oom;
}
if (!dbus_message_iter_next(&iter) ||
strv_free(l);
}
carries_install_info = r;
carries_install_info = r;
carries_install_info = r;
else
assert_not_reached("Uh? Wrong method");
strv_free(l);
if (r < 0) {
}
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "DisableUnitFiles") ||
char **l = NULL;
unsigned n_changes = 0;
goto oom;
r = bus_parse_strv_iter(&iter, &l);
if (r < 0) {
if (r == -ENOMEM)
goto oom;
}
if (!dbus_message_iter_next(&iter) ||
strv_free(l);
}
else
assert_not_reached("Uh? Wrong method");
strv_free(l);
if (r < 0) {
}
if (!reply)
goto oom;
} else {
const BusBoundProperties bps[] = {
{ "org.freedesktop.systemd1.Manager", bus_manager_properties, m },
{ NULL, }
};
}
if (job_type != _JOB_TYPE_INVALID) {
Unit *u;
dbus_bool_t b;
&error,
else
&error,
if (!b)
if (old_name) {
u = manager_get_unit(m, old_name);
}
}
if (mode < 0) {
}
if (r < 0)
}
if (reply)
goto oom;
return DBUS_HANDLER_RESULT_HANDLED;
oom:
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
const DBusObjectPathVTable bus_manager_vtable = {
};