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 " <property name=\"TimeoutStopUSec\" type=\"t\" access=\"read\"/>\n" \
34 BUS_KILL_CONTEXT_INTERFACE \
35 BUS_CGROUP_CONTEXT_INTERFACE \
36 " <property name=\"Result\" type=\"s\" access=\"read\"/>\n" \
39 #define INTROSPECTION \
40 DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
44 BUS_PROPERTIES_INTERFACE \
46 BUS_INTROSPECTABLE_INTERFACE \
49 #define INTERFACES_LIST \
50 BUS_UNIT_INTERFACES_LIST \
51 "org.freedesktop.systemd1.Scope\0"
53 const char bus_scope_interface
[] _introspect_("Scope") = BUS_SCOPE_INTERFACE
;
55 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_scope_append_scope_result
, scope_result
, ScopeResult
);
57 static const BusProperty bus_scope_properties
[] = {
58 { "TimeoutStopUSec", bus_property_append_usec
, "t", offsetof(Scope
, timeout_stop_usec
) },
59 { "Result", bus_scope_append_scope_result
, "s", offsetof(Scope
, result
) },
63 DBusHandlerResult
bus_scope_message_handler(Unit
*u
, DBusConnection
*c
, DBusMessage
*message
) {
66 const BusBoundProperties bps
[] = {
67 { "org.freedesktop.systemd1.Unit", bus_unit_properties
, u
},
68 { "org.freedesktop.systemd1.Scope", bus_scope_properties
, s
},
69 { "org.freedesktop.systemd1.Scope", bus_cgroup_context_properties
, &s
->cgroup_context
},
70 { "org.freedesktop.systemd1.Scope", bus_kill_context_properties
, &s
->kill_context
},
74 SELINUX_UNIT_ACCESS_CHECK(u
, c
, message
, "status");
76 return bus_default_message_handler(c
, message
, INTROSPECTION
, INTERFACES_LIST
, bps
);
79 static int bus_scope_set_transient_property(
83 UnitSetPropertiesMode mode
,
92 if (streq(name
, "PIDs")) {
95 if (dbus_message_iter_get_arg_type(i
) != DBUS_TYPE_ARRAY
||
96 dbus_message_iter_get_element_type(i
) != DBUS_TYPE_UINT32
)
99 r
= set_ensure_allocated(&s
->pids
, trivial_hash_func
, trivial_compare_func
);
103 dbus_message_iter_recurse(i
, &sub
);
104 while (dbus_message_iter_get_arg_type(&sub
) == DBUS_TYPE_UINT32
) {
107 dbus_message_iter_get_basic(&sub
, &pid
);
112 r
= set_put(s
->pids
, LONG_TO_PTR(pid
));
113 if (r
< 0 && r
!= -EEXIST
)
116 dbus_message_iter_next(&sub
);
119 if (set_size(s
->pids
) <= 0)
128 int bus_scope_set_property(
132 UnitSetPropertiesMode mode
,
142 r
= bus_cgroup_set_property(u
, &s
->cgroup_context
, name
, i
, mode
, error
);
146 if (u
->load_state
== UNIT_STUB
) {
147 /* While we are created we still accept PIDs */
149 r
= bus_scope_set_transient_property(s
, name
, i
, mode
, error
);
157 int bus_scope_commit_properties(Unit
*u
) {
160 unit_realize_cgroup(u
);