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-common.h"
26 #include "dbus-cgroup.h"
27 #include "dbus-kill.h"
28 #include "selinux-access.h"
29 #include "dbus-scope.h"
31 #define BUS_SCOPE_INTERFACE \
32 " <interface name=\"org.freedesktop.systemd1.Scope\">\n" \
33 BUS_UNIT_CGROUP_INTERFACE \
34 " <property name=\"TimeoutStopUSec\" type=\"t\" access=\"read\"/>\n" \
35 BUS_KILL_CONTEXT_INTERFACE \
36 BUS_CGROUP_CONTEXT_INTERFACE \
37 " <property name=\"Result\" type=\"s\" access=\"read\"/>\n" \
40 #define INTROSPECTION \
41 DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
45 BUS_PROPERTIES_INTERFACE \
47 BUS_INTROSPECTABLE_INTERFACE \
50 #define INTERFACES_LIST \
51 BUS_UNIT_INTERFACES_LIST \
52 "org.freedesktop.systemd1.Scope\0"
54 const char bus_scope_interface[] = BUS_SCOPE_INTERFACE;
56 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_scope_append_scope_result, scope_result, ScopeResult);
58 static const BusProperty bus_scope_properties[] = {
59 { "TimeoutStopUSec", bus_property_append_usec, "t", offsetof(Scope, timeout_stop_usec) },
60 { "Result", bus_scope_append_scope_result, "s", offsetof(Scope, result) },
64 DBusHandlerResult bus_scope_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
67 const BusBoundProperties bps[] = {
68 { "org.freedesktop.systemd1.Unit", bus_unit_properties, u },
69 { "org.freedesktop.systemd1.Scope", bus_unit_cgroup_properties, u },
70 { "org.freedesktop.systemd1.Scope", bus_scope_properties, s },
71 { "org.freedesktop.systemd1.Scope", bus_cgroup_context_properties, &s->cgroup_context },
72 { "org.freedesktop.systemd1.Scope", bus_kill_context_properties, &s->kill_context },
76 SELINUX_UNIT_ACCESS_CHECK(u, c, message, "status");
78 return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, bps);
81 static int bus_scope_set_transient_property(
85 UnitSetPropertiesMode mode,
94 if (streq(name, "PIDs")) {
98 if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_ARRAY ||
99 dbus_message_iter_get_element_type(i) != DBUS_TYPE_UINT32)
102 r = set_ensure_allocated(&s->pids, trivial_hash_func, trivial_compare_func);
106 dbus_message_iter_recurse(i, &sub);
107 while (dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_UINT32) {
110 dbus_message_iter_get_basic(&sub, &pid);
115 if (mode != UNIT_CHECK) {
116 r = set_put(s->pids, LONG_TO_PTR(pid));
117 if (r < 0 && r != -EEXIST)
121 dbus_message_iter_next(&sub);
130 } else if (streq(name, "TimeoutStopUSec")) {
132 if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_UINT64)
135 if (mode != UNIT_CHECK) {
138 dbus_message_iter_get_basic(i, &t);
140 s->timeout_stop_usec = t;
142 unit_write_drop_in_format(UNIT(s), mode, name, "[Scope]\nTimeoutStopSec=%lluus\n", (unsigned long long) t);
151 int bus_scope_set_property(
155 UnitSetPropertiesMode mode,
165 r = bus_cgroup_set_property(u, &s->cgroup_context, name, i, mode, error);
169 if (u->load_state == UNIT_STUB) {
170 /* While we are created we still accept PIDs */
172 r = bus_scope_set_transient_property(s, name, i, mode, error);
176 r = bus_kill_context_set_transient_property(u, &s->kill_context, name, i, mode, error);
184 int bus_scope_commit_properties(Unit *u) {
187 unit_realize_cgroup(u);