dbus-unit.c revision 000a996dc46c187f803b67b0b0d51ad4d0bc1658
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering This file is part of systemd.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Copyright 2010 Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering systemd is free software; you can redistribute it and/or modify it
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering under the terms of the GNU Lesser General Public License as published by
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering (at your option) any later version.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering systemd is distributed in the hope that it will be useful, but
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Lesser General Public License for more details.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering You should have received a copy of the GNU Lesser General Public License
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic BUS_DEFINE_PROPERTY_GET_ENUM(property_get_load_state, unit_load_state, UnitLoadState);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic BUS_DEFINE_PROPERTY_GET_ENUM(property_get_job_mode, job_mode, JobMode);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic BUS_DEFINE_PROPERTY_GET_ENUM(property_get_failure_action, failure_action, FailureAction);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering const char *t;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering r = sd_bus_message_open_container(reply, 'a', "s");
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering r = sd_bus_message_append(reply, "s", t);
d8f52ed25a9edce75fda5251c977b7898e33887eLennart Poettering return sd_bus_message_close_container(reply);
acf97e213e69a97e63ab8f7fad7ecd53608c757aLennart Poettering return sd_bus_message_append(reply, "s", f ? f->id : "");
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering r = sd_bus_message_open_container(reply, 'a', "s");
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering r = sd_bus_message_append(reply, "s", u->id);
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering return sd_bus_message_close_container(reply);
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poetteringstatic int property_get_obsolete_dependencies(
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering /* For dependency types we don't support anymore always return an empty array */
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen return sd_bus_message_append(reply, "s", unit_description(u));
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering return sd_bus_message_append(reply, "s", unit_active_state_to_string(unit_active_state(u)));
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering return sd_bus_message_append(reply, "s", unit_sub_state_to_string(u));
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering return sd_bus_message_append(reply, "s", unit_file_state_to_string(unit_get_unit_file_state(u)));
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering return sd_bus_message_append(reply, "b", unit_can_start(u) && !u->refuse_manual_start);
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering /* On the lower levels we assume that every unit we can start
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering * we can also stop */
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering return sd_bus_message_append(reply, "b", unit_can_start(u) && !u->refuse_manual_stop);
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering return sd_bus_message_append(reply, "b", unit_can_reload(u));
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering return sd_bus_message_append(reply, "b", unit_can_isolate(u) && !u->refuse_manual_start);
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering return sd_bus_message_append(reply, "(uo)", 0, "/");
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering return sd_bus_message_append(reply, "(uo)", u->job->id, p);
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poetteringstatic int property_get_need_daemon_reload(
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering return sd_bus_message_append(reply, "b", unit_need_daemon_reload(u));
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering const char *(*to_string)(ConditionType type) = NULL;
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering to_string = streq(property, "Asserts") ? assert_type_to_string : condition_type_to_string;
9d12709626bccc0cae677a7035f62efe6aabb4abLennart Poettering r = sd_bus_message_open_container(reply, 'a', "(sbbsi)");
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering c->result == CONDITION_SUCCEEDED ? 1 : -1;
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering r = sd_bus_message_append(reply, "(sbbsi)",
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering return sd_bus_message_close_container(reply);
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering _cleanup_bus_error_free_ sd_bus_error e = SD_BUS_ERROR_NULL;
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering sd_bus_error_set_errno(&e, u->load_error);
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering return sd_bus_message_append(reply, "(ss)", e.name, e.message);
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poetteringstatic int bus_verify_manage_units_async_full(
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering return bus_verify_polkit_async(call, capability, "org.freedesktop.systemd1.manage-units", details, false, UID_INVALID, &u->manager->polkit_registry, error);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering static const char *const polkit_message_for_job[_JOB_TYPE_MAX] = {
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering [JOB_START] = N_("Authentication is required to start '$(unit)'."),
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering [JOB_STOP] = N_("Authentication is required to stop '$(unit)'."),
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering [JOB_RELOAD] = N_("Authentication is required to reload '$(unit)'."),
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering [JOB_RESTART] = N_("Authentication is required to restart '$(unit)'."),
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering [JOB_TRY_RESTART] = N_("Authentication is required to restart '$(unit)'."),
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering assert(job_type >= 0 && job_type < _JOB_TYPE_MAX);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering r = mac_selinux_unit_access_check(u, message, job_type == JOB_STOP ? "stop" : "start", error);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering r = sd_bus_message_read(message, "s", &smode);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Job mode %s invalid", smode);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering verb = strjoin("reload-or-", job_type_to_string(job_type), NULL);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering verb = strdup(job_type_to_string(job_type));
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering job_type < _JOB_TYPE_MAX ? polkit_message_for_job[job_type] : NULL,
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers return bus_unit_queue_job(message, u, job_type, mode, reload_if_possible, error);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic int method_start(sd_bus_message *message, void *userdata, sd_bus_error *error) {
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering return bus_unit_method_start_generic(message, userdata, JOB_START, false, error);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic int method_stop(sd_bus_message *message, void *userdata, sd_bus_error *error) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return bus_unit_method_start_generic(message, userdata, JOB_STOP, false, error);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic int method_reload(sd_bus_message *message, void *userdata, sd_bus_error *error) {
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering return bus_unit_method_start_generic(message, userdata, JOB_RELOAD, false, error);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic int method_restart(sd_bus_message *message, void *userdata, sd_bus_error *error) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return bus_unit_method_start_generic(message, userdata, JOB_RESTART, false, error);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic int method_try_restart(sd_bus_message *message, void *userdata, sd_bus_error *error) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return bus_unit_method_start_generic(message, userdata, JOB_TRY_RESTART, false, error);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic int method_reload_or_restart(sd_bus_message *message, void *userdata, sd_bus_error *error) {
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering return bus_unit_method_start_generic(message, userdata, JOB_RESTART, true, error);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic int method_reload_or_try_restart(sd_bus_message *message, void *userdata, sd_bus_error *error) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return bus_unit_method_start_generic(message, userdata, JOB_TRY_RESTART, true, error);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringint bus_unit_method_kill(sd_bus_message *message, void *userdata, sd_bus_error *error) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering r = mac_selinux_unit_access_check(u, message, "stop", error);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering r = sd_bus_message_read(message, "si", &swho, &signo);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid who argument %s", swho);
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Signal number out of range.");
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering N_("Authentication is required to kill '$(unit)'."),
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering return sd_bus_reply_method_return(message, NULL);
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poetteringint bus_unit_method_reset_failed(sd_bus_message *message, void *userdata, sd_bus_error *error) {
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering r = mac_selinux_unit_access_check(u, message, "reload", error);
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering "reset-failed",
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering N_("Authentication is required to reset the \"failed\" state of '$(unit)'."),
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering return sd_bus_reply_method_return(message, NULL);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringint bus_unit_method_set_properties(sd_bus_message *message, void *userdata, sd_bus_error *error) {
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering r = mac_selinux_unit_access_check(u, message, "start", error);
e7e9b6bb0b0bc5b1eb256a44f8afec6b634f26efZbigniew Jędrzejewski-Szmek r = sd_bus_message_read(message, "b", &runtime);
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering "set-property",
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering N_("Authentication is required to set properties on '$(unit)'."),
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering r = bus_unit_set_properties(u, message, runtime ? UNIT_RUNTIME : UNIT_PERSISTENT, true, error);
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering return sd_bus_reply_method_return(message, NULL);
a6c616024db23fef34152c1432892824a07799ccLennart Poettering SD_BUS_PROPERTY("Id", "s", NULL, offsetof(Unit, id), SD_BUS_VTABLE_PROPERTY_CONST),
a6c616024db23fef34152c1432892824a07799ccLennart Poettering SD_BUS_PROPERTY("Names", "as", property_get_names, 0, SD_BUS_VTABLE_PROPERTY_CONST),
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen SD_BUS_PROPERTY("Following", "s", property_get_following, 0, 0),
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen SD_BUS_PROPERTY("Requires", "as", property_get_dependencies, offsetof(Unit, dependencies[UNIT_REQUIRES]), SD_BUS_VTABLE_PROPERTY_CONST),
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering SD_BUS_PROPERTY("Requisite", "as", property_get_dependencies, offsetof(Unit, dependencies[UNIT_REQUISITE]), SD_BUS_VTABLE_PROPERTY_CONST),
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering SD_BUS_PROPERTY("Wants", "as", property_get_dependencies, offsetof(Unit, dependencies[UNIT_WANTS]), SD_BUS_VTABLE_PROPERTY_CONST),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SD_BUS_PROPERTY("BindsTo", "as", property_get_dependencies, offsetof(Unit, dependencies[UNIT_BINDS_TO]), SD_BUS_VTABLE_PROPERTY_CONST),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SD_BUS_PROPERTY("PartOf", "as", property_get_dependencies, offsetof(Unit, dependencies[UNIT_PART_OF]), SD_BUS_VTABLE_PROPERTY_CONST),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SD_BUS_PROPERTY("RequiredBy", "as", property_get_dependencies, offsetof(Unit, dependencies[UNIT_REQUIRED_BY]), SD_BUS_VTABLE_PROPERTY_CONST),
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers SD_BUS_PROPERTY("RequisiteOf", "as", property_get_dependencies, offsetof(Unit, dependencies[UNIT_REQUISITE_OF]), SD_BUS_VTABLE_PROPERTY_CONST),
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers SD_BUS_PROPERTY("WantedBy", "as", property_get_dependencies, offsetof(Unit, dependencies[UNIT_WANTED_BY]), SD_BUS_VTABLE_PROPERTY_CONST),
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers SD_BUS_PROPERTY("BoundBy", "as", property_get_dependencies, offsetof(Unit, dependencies[UNIT_BOUND_BY]), SD_BUS_VTABLE_PROPERTY_CONST),
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers SD_BUS_PROPERTY("ConsistsOf", "as", property_get_dependencies, offsetof(Unit, dependencies[UNIT_CONSISTS_OF]), SD_BUS_VTABLE_PROPERTY_CONST),
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers SD_BUS_PROPERTY("Conflicts", "as", property_get_dependencies, offsetof(Unit, dependencies[UNIT_CONFLICTS]), SD_BUS_VTABLE_PROPERTY_CONST),
f647962d64e844689f3e2acfce6102fc47e76df2Michal Schmidt SD_BUS_PROPERTY("ConflictedBy", "as", property_get_dependencies, offsetof(Unit, dependencies[UNIT_CONFLICTED_BY]), SD_BUS_VTABLE_PROPERTY_CONST),
f647962d64e844689f3e2acfce6102fc47e76df2Michal Schmidt SD_BUS_PROPERTY("Before", "as", property_get_dependencies, offsetof(Unit, dependencies[UNIT_BEFORE]), SD_BUS_VTABLE_PROPERTY_CONST),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SD_BUS_PROPERTY("After", "as", property_get_dependencies, offsetof(Unit, dependencies[UNIT_AFTER]), SD_BUS_VTABLE_PROPERTY_CONST),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SD_BUS_PROPERTY("OnFailure", "as", property_get_dependencies, offsetof(Unit, dependencies[UNIT_ON_FAILURE]), SD_BUS_VTABLE_PROPERTY_CONST),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SD_BUS_PROPERTY("Triggers", "as", property_get_dependencies, offsetof(Unit, dependencies[UNIT_TRIGGERS]), SD_BUS_VTABLE_PROPERTY_CONST),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SD_BUS_PROPERTY("TriggeredBy", "as", property_get_dependencies, offsetof(Unit, dependencies[UNIT_TRIGGERED_BY]), SD_BUS_VTABLE_PROPERTY_CONST),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SD_BUS_PROPERTY("PropagatesReloadTo", "as", property_get_dependencies, offsetof(Unit, dependencies[UNIT_PROPAGATES_RELOAD_TO]), SD_BUS_VTABLE_PROPERTY_CONST),
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers SD_BUS_PROPERTY("ReloadPropagatedFrom", "as", property_get_dependencies, offsetof(Unit, dependencies[UNIT_RELOAD_PROPAGATED_FROM]), SD_BUS_VTABLE_PROPERTY_CONST),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SD_BUS_PROPERTY("JoinsNamespaceOf", "as", property_get_dependencies, offsetof(Unit, dependencies[UNIT_JOINS_NAMESPACE_OF]), SD_BUS_VTABLE_PROPERTY_CONST),
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers SD_BUS_PROPERTY("RequiresOverridable", "as", property_get_obsolete_dependencies, 0, SD_BUS_VTABLE_HIDDEN),
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers SD_BUS_PROPERTY("RequisiteOverridable", "as", property_get_obsolete_dependencies, 0, SD_BUS_VTABLE_HIDDEN),
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers SD_BUS_PROPERTY("RequiredByOverridable", "as", property_get_obsolete_dependencies, 0, SD_BUS_VTABLE_HIDDEN),
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering SD_BUS_PROPERTY("RequisiteOfOverridable", "as", property_get_obsolete_dependencies, 0, SD_BUS_VTABLE_HIDDEN),
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers SD_BUS_PROPERTY("RequiresMountsFor", "as", NULL, offsetof(Unit, requires_mounts_for), SD_BUS_VTABLE_PROPERTY_CONST),
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering SD_BUS_PROPERTY("Documentation", "as", NULL, offsetof(Unit, documentation), SD_BUS_VTABLE_PROPERTY_CONST),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SD_BUS_PROPERTY("Description", "s", property_get_description, 0, SD_BUS_VTABLE_PROPERTY_CONST),
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers SD_BUS_PROPERTY("LoadState", "s", property_get_load_state, offsetof(Unit, load_state), SD_BUS_VTABLE_PROPERTY_CONST),
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers SD_BUS_PROPERTY("ActiveState", "s", property_get_active_state, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SD_BUS_PROPERTY("SubState", "s", property_get_sub_state, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering SD_BUS_PROPERTY("FragmentPath", "s", NULL, offsetof(Unit, fragment_path), SD_BUS_VTABLE_PROPERTY_CONST),
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers SD_BUS_PROPERTY("SourcePath", "s", NULL, offsetof(Unit, source_path), SD_BUS_VTABLE_PROPERTY_CONST),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SD_BUS_PROPERTY("DropInPaths", "as", NULL, offsetof(Unit, dropin_paths), SD_BUS_VTABLE_PROPERTY_CONST),
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering SD_BUS_PROPERTY("UnitFileState", "s", property_get_unit_file_state, 0, 0),
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering SD_BUS_PROPERTY("UnitFilePreset", "s", property_get_unit_file_preset, 0, 0),
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering BUS_PROPERTY_DUAL_TIMESTAMP("InactiveExitTimestamp", offsetof(Unit, inactive_exit_timestamp), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering BUS_PROPERTY_DUAL_TIMESTAMP("ActiveEnterTimestamp", offsetof(Unit, active_enter_timestamp), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers BUS_PROPERTY_DUAL_TIMESTAMP("ActiveExitTimestamp", offsetof(Unit, active_exit_timestamp), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers BUS_PROPERTY_DUAL_TIMESTAMP("InactiveEnterTimestamp", offsetof(Unit, inactive_enter_timestamp), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SD_BUS_PROPERTY("CanStart", "b", property_get_can_start, 0, SD_BUS_VTABLE_PROPERTY_CONST),
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers SD_BUS_PROPERTY("CanStop", "b", property_get_can_stop, 0, SD_BUS_VTABLE_PROPERTY_CONST),
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen SD_BUS_PROPERTY("CanReload", "b", property_get_can_reload, 0, SD_BUS_VTABLE_PROPERTY_CONST),
27e72d6b22890ba4a8cbc05c49667cd1cccf1461Simon Peeters SD_BUS_PROPERTY("CanIsolate", "b", property_get_can_isolate, 0, SD_BUS_VTABLE_PROPERTY_CONST),
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen SD_BUS_PROPERTY("Job", "(uo)", property_get_job, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidt SD_BUS_PROPERTY("StopWhenUnneeded", "b", bus_property_get_bool, offsetof(Unit, stop_when_unneeded), SD_BUS_VTABLE_PROPERTY_CONST),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SD_BUS_PROPERTY("RefuseManualStart", "b", bus_property_get_bool, offsetof(Unit, refuse_manual_start), SD_BUS_VTABLE_PROPERTY_CONST),
a7893c6b28772edbc7e1fea3c209caa54d465648Lennart Poettering SD_BUS_PROPERTY("RefuseManualStop", "b", bus_property_get_bool, offsetof(Unit, refuse_manual_stop), SD_BUS_VTABLE_PROPERTY_CONST),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SD_BUS_PROPERTY("AllowIsolate", "b", bus_property_get_bool, offsetof(Unit, allow_isolate), SD_BUS_VTABLE_PROPERTY_CONST),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SD_BUS_PROPERTY("DefaultDependencies", "b", bus_property_get_bool, offsetof(Unit, default_dependencies), SD_BUS_VTABLE_PROPERTY_CONST),
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering SD_BUS_PROPERTY("OnFailureJobMode", "s", property_get_job_mode, offsetof(Unit, on_failure_job_mode), SD_BUS_VTABLE_PROPERTY_CONST),
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering SD_BUS_PROPERTY("IgnoreOnIsolate", "b", bus_property_get_bool, offsetof(Unit, ignore_on_isolate), SD_BUS_VTABLE_PROPERTY_CONST),
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen SD_BUS_PROPERTY("NeedDaemonReload", "b", property_get_need_daemon_reload, 0, SD_BUS_VTABLE_PROPERTY_CONST),
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering SD_BUS_PROPERTY("JobTimeoutUSec", "t", bus_property_get_usec, offsetof(Unit, job_timeout), SD_BUS_VTABLE_PROPERTY_CONST),
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers SD_BUS_PROPERTY("JobTimeoutAction", "s", property_get_failure_action, offsetof(Unit, job_timeout_action), SD_BUS_VTABLE_PROPERTY_CONST),
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering SD_BUS_PROPERTY("JobTimeoutRebootArgument", "s", NULL, offsetof(Unit, job_timeout_reboot_arg), SD_BUS_VTABLE_PROPERTY_CONST),
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering SD_BUS_PROPERTY("ConditionResult", "b", bus_property_get_bool, offsetof(Unit, condition_result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SD_BUS_PROPERTY("AssertResult", "b", bus_property_get_bool, offsetof(Unit, assert_result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering BUS_PROPERTY_DUAL_TIMESTAMP("ConditionTimestamp", offsetof(Unit, condition_timestamp), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering BUS_PROPERTY_DUAL_TIMESTAMP("AssertTimestamp", offsetof(Unit, assert_timestamp), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering SD_BUS_PROPERTY("Conditions", "a(sbbsi)", property_get_conditions, offsetof(Unit, conditions), 0),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SD_BUS_PROPERTY("Asserts", "a(sbbsi)", property_get_conditions, offsetof(Unit, asserts), 0),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SD_BUS_PROPERTY("LoadError", "(ss)", property_get_load_error, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SD_BUS_PROPERTY("Transient", "b", bus_property_get_bool, offsetof(Unit, transient), SD_BUS_VTABLE_PROPERTY_CONST),
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering SD_BUS_PROPERTY("NetClass", "u", NULL, offsetof(Unit, cgroup_netclass_id), 0),
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers SD_BUS_METHOD("Start", "s", "o", method_start, SD_BUS_VTABLE_UNPRIVILEGED),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SD_BUS_METHOD("Stop", "s", "o", method_stop, SD_BUS_VTABLE_UNPRIVILEGED),
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering SD_BUS_METHOD("Reload", "s", "o", method_reload, SD_BUS_VTABLE_UNPRIVILEGED),
8c841f21f5042b11acc91cc1b039cb162cbbe8f4Djalal Harouni SD_BUS_METHOD("Restart", "s", "o", method_restart, SD_BUS_VTABLE_UNPRIVILEGED),
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers SD_BUS_METHOD("TryRestart", "s", "o", method_try_restart, SD_BUS_VTABLE_UNPRIVILEGED),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SD_BUS_METHOD("ReloadOrRestart", "s", "o", method_reload_or_restart, SD_BUS_VTABLE_UNPRIVILEGED),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SD_BUS_METHOD("ReloadOrTryRestart", "s", "o", method_reload_or_try_restart, SD_BUS_VTABLE_UNPRIVILEGED),
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering SD_BUS_METHOD("Kill", "si", NULL, bus_unit_method_kill, SD_BUS_VTABLE_UNPRIVILEGED),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SD_BUS_METHOD("ResetFailed", NULL, NULL, bus_unit_method_reset_failed, SD_BUS_VTABLE_UNPRIVILEGED),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SD_BUS_METHOD("SetProperties", "ba(sv)", NULL, bus_unit_method_set_properties, SD_BUS_VTABLE_UNPRIVILEGED),
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering return sd_bus_message_append(reply, "s", unit_slice_name(u));
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering if (r < 0 && r != -ENODATA)
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering log_unit_warning_errno(u, r, "Failed to get memory.usage_in_bytes attribute: %m");
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering return sd_bus_message_append(reply, "t", sz);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering if (r < 0 && r != -ENODATA)
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering log_unit_warning_errno(u, r, "Failed to get pids.current attribute: %m");
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering return sd_bus_message_append(reply, "t", cn);
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering if (r < 0 && r != -ENODATA)
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering log_unit_warning_errno(u, r, "Failed to get cpuacct.usage attribute: %m");
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering return sd_bus_message_append(reply, "t", ns);
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering const char *t;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering /* Three cases: a) u->cgroup_path is NULL, in which case the
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering * unit has no control group, which we report as the empty
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering * string. b) u->cgroup_path is the empty string, which
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering * indicates the root cgroup, which we report as "/". c) all
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering * other cases we report as-is. */
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering t = isempty(u->cgroup_path) ? "/" : u->cgroup_path;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering return sd_bus_message_append(reply, "s", t);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poetteringconst sd_bus_vtable bus_unit_cgroup_vtable[] = {
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering SD_BUS_PROPERTY("Slice", "s", property_get_slice, 0, 0),
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering SD_BUS_PROPERTY("ControlGroup", "s", property_get_cgroup, 0, 0),
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering SD_BUS_PROPERTY("MemoryCurrent", "t", property_get_current_memory, 0, 0),
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering SD_BUS_PROPERTY("CPUUsageNSec", "t", property_get_cpu_usage, 0, 0),
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering SD_BUS_PROPERTY("TasksCurrent", "t", property_get_current_tasks, 0, 0),
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poetteringstatic int send_new_signal(sd_bus *bus, void *userdata) {
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering "org.freedesktop.systemd1.Manager",
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering r = sd_bus_message_append(m, "so", u->id, p);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poetteringstatic int send_changed_signal(sd_bus *bus, void *userdata) {
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering /* Send a properties changed signal. First for the specific
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering * type, then for the generic unit. The clients may rely on
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering * this order to get atomic behavior if needed. */
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering return sd_bus_emit_properties_changed_strv(
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poetteringvoid bus_unit_send_change_signal(Unit *u) {
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering LIST_REMOVE(dbus_queue, u->manager->dbus_unit_queue, u);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering r = bus_foreach_bus(u->manager, NULL, u->sent_dbus_new_signal ? send_changed_signal : send_new_signal, u);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering log_unit_debug_errno(u, r, "Failed to send unit change signal for %s: %m", u->id);
56159e0d918e9a9be07988133bb2847779325de0Lennart Poetteringstatic int send_removed_signal(sd_bus *bus, void *userdata) {
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering "org.freedesktop.systemd1.Manager",
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering "UnitRemoved");
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering r = sd_bus_message_append(m, "so", u->id, p);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringvoid bus_unit_send_removed_signal(Unit *u) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering r = bus_foreach_bus(u->manager, NULL, send_removed_signal, u);
1dba654b27918c22e413ac5b3c19301f1ff86ad2Lennart Poettering log_unit_debug_errno(u, r, "Failed to send unit remove signal for %s: %m", u->id);
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering assert(type >= 0 && type < _JOB_TYPE_MAX);
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering assert(mode >= 0 && mode < _JOB_MODE_MAX);
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering if (reload_if_possible && unit_can_reload(u)) {
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering (type == JOB_START || type == JOB_RESTART || type == JOB_TRY_RESTART) ? "start" :
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering type == JOB_STOP ? "stop" : "reload", error);
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering (u->load_state == UNIT_NOT_FOUND || u->load_state == UNIT_ERROR) &&
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s not loaded.", u->id);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if ((type == JOB_START && u->refuse_manual_start) ||
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering (type == JOB_STOP && u->refuse_manual_stop) ||
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering ((type == JOB_RESTART || type == JOB_TRY_RESTART) && (u->refuse_manual_start || u->refuse_manual_stop)) ||
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering (type == JOB_RELOAD_OR_START && job_type_collapse(type, u) == JOB_START && u->refuse_manual_start))
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return sd_bus_error_setf(error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Operation refused, unit %s may be requested by dependency only.", u->id);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = manager_add_job(u->manager, type, u, mode, error, &j);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (sd_bus_message_get_bus(message) == u->manager->api_bus) {
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = sd_bus_track_new(sd_bus_message_get_bus(message), &j->clients, NULL, NULL);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = sd_bus_track_add_sender(j->clients, message);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return sd_bus_reply_method_return(message, "o", path);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poetteringstatic int bus_unit_set_transient_property(
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering const char *d;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = sd_bus_message_read(message, "s", &d);
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering unit_write_drop_in_format(u, mode, name, "[Unit]\nDescription=%s\n", d);
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering } else if (streq(name, "DefaultDependencies")) {
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering r = sd_bus_message_read(message, "b", &b);
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering unit_write_drop_in_format(u, mode, name, "[Unit]\nDefaultDependencies=%s\n", yes_no(b));
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering const char *s;
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "The slice property is only available for units with control groups.");
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Slice may not be set for slice units.");
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering if (unit_has_name(u, SPECIAL_INIT_SCOPE))
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Cannot set slice for init.scope");
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering r = sd_bus_message_read(message, "s", &s);
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering if (!unit_name_is_valid(s, UNIT_NAME_PLAIN))
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid unit name '%s'", s);
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering r = manager_load_unit(u->manager, s, NULL, error, &slice);
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unit name '%s' is not a slice", s);
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering unit_write_drop_in_private_format(u, mode, name, "Slice=%s\n", s);
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering "PropagatesReloadTo", "ReloadPropagatedFrom",
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering d = UNIT_REQUIRES; /* redirect for obsolete unit dependency type */
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering else if (streq(name, "RequisiteOverridable"))
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid unit dependency: %s", name);
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering r = sd_bus_message_enter_container(message, 'a', "s");
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering while ((r = sd_bus_message_read(message, "s", &other)) > 0) {
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering if (!unit_name_is_valid(other, UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE))
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid unit name %s", other);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = unit_add_dependency_by_name(u, d, other, NULL, true);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering unit_write_drop_in_format(u, mode, label, "[Unit]\n%s=%s\n", name, other);
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering r = sd_bus_message_exit_container(message);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering unsigned n = 0;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering /* We iterate through the array twice. First run we just check
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering * if all passed data is valid, second run actually applies
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering * it. This is to implement transaction-like behaviour without
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering * actually providing full transactions. */
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = sd_bus_message_enter_container(message, 'a', "(sv)");
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = sd_bus_message_enter_container(message, 'r', "sv");
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering /* Reached EOF. Let's try again, and this time for realz... */
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = sd_bus_message_rewind(message, false);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = sd_bus_message_read(message, "s", &name);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_PROPERTY_READ_ONLY, "Objects of this type do not support setting properties.");
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = sd_bus_message_enter_container(message, 'v', NULL);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = UNIT_VTABLE(u)->bus_set_property(u, name, message, for_real ? mode : UNIT_CHECK, error);
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering if (r == 0 && u->transient && u->load_state == UNIT_STUB)
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = bus_unit_set_transient_property(u, name, message, for_real ? mode : UNIT_CHECK, error);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_PROPERTY_READ_ONLY, "Cannot set property %s, or unknown property.", name);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = sd_bus_message_exit_container(message);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = sd_bus_message_exit_container(message);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = sd_bus_message_exit_container(message);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (commit && n > 0 && UNIT_VTABLE(u)->bus_commit_properties)
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering UNIT_VTABLE(u)->bus_commit_properties(u);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poetteringint bus_unit_check_load_state(Unit *u, sd_bus_error *error) {
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering /* Give a better description of the unit error when
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering * possible. Note that in the case of UNIT_MASKED, load_error
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering * is not set. */
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return sd_bus_error_setf(error, BUS_ERROR_UNIT_MASKED, "Unit is masked.");
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit not found.");
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return sd_bus_error_set_errnof(error, u->load_error, "Unit is not loaded properly: %m.");