dbus-unit.c revision 000a996dc46c187f803b67b0b0d51ad4d0bc1658
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering/***
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering This file is part of systemd.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Copyright 2010 Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart 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
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
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 Poettering***/
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
8bdbb8d9cbe1d35708385573d70984ab4533812dLennart Poettering#include "sd-bus.h"
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering#include "alloc-util.h"
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering#include "bus-common-errors.h"
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering#include "cgroup-util.h"
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering#include "dbus-unit.h"
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering#include "dbus.h"
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering#include "locale-util.h"
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering#include "log.h"
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering#include "selinux-access.h"
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering#include "special.h"
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering#include "string-util.h"
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering#include "strv.h"
d538bfc71331d2e48363283decd77a61599021dbCristian Rodríguez#include "user-util.h"
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen
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);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
acf97e213e69a97e63ab8f7fad7ecd53608c757aLennart Poetteringstatic int property_get_names(
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen sd_bus *bus,
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen const char *path,
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering const char *interface,
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering const char *property,
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering sd_bus_message *reply,
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering void *userdata,
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering sd_bus_error *error) {
9d12709626bccc0cae677a7035f62efe6aabb4abLennart Poettering
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering Unit *u = userdata;
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering Iterator i;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering const char *t;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering int r;
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering assert(bus);
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering assert(reply);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering assert(u);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering r = sd_bus_message_open_container(reply, 'a', "s");
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (r < 0)
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return r;
e56056e93d33619a3acf13e483900b4f8938228fThomas Hindoe Paaboel Andersen
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering SET_FOREACH(t, u->names, i) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering r = sd_bus_message_append(reply, "s", t);
d21ed1ead18d16d35c30299a69d3366847f8a039Lennart Poettering if (r < 0)
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return r;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering }
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
d8f52ed25a9edce75fda5251c977b7898e33887eLennart Poettering return sd_bus_message_close_container(reply);
acf97e213e69a97e63ab8f7fad7ecd53608c757aLennart Poettering}
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poetteringstatic int property_get_following(
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering sd_bus *bus,
6e18cc9fa078d2a967251017ddb5baefb104b720Lennart Poettering const char *path,
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering const char *interface,
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering const char *property,
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering sd_bus_message *reply,
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering void *userdata,
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering sd_bus_error *error) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Unit *u = userdata, *f;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering assert(bus);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering assert(reply);
acf97e213e69a97e63ab8f7fad7ecd53608c757aLennart Poettering assert(u);
acf97e213e69a97e63ab8f7fad7ecd53608c757aLennart Poettering
acf97e213e69a97e63ab8f7fad7ecd53608c757aLennart Poettering f = unit_following(u);
acf97e213e69a97e63ab8f7fad7ecd53608c757aLennart Poettering return sd_bus_message_append(reply, "s", f ? f->id : "");
acf97e213e69a97e63ab8f7fad7ecd53608c757aLennart Poettering}
acf97e213e69a97e63ab8f7fad7ecd53608c757aLennart Poettering
acf97e213e69a97e63ab8f7fad7ecd53608c757aLennart Poetteringstatic int property_get_dependencies(
acf97e213e69a97e63ab8f7fad7ecd53608c757aLennart Poettering sd_bus *bus,
acf97e213e69a97e63ab8f7fad7ecd53608c757aLennart Poettering const char *path,
acf97e213e69a97e63ab8f7fad7ecd53608c757aLennart Poettering const char *interface,
acf97e213e69a97e63ab8f7fad7ecd53608c757aLennart Poettering const char *property,
acf97e213e69a97e63ab8f7fad7ecd53608c757aLennart Poettering sd_bus_message *reply,
acf97e213e69a97e63ab8f7fad7ecd53608c757aLennart Poettering void *userdata,
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering sd_bus_error *error) {
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering Set *s = *(Set**) userdata;
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering Iterator j;
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering Unit *u;
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering int r;
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering assert(bus);
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering assert(reply);
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering r = sd_bus_message_open_container(reply, 'a', "s");
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering if (r < 0)
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering return r;
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering SET_FOREACH(u, s, j) {
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering r = sd_bus_message_append(reply, "s", u->id);
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering if (r < 0)
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering return r;
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering }
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering return sd_bus_message_close_container(reply);
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering}
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poetteringstatic int property_get_obsolete_dependencies(
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen sd_bus *bus,
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering const char *path,
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering const char *interface,
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen const char *property,
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering sd_bus_message *reply,
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering void *userdata,
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering sd_bus_error *error) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering assert(bus);
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering assert(reply);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering /* For dependency types we don't support anymore always return an empty array */
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen return sd_bus_message_append(reply, "as", 0);
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen}
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersenstatic int property_get_description(
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen sd_bus *bus,
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen const char *path,
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen const char *interface,
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen const char *property,
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering sd_bus_message *reply,
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen void *userdata,
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen sd_bus_error *error) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Unit *u = userdata;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering assert(bus);
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen assert(reply);
5b30bef856e89a571df57b7b953e9a1409d9acedLennart Poettering assert(u);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen return sd_bus_message_append(reply, "s", unit_description(u));
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering}
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poetteringstatic int property_get_active_state(
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering sd_bus *bus,
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering const char *path,
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering const char *interface,
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering const char *property,
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering sd_bus_message *reply,
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering void *userdata,
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering sd_bus_error *error) {
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering Unit *u = userdata;
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering assert(bus);
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering assert(reply);
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering assert(u);
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering return sd_bus_message_append(reply, "s", unit_active_state_to_string(unit_active_state(u)));
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering}
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poetteringstatic int property_get_sub_state(
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering sd_bus *bus,
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering const char *path,
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen const char *interface,
5b30bef856e89a571df57b7b953e9a1409d9acedLennart Poettering const char *property,
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen sd_bus_message *reply,
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen void *userdata,
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen sd_bus_error *error) {
5b30bef856e89a571df57b7b953e9a1409d9acedLennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Unit *u = userdata;
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering assert(bus);
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering assert(reply);
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering assert(u);
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering return sd_bus_message_append(reply, "s", unit_sub_state_to_string(u));
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering}
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poetteringstatic int property_get_unit_file_preset(
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering sd_bus *bus,
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering const char *path,
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering const char *interface,
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering const char *property,
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering sd_bus_message *reply,
e56056e93d33619a3acf13e483900b4f8938228fThomas Hindoe Paaboel Andersen void *userdata,
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering sd_bus_error *error) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Unit *u = userdata;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering int r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering assert(bus);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering assert(reply);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering assert(u);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering r = unit_get_unit_file_preset(u);
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering return sd_bus_message_append(reply, "s",
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering r < 0 ? "":
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering r > 0 ? "enabled" : "disabled");
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering}
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poetteringstatic int property_get_unit_file_state(
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering sd_bus *bus,
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering const char *path,
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering const char *interface,
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering const char *property,
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering sd_bus_message *reply,
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering void *userdata,
c19de71113f956809995fc68817e055e9f61f607Lennart Poettering sd_bus_error *error) {
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering Unit *u = userdata;
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering assert(bus);
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering assert(reply);
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering assert(u);
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering return sd_bus_message_append(reply, "s", unit_file_state_to_string(unit_get_unit_file_state(u)));
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering}
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poetteringstatic int property_get_can_start(
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering sd_bus *bus,
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering const char *path,
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering const char *interface,
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering const char *property,
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering sd_bus_message *reply,
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering void *userdata,
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering sd_bus_error *error) {
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering Unit *u = userdata;
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering assert(bus);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering assert(reply);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering assert(u);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering return sd_bus_message_append(reply, "b", unit_can_start(u) && !u->refuse_manual_start);
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering}
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poetteringstatic int property_get_can_stop(
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering sd_bus *bus,
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering const char *path,
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering const char *interface,
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering const char *property,
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering sd_bus_message *reply,
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering void *userdata,
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering sd_bus_error *error) {
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering Unit *u = userdata;
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering assert(bus);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering assert(reply);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering assert(u);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering /* On the lower levels we assume that every unit we can start
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering * we can also stop */
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering return sd_bus_message_append(reply, "b", unit_can_start(u) && !u->refuse_manual_stop);
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering}
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poetteringstatic int property_get_can_reload(
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering sd_bus *bus,
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering const char *path,
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering const char *interface,
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering const char *property,
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering sd_bus_message *reply,
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering void *userdata,
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering sd_bus_error *error) {
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering Unit *u = userdata;
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering assert(bus);
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering assert(reply);
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering assert(u);
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering return sd_bus_message_append(reply, "b", unit_can_reload(u));
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering}
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poetteringstatic int property_get_can_isolate(
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering sd_bus *bus,
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering const char *path,
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering const char *interface,
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering const char *property,
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering sd_bus_message *reply,
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering void *userdata,
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering sd_bus_error *error) {
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering Unit *u = userdata;
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering assert(bus);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering assert(reply);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering assert(u);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering return sd_bus_message_append(reply, "b", unit_can_isolate(u) && !u->refuse_manual_start);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering}
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poetteringstatic int property_get_job(
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering sd_bus *bus,
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering const char *path,
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering const char *interface,
c19de71113f956809995fc68817e055e9f61f607Lennart Poettering const char *property,
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering sd_bus_message *reply,
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering void *userdata,
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering sd_bus_error *error) {
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering _cleanup_free_ char *p = NULL;
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering Unit *u = userdata;
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering assert(bus);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering assert(reply);
8937e7b68940d0fa0d0aab90eb7425fa7dccebc9Lennart Poettering assert(u);
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering if (!u->job)
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering return sd_bus_message_append(reply, "(uo)", 0, "/");
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering p = job_dbus_path(u->job);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering if (!p)
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering return -ENOMEM;
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering return sd_bus_message_append(reply, "(uo)", u->job->id, p);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering}
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poetteringstatic int property_get_need_daemon_reload(
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen sd_bus *bus,
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen const char *path,
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering const char *interface,
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering const char *property,
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering sd_bus_message *reply,
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering void *userdata,
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering sd_bus_error *error) {
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering Unit *u = userdata;
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering
d21ed1ead18d16d35c30299a69d3366847f8a039Lennart Poettering assert(bus);
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering assert(reply);
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering assert(u);
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering return sd_bus_message_append(reply, "b", unit_need_daemon_reload(u));
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering}
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering
a7893c6b28772edbc7e1fea3c209caa54d465648Lennart Poetteringstatic int property_get_conditions(
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering sd_bus *bus,
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering const char *path,
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering const char *interface,
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering const char *property,
a7893c6b28772edbc7e1fea3c209caa54d465648Lennart Poettering sd_bus_message *reply,
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering void *userdata,
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen sd_bus_error *error) {
a7893c6b28772edbc7e1fea3c209caa54d465648Lennart Poettering
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering const char *(*to_string)(ConditionType type) = NULL;
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen Condition **list = userdata, *c;
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering int r;
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering assert(bus);
a7893c6b28772edbc7e1fea3c209caa54d465648Lennart Poettering assert(reply);
5b30bef856e89a571df57b7b953e9a1409d9acedLennart Poettering assert(list);
5b30bef856e89a571df57b7b953e9a1409d9acedLennart Poettering
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering to_string = streq(property, "Asserts") ? assert_type_to_string : condition_type_to_string;
9d12709626bccc0cae677a7035f62efe6aabb4abLennart Poettering
9d12709626bccc0cae677a7035f62efe6aabb4abLennart Poettering r = sd_bus_message_open_container(reply, 'a', "(sbbsi)");
9d12709626bccc0cae677a7035f62efe6aabb4abLennart Poettering if (r < 0)
9d12709626bccc0cae677a7035f62efe6aabb4abLennart Poettering return r;
9d12709626bccc0cae677a7035f62efe6aabb4abLennart Poettering
9d12709626bccc0cae677a7035f62efe6aabb4abLennart Poettering LIST_FOREACH(conditions, c, *list) {
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering int tristate;
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering tristate =
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering c->result == CONDITION_UNTESTED ? 0 :
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering c->result == CONDITION_SUCCEEDED ? 1 : -1;
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering r = sd_bus_message_append(reply, "(sbbsi)",
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering to_string(c->type),
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering c->trigger, c->negate,
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering c->parameter, tristate);
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering if (r < 0)
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering return r;
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering }
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering return sd_bus_message_close_container(reply);
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering}
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poetteringstatic int property_get_load_error(
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering sd_bus *bus,
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering const char *path,
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering const char *interface,
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering const char *property,
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering sd_bus_message *reply,
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering void *userdata,
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering sd_bus_error *error) {
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering _cleanup_bus_error_free_ sd_bus_error e = SD_BUS_ERROR_NULL;
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering Unit *u = userdata;
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering assert(bus);
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering assert(reply);
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering assert(u);
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering if (u->load_error != 0)
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering sd_bus_error_set_errno(&e, u->load_error);
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering return sd_bus_message_append(reply, "(ss)", e.name, e.message);
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering}
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poetteringstatic int bus_verify_manage_units_async_full(
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering Unit *u,
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering const char *verb,
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering int capability,
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering const char *polkit_message,
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering sd_bus_message *call,
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering sd_bus_error *error) {
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering const char *details[9] = {
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering "unit", u->id,
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering "verb", verb,
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering };
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering if (polkit_message) {
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering details[4] = "polkit.message";
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering details[5] = polkit_message;
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering details[6] = "polkit.gettext_domain";
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering details[7] = GETTEXT_PACKAGE;
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering }
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering return bus_verify_polkit_async(call, capability, "org.freedesktop.systemd1.manage-units", details, false, UID_INVALID, &u->manager->polkit_registry, error);
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering}
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poetteringint bus_unit_method_start_generic(
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering sd_bus_message *message,
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering Unit *u,
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering JobType job_type,
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering bool reload_if_possible,
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering sd_bus_error *error) {
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering const char *smode;
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering JobMode mode;
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering _cleanup_free_ char *verb = NULL;
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 };
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering int r;
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering assert(message);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering assert(u);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering assert(job_type >= 0 && job_type < _JOB_TYPE_MAX);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering r = mac_selinux_unit_access_check(u, message, job_type == JOB_STOP ? "stop" : "start", error);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering if (r < 0)
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering return r;
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering r = sd_bus_message_read(message, "s", &smode);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering if (r < 0)
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering return r;
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering mode = job_mode_from_string(smode);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering if (mode < 0)
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Job mode %s invalid", smode);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering if (reload_if_possible)
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering verb = strjoin("reload-or-", job_type_to_string(job_type), NULL);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering else
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering verb = strdup(job_type_to_string(job_type));
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering if (!verb)
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering return -ENOMEM;
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering r = bus_verify_manage_units_async_full(
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering u,
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering verb,
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering CAP_SYS_ADMIN,
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering job_type < _JOB_TYPE_MAX ? polkit_message_for_job[job_type] : NULL,
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering message,
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering error);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering if (r < 0)
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return r;
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers if (r == 0)
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers return bus_unit_queue_job(message, u, job_type, mode, reload_if_possible, error);
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering}
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers
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);
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering}
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering
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);
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen}
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
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);
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering}
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering
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 Poettering}
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
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 Poettering}
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
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);
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering}
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
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 Poettering}
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringint bus_unit_method_kill(sd_bus_message *message, void *userdata, sd_bus_error *error) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Unit *u = userdata;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering const char *swho;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering int32_t signo;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering KillWho who;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering int r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering assert(message);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering assert(u);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering r = mac_selinux_unit_access_check(u, message, "stop", error);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (r < 0)
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering r = sd_bus_message_read(message, "si", &swho, &signo);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (r < 0)
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (isempty(swho))
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering who = KILL_ALL;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering else {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering who = kill_who_from_string(swho);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (who < 0)
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid who argument %s", swho);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering }
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering if (signo <= 0 || signo >= _NSIG)
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Signal number out of range.");
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering r = bus_verify_manage_units_async_full(
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering u,
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering "kill",
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering CAP_KILL,
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering N_("Authentication is required to kill '$(unit)'."),
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering message,
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering error);
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering if (r < 0)
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering return r;
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering if (r == 0)
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering r = unit_kill(u, who, signo, error);
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering if (r < 0)
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering return r;
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering return sd_bus_reply_method_return(message, NULL);
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering}
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poetteringint bus_unit_method_reset_failed(sd_bus_message *message, void *userdata, sd_bus_error *error) {
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering Unit *u = userdata;
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering int r;
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering assert(message);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering assert(u);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering r = mac_selinux_unit_access_check(u, message, "reload", error);
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering if (r < 0)
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering return r;
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering r = bus_verify_manage_units_async_full(
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering u,
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering "reset-failed",
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering CAP_SYS_ADMIN,
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering N_("Authentication is required to reset the \"failed\" state of '$(unit)'."),
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering message,
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering error);
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering if (r < 0)
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering return r;
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering if (r == 0)
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering unit_reset_failed(u);
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering return sd_bus_reply_method_return(message, NULL);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering}
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringint bus_unit_method_set_properties(sd_bus_message *message, void *userdata, sd_bus_error *error) {
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering Unit *u = userdata;
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering int runtime, r;
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering assert(message);
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering assert(u);
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering r = mac_selinux_unit_access_check(u, message, "start", error);
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering if (r < 0)
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering return r;
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering
e7e9b6bb0b0bc5b1eb256a44f8afec6b634f26efZbigniew Jędrzejewski-Szmek r = sd_bus_message_read(message, "b", &runtime);
e7e9b6bb0b0bc5b1eb256a44f8afec6b634f26efZbigniew Jędrzejewski-Szmek if (r < 0)
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering return r;
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering r = bus_verify_manage_units_async_full(
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering u,
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering "set-property",
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering CAP_SYS_ADMIN,
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering N_("Authentication is required to set properties on '$(unit)'."),
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering message,
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering error);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering if (r < 0)
a6c616024db23fef34152c1432892824a07799ccLennart Poettering return r;
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers if (r == 0)
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering r = bus_unit_set_properties(u, message, runtime ? UNIT_RUNTIME : UNIT_PERSISTENT, true, error);
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering if (r < 0)
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering return r;
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering return sd_bus_reply_method_return(message, NULL);
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering}
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poetteringconst sd_bus_vtable bus_unit_vtable[] = {
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers SD_BUS_VTABLE_START(0),
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers
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),
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen
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),
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen SD_BUS_VTABLE_END
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen};
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersenstatic int property_get_slice(
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen sd_bus *bus,
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen const char *path,
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen const char *interface,
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering const char *property,
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen sd_bus_message *reply,
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen void *userdata,
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen sd_bus_error *error) {
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen Unit *u = userdata;
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen
5b30bef856e89a571df57b7b953e9a1409d9acedLennart Poettering assert(bus);
5b30bef856e89a571df57b7b953e9a1409d9acedLennart Poettering assert(reply);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering assert(u);
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering return sd_bus_message_append(reply, "s", unit_slice_name(u));
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers}
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poetteringstatic int property_get_current_memory(
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering sd_bus *bus,
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering const char *path,
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering const char *interface,
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering const char *property,
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering sd_bus_message *reply,
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering void *userdata,
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering sd_bus_error *error) {
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering uint64_t sz = (uint64_t) -1;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering Unit *u = userdata;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering int r;
c19de71113f956809995fc68817e055e9f61f607Lennart Poettering
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering assert(bus);
c19de71113f956809995fc68817e055e9f61f607Lennart Poettering assert(reply);
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering assert(u);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering r = unit_get_memory_current(u, &sz);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering if (r < 0 && r != -ENODATA)
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering log_unit_warning_errno(u, r, "Failed to get memory.usage_in_bytes attribute: %m");
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering return sd_bus_message_append(reply, "t", sz);
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering}
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poetteringstatic int property_get_current_tasks(
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering sd_bus *bus,
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering const char *path,
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering const char *interface,
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering const char *property,
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering sd_bus_message *reply,
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering void *userdata,
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering sd_bus_error *error) {
9a14fb6285bdb089d4fc195410de3362cb4f586fThomas Hindoe Paaboel Andersen
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering uint64_t cn = (uint64_t) -1;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering Unit *u = userdata;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering int r;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering assert(bus);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering assert(reply);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering assert(u);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering r = unit_get_tasks_current(u, &cn);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering if (r < 0 && r != -ENODATA)
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering log_unit_warning_errno(u, r, "Failed to get pids.current attribute: %m");
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering return sd_bus_message_append(reply, "t", cn);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering}
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poetteringstatic int property_get_cpu_usage(
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering sd_bus *bus,
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering const char *path,
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering const char *interface,
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering const char *property,
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering sd_bus_message *reply,
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering void *userdata,
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering sd_bus_error *error) {
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering
c19de71113f956809995fc68817e055e9f61f607Lennart Poettering nsec_t ns = (nsec_t) -1;
c19de71113f956809995fc68817e055e9f61f607Lennart Poettering Unit *u = userdata;
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering int r;
c19de71113f956809995fc68817e055e9f61f607Lennart Poettering
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering assert(bus);
c19de71113f956809995fc68817e055e9f61f607Lennart Poettering assert(reply);
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering assert(u);
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering r = unit_get_cpu_usage(u, &ns);
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering if (r < 0 && r != -ENODATA)
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering log_unit_warning_errno(u, r, "Failed to get cpuacct.usage attribute: %m");
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering return sd_bus_message_append(reply, "t", ns);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering}
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poetteringstatic int property_get_cgroup(
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering sd_bus *bus,
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering const char *path,
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering const char *interface,
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering const char *property,
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering sd_bus_message *reply,
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering void *userdata,
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering sd_bus_error *error) {
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering
c19de71113f956809995fc68817e055e9f61f607Lennart Poettering Unit *u = userdata;
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering const char *t;
c19de71113f956809995fc68817e055e9f61f607Lennart Poettering
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering assert(bus);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering assert(reply);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering assert(u);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
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
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering if (u->cgroup_path)
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering t = isempty(u->cgroup_path) ? "/" : u->cgroup_path;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering else
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering t = "";
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering return sd_bus_message_append(reply, "s", t);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering}
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poetteringconst sd_bus_vtable bus_unit_cgroup_vtable[] = {
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering SD_BUS_VTABLE_START(0),
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 Poettering SD_BUS_VTABLE_END
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering};
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poetteringstatic int send_new_signal(sd_bus *bus, void *userdata) {
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering _cleanup_free_ char *p = NULL;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering Unit *u = userdata;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering int r;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering assert(bus);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering assert(u);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering p = unit_dbus_path(u);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering if (!p)
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering return -ENOMEM;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering r = sd_bus_message_new_signal(
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering bus,
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering &m,
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering "/org/freedesktop/systemd1",
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering "org.freedesktop.systemd1.Manager",
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering "UnitNew");
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering if (r < 0)
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering return r;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering r = sd_bus_message_append(m, "so", u->id, p);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering if (r < 0)
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering return r;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering return sd_bus_send(bus, m, NULL);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering}
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poetteringstatic int send_changed_signal(sd_bus *bus, void *userdata) {
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering _cleanup_free_ char *p = NULL;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering Unit *u = userdata;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering int r;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering assert(bus);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering assert(u);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering p = unit_dbus_path(u);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering if (!p)
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering return -ENOMEM;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
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
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering r = sd_bus_emit_properties_changed_strv(
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering bus, p,
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering unit_dbus_interface_from_type(u->type),
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering NULL);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering if (r < 0)
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering return r;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering return sd_bus_emit_properties_changed_strv(
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering bus, p,
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering "org.freedesktop.systemd1.Unit",
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering NULL);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering}
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poetteringvoid bus_unit_send_change_signal(Unit *u) {
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering int r;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering assert(u);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering if (u->in_dbus_queue) {
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering LIST_REMOVE(dbus_queue, u->manager->dbus_unit_queue, u);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering u->in_dbus_queue = false;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering }
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering if (!u->id)
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering return;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering r = bus_foreach_bus(u->manager, NULL, u->sent_dbus_new_signal ? send_changed_signal : send_new_signal, u);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering if (r < 0)
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering log_unit_debug_errno(u, r, "Failed to send unit change signal for %s: %m", u->id);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers u->sent_dbus_new_signal = true;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering}
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
56159e0d918e9a9be07988133bb2847779325de0Lennart Poetteringstatic int send_removed_signal(sd_bus *bus, void *userdata) {
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering _cleanup_free_ char *p = NULL;
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering Unit *u = userdata;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering int r;
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering assert(bus);
acf97e213e69a97e63ab8f7fad7ecd53608c757aLennart Poettering assert(u);
acf97e213e69a97e63ab8f7fad7ecd53608c757aLennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering p = unit_dbus_path(u);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (!p)
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return -ENOMEM;
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering r = sd_bus_message_new_signal(
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering bus,
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen &m,
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering "/org/freedesktop/systemd1",
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering "org.freedesktop.systemd1.Manager",
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering "UnitRemoved");
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering if (r < 0)
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering return r;
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering r = sd_bus_message_append(m, "so", u->id, p);
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering if (r < 0)
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen return r;
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return sd_bus_send(bus, m, NULL);
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen}
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringvoid bus_unit_send_removed_signal(Unit *u) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering int r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering assert(u);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering if (!u->sent_dbus_new_signal)
1dba654b27918c22e413ac5b3c19301f1ff86ad2Lennart Poettering bus_unit_send_change_signal(u);
1dba654b27918c22e413ac5b3c19301f1ff86ad2Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (!u->id)
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering return;
1dba654b27918c22e413ac5b3c19301f1ff86ad2Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering r = bus_foreach_bus(u->manager, NULL, send_removed_signal, u);
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering if (r < 0)
1dba654b27918c22e413ac5b3c19301f1ff86ad2Lennart Poettering log_unit_debug_errno(u, r, "Failed to send unit remove signal for %s: %m", u->id);
1dba654b27918c22e413ac5b3c19301f1ff86ad2Lennart Poettering}
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
56159e0d918e9a9be07988133bb2847779325de0Lennart Poetteringint bus_unit_queue_job(
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering sd_bus_message *message,
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Unit *u,
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering JobType type,
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering JobMode mode,
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering bool reload_if_possible,
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering sd_bus_error *error) {
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering _cleanup_free_ char *path = NULL;
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering Job *j;
acf97e213e69a97e63ab8f7fad7ecd53608c757aLennart Poettering int r;
acf97e213e69a97e63ab8f7fad7ecd53608c757aLennart Poettering
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering assert(message);
1dba654b27918c22e413ac5b3c19301f1ff86ad2Lennart Poettering assert(u);
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering assert(type >= 0 && type < _JOB_TYPE_MAX);
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering assert(mode >= 0 && mode < _JOB_MODE_MAX);
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering if (reload_if_possible && unit_can_reload(u)) {
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering if (type == JOB_RESTART)
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering type = JOB_RELOAD_OR_START;
1dba654b27918c22e413ac5b3c19301f1ff86ad2Lennart Poettering else if (type == JOB_TRY_RESTART)
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering type = JOB_RELOAD;
1dba654b27918c22e413ac5b3c19301f1ff86ad2Lennart Poettering }
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering r = mac_selinux_unit_access_check(
1dba654b27918c22e413ac5b3c19301f1ff86ad2Lennart Poettering u, message,
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering (type == JOB_START || type == JOB_RESTART || type == JOB_TRY_RESTART) ? "start" :
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering type == JOB_STOP ? "stop" : "reload", error);
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering if (r < 0)
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering return r;
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering if (type == JOB_STOP &&
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering (u->load_state == UNIT_NOT_FOUND || u->load_state == UNIT_ERROR) &&
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering unit_active_state(u) == UNIT_INACTIVE)
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s not loaded.", u->id);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
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
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = manager_add_job(u->manager, type, u, mode, error, &j);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (r < 0)
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return r;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (sd_bus_message_get_bus(message) == u->manager->api_bus) {
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (!j->clients) {
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = sd_bus_track_new(sd_bus_message_get_bus(message), &j->clients, NULL, NULL);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (r < 0)
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return r;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering }
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = sd_bus_track_add_sender(j->clients, message);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (r < 0)
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return r;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering }
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering path = job_dbus_path(j);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (!path)
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return -ENOMEM;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return sd_bus_reply_method_return(message, "o", path);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering}
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poetteringstatic int bus_unit_set_transient_property(
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering Unit *u,
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering const char *name,
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering sd_bus_message *message,
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering UnitSetPropertiesMode mode,
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering sd_bus_error *error) {
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering int r;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering assert(u);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering assert(name);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering assert(message);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (streq(name, "Description")) {
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering const char *d;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = sd_bus_message_read(message, "s", &d);
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering if (r < 0)
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering return r;
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering if (mode != UNIT_CHECK) {
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering r = unit_set_description(u, d);
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering if (r < 0)
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering return r;
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering unit_write_drop_in_format(u, mode, name, "[Unit]\nDescription=%s\n", d);
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering }
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering return 1;
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering } else if (streq(name, "DefaultDependencies")) {
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering int b;
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering r = sd_bus_message_read(message, "b", &b);
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering if (r < 0)
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering return r;
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering if (mode != UNIT_CHECK) {
bb4a228207815df88cdf68acd9e46ec19e0d3e30Lennart Poettering u->default_dependencies = b;
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering unit_write_drop_in_format(u, mode, name, "[Unit]\nDefaultDependencies=%s\n", yes_no(b));
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering }
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering
bb4a228207815df88cdf68acd9e46ec19e0d3e30Lennart Poettering return 1;
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering } else if (streq(name, "Slice")) {
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering Unit *slice;
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering const char *s;
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering if (!UNIT_HAS_CGROUP_CONTEXT(u))
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 if (u->type == UNIT_SLICE)
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
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering r = sd_bus_message_read(message, "s", &s);
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering if (r < 0)
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering return r;
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering
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
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering r = manager_load_unit(u->manager, s, NULL, error, &slice);
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering if (r < 0)
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering return r;
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering if (slice->type != UNIT_SLICE)
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unit name '%s' is not a slice", s);
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering if (mode != UNIT_CHECK) {
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering r = unit_set_slice(u, slice);
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering if (r < 0)
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering return r;
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering unit_write_drop_in_private_format(u, mode, name, "Slice=%s\n", s);
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering }
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering return 1;
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering } else if (STR_IN_SET(name,
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering "Requires", "RequiresOverridable",
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering "Requisite", "RequisiteOverridable",
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering "Wants",
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering "BindsTo",
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering "Conflicts",
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering "Before", "After",
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering "OnFailure",
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering "PropagatesReloadTo", "ReloadPropagatedFrom",
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering "PartOf")) {
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering UnitDependency d;
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering const char *other;
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering if (streq(name, "RequiresOverridable"))
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering d = UNIT_REQUIRES; /* redirect for obsolete unit dependency type */
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering else if (streq(name, "RequisiteOverridable"))
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering d = UNIT_REQUISITE; /* same here */
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering else {
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering d = unit_dependency_from_string(name);
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering if (d < 0)
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid unit dependency: %s", name);
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering }
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering r = sd_bus_message_enter_container(message, 'a', "s");
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering if (r < 0)
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering return r;
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering
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
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (mode != UNIT_CHECK) {
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering _cleanup_free_ char *label = NULL;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = unit_add_dependency_by_name(u, d, other, NULL, true);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (r < 0)
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return r;
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering label = strjoin(name, "-", other, NULL);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (!label)
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return -ENOMEM;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering unit_write_drop_in_format(u, mode, label, "[Unit]\n%s=%s\n", name, other);
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering }
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering }
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (r < 0)
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return r;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering r = sd_bus_message_exit_container(message);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (r < 0)
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return r;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return 1;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering }
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return 0;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering}
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poetteringint bus_unit_set_properties(
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering Unit *u,
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering sd_bus_message *message,
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering UnitSetPropertiesMode mode,
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering bool commit,
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering sd_bus_error *error) {
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering bool for_real = false;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering unsigned n = 0;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering int r;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering assert(u);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering assert(message);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
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
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = sd_bus_message_enter_container(message, 'a', "(sv)");
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (r < 0)
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return r;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering for (;;) {
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering const char *name;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = sd_bus_message_enter_container(message, 'r', "sv");
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (r < 0)
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return r;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (r == 0) {
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (for_real || mode == UNIT_CHECK)
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering break;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering /* Reached EOF. Let's try again, and this time for realz... */
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = sd_bus_message_rewind(message, false);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (r < 0)
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering return r;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering for_real = true;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering continue;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering }
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = sd_bus_message_read(message, "s", &name);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (r < 0)
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return r;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (!UNIT_VTABLE(u)->bus_set_property)
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
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = sd_bus_message_enter_container(message, 'v', NULL);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (r < 0)
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return r;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
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 if (r < 0)
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return r;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (r == 0)
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_PROPERTY_READ_ONLY, "Cannot set property %s, or unknown property.", name);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = sd_bus_message_exit_container(message);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (r < 0)
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return r;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = sd_bus_message_exit_container(message);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (r < 0)
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return r;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering n += for_real;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering }
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering r = sd_bus_message_exit_container(message);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (r < 0)
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return r;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (commit && n > 0 && UNIT_VTABLE(u)->bus_commit_properties)
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering UNIT_VTABLE(u)->bus_commit_properties(u);
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return n;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering}
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poetteringint bus_unit_check_load_state(Unit *u, sd_bus_error *error) {
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (u->load_state == UNIT_LOADED)
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return 0;
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
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 if (u->load_state == UNIT_MASKED)
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return sd_bus_error_setf(error, BUS_ERROR_UNIT_MASKED, "Unit is masked.");
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering if (u->load_state == UNIT_NOT_FOUND)
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit not found.");
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering return sd_bus_error_set_errnof(error, u->load_error, "Unit is not loaded properly: %m.");
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering}
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering