1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2013 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 #include "dbus-unit.h"
25 #include "dbus-cgroup.h"
26 #include "dbus-kill.h"
27 #include "dbus-scope.h"
30 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, scope_result, ScopeResult);
32 const sd_bus_vtable bus_scope_vtable[] = {
33 SD_BUS_VTABLE_START(0),
34 SD_BUS_PROPERTY("TimeoutStopUSec", "t", bus_property_get_usec, offsetof(Scope, timeout_stop_usec), SD_BUS_VTABLE_PROPERTY_CONST),
35 SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Scope, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
39 static int bus_scope_set_transient_property(
42 sd_bus_message *message,
43 UnitSetPropertiesMode mode,
44 sd_bus_error *error) {
52 if (streq(name, "PIDs")) {
56 r = set_ensure_allocated(&s->pids, trivial_hash_func, trivial_compare_func);
60 r = sd_bus_message_enter_container(message, 'a', "u");
64 while ((r = sd_bus_message_read(message, "u", &pid)) > 0) {
69 if (mode != UNIT_CHECK) {
70 r = set_put(s->pids, LONG_TO_PTR(pid));
71 if (r < 0 && r != -EEXIST)
80 r = sd_bus_message_exit_container(message);
89 } else if (streq(name, "TimeoutStopUSec")) {
91 if (mode != UNIT_CHECK) {
92 r = sd_bus_message_read(message, "t", &s->timeout_stop_usec);
96 unit_write_drop_in_format(UNIT(s), mode, name, "[Scope]\nTimeoutStopSec=%lluus\n", (unsigned long long) s->timeout_stop_usec);
98 r = sd_bus_message_skip(message, "t");
109 int bus_scope_set_property(
112 sd_bus_message *message,
113 UnitSetPropertiesMode mode,
114 sd_bus_error *error) {
123 r = bus_cgroup_set_property(u, &s->cgroup_context, name, message, mode, error);
127 if (u->load_state == UNIT_STUB) {
128 /* While we are created we still accept PIDs */
130 r = bus_scope_set_transient_property(s, name, message, mode, error);
134 r = bus_kill_context_set_transient_property(u, &s->kill_context, name, message, mode, error);
142 int bus_scope_commit_properties(Unit *u) {
145 unit_realize_cgroup(u);