dbus-unit.c revision b170dd803d334234ad7edd0dc7bb34860832bc07
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering This file is part of systemd.
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering Copyright 2010 Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering systemd is free software; you can redistribute it and/or modify it
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering under the terms of the GNU Lesser General Public License as published by
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering (at your option) any later version.
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering systemd is distributed in the hope that it will be useful, but
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering Lesser General Public License for more details.
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering You should have received a copy of the GNU Lesser General Public License
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poetteringconst char bus_unit_interface[] _introspect_("Unit") = BUS_UNIT_INTERFACE;
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poettering "LoadState\0" \
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poettering "ActiveState\0" \
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poettering "InactiveExitTimestamp\0" \
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering "ActiveEnterTimestamp\0" \
40b71e89bae4e51768db4dc50ec64c1e9c96eec4Sebastian Thorarensen "ActiveExitTimestamp\0" \
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poettering "InactiveEnterTimestamp\0" \
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poettering "NeedDaemonReload\0"
15a5e95075a7f6007dd97b2a165c8ed16fe683dfLennart Poetteringstatic int bus_unit_append_names(DBusMessageIter *i, const char *property, void *data) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (!dbus_message_iter_open_container(i, DBUS_TYPE_ARRAY, "s", &sub))
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &t))
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (!dbus_message_iter_close_container(i, &sub))
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poetteringstatic int bus_unit_append_following(DBusMessageIter *i, const char *property, void *data) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering const char *d;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poetteringstatic int bus_unit_append_slice(DBusMessageIter *i, const char *property, void *data) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering const char *d;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
13790add4bf648fed816361794d8277a75253410Lennart Poetteringstatic int bus_unit_append_dependencies(DBusMessageIter *i, const char *property, void *data) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (!dbus_message_iter_open_container(i, DBUS_TYPE_ARRAY, "s", &sub))
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &u->id))
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (!dbus_message_iter_close_container(i, &sub))
13790add4bf648fed816361794d8277a75253410Lennart Poetteringstatic int bus_unit_append_description(DBusMessageIter *i, const char *property, void *data) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering const char *d;
e22aa3d3284709234f086ebebc13a905a295b7a7Lennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
13790add4bf648fed816361794d8277a75253410Lennart Poetteringstatic DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_unit_append_load_state, unit_load_state, UnitLoadState);
13790add4bf648fed816361794d8277a75253410Lennart Poetteringstatic int bus_unit_append_active_state(DBusMessageIter *i, const char *property, void *data) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering state = unit_active_state_to_string(unit_active_state(u));
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &state))
13790add4bf648fed816361794d8277a75253410Lennart Poetteringstatic int bus_unit_append_sub_state(DBusMessageIter *i, const char *property, void *data) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &state))
13790add4bf648fed816361794d8277a75253410Lennart Poetteringstatic int bus_unit_append_file_state(DBusMessageIter *i, const char *property, void *data) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering state = strempty(unit_file_state_to_string(unit_get_unit_file_state(u)));
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &state))
13790add4bf648fed816361794d8277a75253410Lennart Poetteringstatic int bus_unit_append_can_start(DBusMessageIter *i, const char *property, void *data) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b))
13790add4bf648fed816361794d8277a75253410Lennart Poetteringstatic int bus_unit_append_can_stop(DBusMessageIter *i, const char *property, void *data) {
e22aa3d3284709234f086ebebc13a905a295b7a7Lennart Poettering /* On the lower levels we assume that every unit we can start
e22aa3d3284709234f086ebebc13a905a295b7a7Lennart Poettering * we can also stop */
e22aa3d3284709234f086ebebc13a905a295b7a7Lennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b))
dacd6cee76a08331b8c8616c5f30f70ee49aa2f9Lennart Poetteringstatic int bus_unit_append_can_reload(DBusMessageIter *i, const char *property, void *data) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b))
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poetteringstatic int bus_unit_append_can_isolate(DBusMessageIter *i, const char *property, void *data) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b))
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poetteringstatic int bus_unit_append_job(DBusMessageIter *i, const char *property, void *data) {
e3bfb7be07d9b1f4ebb12eb22c4c8bcd2a988d51Zbigniew Jędrzejewski-Szmek if (!dbus_message_iter_open_container(i, DBUS_TYPE_STRUCT, NULL, &sub))
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_UINT32, &u->job->id) ||
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &p))
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering /* No job, so let's fill in some placeholder
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering * data. Since we need to fill in a valid path we
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering * simple point to ourselves. */
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_UINT32, &id) ||
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &p))
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (!dbus_message_iter_close_container(i, &sub))
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poetteringstatic int bus_unit_append_need_daemon_reload(DBusMessageIter *i, const char *property, void *data) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b))
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poetteringstatic int bus_unit_append_load_error(DBusMessageIter *i, const char *property, void *data) {
41891700e02daf0cab9e86908c76ac6f411bbd57Lennart Poettering message = strempty(strerror(-u->load_error));
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (!dbus_message_iter_open_container(i, DBUS_TYPE_STRUCT, NULL, &sub) ||
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering !dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &name) ||
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering !dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &message) ||
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering !dbus_message_iter_close_container(i, &sub))
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poetteringstatic DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *connection, DBusMessage *message) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "Start"))
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "Stop"))
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "Reload"))
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "Restart"))
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "TryRestart"))
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "ReloadOrRestart")) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "ReloadOrTryRestart")) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "Kill")) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "stop");
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering return bus_send_error_reply(connection, message, &error, r);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering reply = dbus_message_new_method_return(message);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "ResetFailed")) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "reload");
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering reply = dbus_message_new_method_return(message);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "SetProperties")) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (!dbus_message_iter_init(message, &iter))
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (bus_iter_get_basic_and_next(&iter, DBUS_TYPE_BOOLEAN, &runtime, true) < 0)
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering return bus_send_error_reply(connection, message, NULL, -EINVAL);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "start");
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering r = bus_unit_set_properties(u, &iter, runtime ? UNIT_RUNTIME : UNIT_PERSISTENT, true, &error);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering return bus_send_error_reply(connection, message, &error, r);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering reply = dbus_message_new_method_return(message);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering } else if (UNIT_VTABLE(u)->bus_message_handler)
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering return UNIT_VTABLE(u)->bus_message_handler(u, connection, message);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering dbus_set_error(&error, BUS_ERROR_INVALID_JOB_MODE, "Job mode %s is invalid.", smode);
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering return bus_unit_queue_job(connection, message, u, job_type, mode, reload_if_possible);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (!bus_maybe_send_reply(connection, message, reply))
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poetteringstatic DBusHandlerResult bus_unit_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (streq(dbus_message_get_path(message), "/org/freedesktop/systemd1/unit")) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering /* Be nice to gdbus and return introspection data for our mid-level paths */
13790add4bf648fed816361794d8277a75253410Lennart Poettering SELINUX_ACCESS_CHECK(connection, message, "status");
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect")) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering const char *k;
13790add4bf648fed816361794d8277a75253410Lennart Poettering reply = dbus_message_new_method_return(message);
13790add4bf648fed816361794d8277a75253410Lennart Poettering /* We roll our own introspection code here, instead of
13790add4bf648fed816361794d8277a75253410Lennart Poettering * relying on bus_default_message_handler() because we
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering * need to generate our introspection string
13790add4bf648fed816361794d8277a75253410Lennart Poettering * dynamically. */
2de56f70941eaf91a4520bf33de47a87ebd8b2cbZbigniew Jędrzejewski-Szmek f = open_memstream(&introspection, &size);
13790add4bf648fed816361794d8277a75253410Lennart Poettering fputs(DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE
13790add4bf648fed816361794d8277a75253410Lennart Poettering "<node>\n", f);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &introspection, DBUS_TYPE_INVALID)) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (!bus_maybe_send_reply(connection, message, reply))
13790add4bf648fed816361794d8277a75253410Lennart Poettering return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
13790add4bf648fed816361794d8277a75253410Lennart Poettering r = manager_load_unit_from_dbus_path(m, dbus_message_get_path(message), &error, &u);
13790add4bf648fed816361794d8277a75253410Lennart Poettering return bus_send_error_reply(connection, message, &error, r);
13790add4bf648fed816361794d8277a75253410Lennart Poettering return bus_unit_message_dispatch(u, connection, message);
13790add4bf648fed816361794d8277a75253410Lennart Poetteringconst DBusObjectPathVTable bus_unit_vtable = {
13790add4bf648fed816361794d8277a75253410Lennart Poettering .message_function = bus_unit_message_handler
13790add4bf648fed816361794d8277a75253410Lennart Poetteringvoid bus_unit_send_change_signal(Unit *u) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering _cleanup_dbus_message_unref_ DBusMessage *m = NULL;
13790add4bf648fed816361794d8277a75253410Lennart Poettering LIST_REMOVE(Unit, dbus_queue, u->manager->dbus_unit_queue, u);
13790add4bf648fed816361794d8277a75253410Lennart Poettering /* Send a properties changed signal. First for the
13790add4bf648fed816361794d8277a75253410Lennart Poettering * specific type, then for the generic unit. The
d682b3a7e7c7c2941a4d3e193f1e330dbc9fae89Lennart Poettering * clients may rely on this order to get atomic
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering * behavior if needed. */
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (UNIT_VTABLE(u)->bus_invalidating_properties) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering UNIT_VTABLE(u)->bus_invalidating_properties);
13790add4bf648fed816361794d8277a75253410Lennart Poettering log_error("Failed to broadcast change message: %s", strerror(-r));
13790add4bf648fed816361794d8277a75253410Lennart Poettering m = bus_properties_changed_new(p, "org.freedesktop.systemd1.Unit",
13790add4bf648fed816361794d8277a75253410Lennart Poettering /* Send a new signal */
13790add4bf648fed816361794d8277a75253410Lennart Poettering m = dbus_message_new_signal("/org/freedesktop/systemd1",
13790add4bf648fed816361794d8277a75253410Lennart Poettering "org.freedesktop.systemd1.Manager",
15d91bff36c61d38df8edff258d1702a017a0e66Zbigniew Jędrzejewski-Szmek r = bus_broadcast(u->manager, m);
13790add4bf648fed816361794d8277a75253410Lennart Poettering log_error("Failed to broadcast UnitNew/PropertiesChanged message.");
13790add4bf648fed816361794d8277a75253410Lennart Poetteringvoid bus_unit_send_removed_signal(Unit *u) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering _cleanup_dbus_message_unref_ DBusMessage *m = NULL;
13790add4bf648fed816361794d8277a75253410Lennart Poettering m = dbus_message_new_signal("/org/freedesktop/systemd1",
13790add4bf648fed816361794d8277a75253410Lennart Poettering "org.freedesktop.systemd1.Manager",
13790add4bf648fed816361794d8277a75253410Lennart Poettering "UnitRemoved");
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering assert(mode >= 0 && mode < _JOB_MODE_MAX);
4a62c710b62a5a3c7a8a278b810b9d5b5a0c8f4fMichal Schmidt if (reload_if_possible && unit_can_reload(u)) {
4a61c3e51e96a747c30598d78ee3a24e7c569e9fZbigniew Jędrzejewski-Szmek else if (type == JOB_TRY_RESTART)
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering SELINUX_UNIT_ACCESS_CHECK(u, connection, message,
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering (type == JOB_START || type == JOB_RESTART || type == JOB_TRY_RESTART) ? "start" :
23bbb0de4e3f85d9704a5c12a5afa2dfa0159e41Michal Schmidt if (type == JOB_STOP && (u->load_state == UNIT_NOT_FOUND || u->load_state == UNIT_ERROR) && unit_active_state(u) == UNIT_INACTIVE) {
23bbb0de4e3f85d9704a5c12a5afa2dfa0159e41Michal Schmidt dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s not loaded.", u->id);
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering return bus_send_error_reply(connection, message, &error, -EPERM);
23bbb0de4e3f85d9704a5c12a5afa2dfa0159e41Michal Schmidt if ((type == JOB_START && u->refuse_manual_start) ||
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering (type == JOB_STOP && u->refuse_manual_stop) ||
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering ((type == JOB_RESTART || type == JOB_TRY_RESTART) && (u->refuse_manual_start || u->refuse_manual_stop))) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering dbus_set_error(&error, BUS_ERROR_ONLY_BY_DEPENDENCY,
e22aa3d3284709234f086ebebc13a905a295b7a7Lennart Poettering "Operation refused, unit %s may be requested by dependency only.", u->id);
e22aa3d3284709234f086ebebc13a905a295b7a7Lennart Poettering return bus_send_error_reply(connection, message, &error, -EPERM);
e22aa3d3284709234f086ebebc13a905a295b7a7Lennart Poettering r = manager_add_job(u->manager, type, u, mode, true, &error, &j);
e22aa3d3284709234f086ebebc13a905a295b7a7Lennart Poettering return bus_send_error_reply(connection, message, &error, r);
e22aa3d3284709234f086ebebc13a905a295b7a7Lennart Poettering cl = job_bus_client_new(connection, bus_message_get_sender_with_fallback(message));
e22aa3d3284709234f086ebebc13a905a295b7a7Lennart Poettering LIST_PREPEND(JobBusClient, client, j->bus_client_list, cl);
e22aa3d3284709234f086ebebc13a905a295b7a7Lennart Poettering reply = dbus_message_new_method_return(message);
e22aa3d3284709234f086ebebc13a905a295b7a7Lennart Poettering if (!bus_maybe_send_reply(connection, message, reply))
e22aa3d3284709234f086ebebc13a905a295b7a7Lennart Poetteringstatic int bus_unit_set_transient_property(
assert(u);
assert(i);
return -EINVAL;
const char *description;
return -EINVAL;
dbus_message_iter_get_basic(i, &s);
if (isempty(s)) {
return -EINVAL;
Unit *u,
bool commit,
bool for_real = false;
assert(u);
if (u->transient)
return -EINVAL;
const char *name;
if (for_real)
for_real = true;
return -EINVAL;
return -EINVAL;
dbus_set_error(error, DBUS_ERROR_PROPERTY_READ_ONLY, "Objects of this type do not support setting properties.");
return -ENOENT;
dbus_set_error(error, DBUS_ERROR_PROPERTY_READ_ONLY, "Cannot set property %s, or unknown property.", name);
return -ENOENT;
n += for_real;
{ "Requires", bus_unit_append_dependencies, "as", offsetof(Unit, dependencies[UNIT_REQUIRES]), true },
{ "RequiresOverridable", bus_unit_append_dependencies, "as", offsetof(Unit, dependencies[UNIT_REQUIRES_OVERRIDABLE]), true },
{ "Requisite", bus_unit_append_dependencies, "as", offsetof(Unit, dependencies[UNIT_REQUISITE]), true },
{ "RequisiteOverridable", bus_unit_append_dependencies, "as", offsetof(Unit, dependencies[UNIT_REQUISITE_OVERRIDABLE]), true },
{ "BindsTo", bus_unit_append_dependencies, "as", offsetof(Unit, dependencies[UNIT_BINDS_TO]), true },
{ "RequiredBy", bus_unit_append_dependencies, "as", offsetof(Unit, dependencies[UNIT_REQUIRED_BY]), true },
{ "RequiredByOverridable",bus_unit_append_dependencies, "as", offsetof(Unit, dependencies[UNIT_REQUIRED_BY_OVERRIDABLE]), true },
{ "WantedBy", bus_unit_append_dependencies, "as", offsetof(Unit, dependencies[UNIT_WANTED_BY]), true },
{ "BoundBy", bus_unit_append_dependencies, "as", offsetof(Unit, dependencies[UNIT_BOUND_BY]), true },
{ "ConsistsOf", bus_unit_append_dependencies, "as", offsetof(Unit, dependencies[UNIT_CONSISTS_OF]), true },
{ "Conflicts", bus_unit_append_dependencies, "as", offsetof(Unit, dependencies[UNIT_CONFLICTS]), true },
{ "ConflictedBy", bus_unit_append_dependencies, "as", offsetof(Unit, dependencies[UNIT_CONFLICTED_BY]), true },
{ "OnFailure", bus_unit_append_dependencies, "as", offsetof(Unit, dependencies[UNIT_ON_FAILURE]), true },
{ "Triggers", bus_unit_append_dependencies, "as", offsetof(Unit, dependencies[UNIT_TRIGGERS]), true },
{ "TriggeredBy", bus_unit_append_dependencies, "as", offsetof(Unit, dependencies[UNIT_TRIGGERED_BY]), true },
{ "PropagatesReloadTo", bus_unit_append_dependencies, "as", offsetof(Unit, dependencies[UNIT_PROPAGATES_RELOAD_TO]), true },
{ "ReloadPropagatedFrom", bus_unit_append_dependencies, "as", offsetof(Unit, dependencies[UNIT_RELOAD_PROPAGATED_FROM]), true },
{ "InactiveExitTimestamp",bus_property_append_usec, "t", offsetof(Unit, inactive_exit_timestamp.realtime) },
{ "InactiveExitTimestampMonotonic", bus_property_append_usec, "t", offsetof(Unit, inactive_exit_timestamp.monotonic) },
{ "ActiveEnterTimestamp", bus_property_append_usec, "t", offsetof(Unit, active_enter_timestamp.realtime) },
{ "ActiveEnterTimestampMonotonic", bus_property_append_usec, "t", offsetof(Unit, active_enter_timestamp.monotonic) },
{ "ActiveExitTimestamp", bus_property_append_usec, "t", offsetof(Unit, active_exit_timestamp.realtime) },
{ "ActiveExitTimestampMonotonic", bus_property_append_usec, "t", offsetof(Unit, active_exit_timestamp.monotonic) },
{ "InactiveEnterTimestamp", bus_property_append_usec, "t", offsetof(Unit, inactive_enter_timestamp.realtime) },
{ "InactiveEnterTimestampMonotonic",bus_property_append_usec, "t", offsetof(Unit, inactive_enter_timestamp.monotonic) },
{ "ConditionTimestamp", bus_property_append_usec, "t", offsetof(Unit, condition_timestamp.realtime) },
{ "ConditionTimestampMonotonic", bus_property_append_usec, "t", offsetof(Unit, condition_timestamp.monotonic) },
{ NULL, }