File: | build-scan/../src/core/slice.c |
Warning: | line 332, column 28 1st function call argument is an uninitialized value |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* SPDX-License-Identifier: LGPL-2.1+ */ | |||
2 | ||||
3 | #include <errno(*__errno_location ()).h> | |||
4 | ||||
5 | #include "alloc-util.h" | |||
6 | #include "dbus-slice.h" | |||
7 | #include "log.h" | |||
8 | #include "slice.h" | |||
9 | #include "special.h" | |||
10 | #include "string-util.h" | |||
11 | #include "strv.h" | |||
12 | #include "unit-name.h" | |||
13 | #include "unit.h" | |||
14 | ||||
15 | static const UnitActiveState state_translation_table[_SLICE_STATE_MAX] = { | |||
16 | [SLICE_DEAD] = UNIT_INACTIVE, | |||
17 | [SLICE_ACTIVE] = UNIT_ACTIVE | |||
18 | }; | |||
19 | ||||
20 | static void slice_init(Unit *u) { | |||
21 | assert(u)do { if ((__builtin_expect(!!(!(u)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("u"), "../src/core/slice.c", 21, __PRETTY_FUNCTION__ ); } while (0); | |||
22 | assert(u->load_state == UNIT_STUB)do { if ((__builtin_expect(!!(!(u->load_state == UNIT_STUB )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("u->load_state == UNIT_STUB" ), "../src/core/slice.c", 22, __PRETTY_FUNCTION__); } while ( 0); | |||
23 | ||||
24 | u->ignore_on_isolate = true1; | |||
25 | } | |||
26 | ||||
27 | static void slice_set_state(Slice *t, SliceState state) { | |||
28 | SliceState old_state; | |||
29 | assert(t)do { if ((__builtin_expect(!!(!(t)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("t"), "../src/core/slice.c", 29, __PRETTY_FUNCTION__ ); } while (0); | |||
30 | ||||
31 | old_state = t->state; | |||
32 | t->state = state; | |||
33 | ||||
34 | if (state != old_state) | |||
35 | log_debug("%s changed %s -> %s",({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/slice.c", 38, __func__, "%s changed %s -> %s" , ({ typeof(t) _u_ = (t); Unit *_w_ = _u_ ? &(_u_)->meta : ((void*)0); _w_; })->id, slice_state_to_string(old_state ), slice_state_to_string(state)) : -abs(_e); }) | |||
36 | UNIT(t)->id,({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/slice.c", 38, __func__, "%s changed %s -> %s" , ({ typeof(t) _u_ = (t); Unit *_w_ = _u_ ? &(_u_)->meta : ((void*)0); _w_; })->id, slice_state_to_string(old_state ), slice_state_to_string(state)) : -abs(_e); }) | |||
37 | slice_state_to_string(old_state),({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/slice.c", 38, __func__, "%s changed %s -> %s" , ({ typeof(t) _u_ = (t); Unit *_w_ = _u_ ? &(_u_)->meta : ((void*)0); _w_; })->id, slice_state_to_string(old_state ), slice_state_to_string(state)) : -abs(_e); }) | |||
38 | slice_state_to_string(state))({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/slice.c", 38, __func__, "%s changed %s -> %s" , ({ typeof(t) _u_ = (t); Unit *_w_ = _u_ ? &(_u_)->meta : ((void*)0); _w_; })->id, slice_state_to_string(old_state ), slice_state_to_string(state)) : -abs(_e); }); | |||
39 | ||||
40 | unit_notify(UNIT(t)({ typeof(t) _u_ = (t); Unit *_w_ = _u_ ? &(_u_)->meta : ((void*)0); _w_; }), state_translation_table[old_state], state_translation_table[state], 0); | |||
41 | } | |||
42 | ||||
43 | static int slice_add_parent_slice(Slice *s) { | |||
44 | Unit *u = UNIT(s)({ typeof(s) _u_ = (s); Unit *_w_ = _u_ ? &(_u_)->meta : ((void*)0); _w_; }), *parent; | |||
45 | _cleanup_free___attribute__((cleanup(freep))) char *a = NULL((void*)0); | |||
46 | int r; | |||
47 | ||||
48 | assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("s"), "../src/core/slice.c", 48, __PRETTY_FUNCTION__ ); } while (0); | |||
49 | ||||
50 | if (UNIT_ISSET(u->slice)(!!(u->slice).target)) | |||
51 | return 0; | |||
52 | ||||
53 | r = slice_build_parent_slice(u->id, &a); | |||
54 | if (r <= 0) /* 0 means root slice */ | |||
55 | return r; | |||
56 | ||||
57 | r = manager_load_unit(u->manager, a, NULL((void*)0), NULL((void*)0), &parent); | |||
58 | if (r < 0) | |||
59 | return r; | |||
60 | ||||
61 | unit_ref_set(&u->slice, u, parent); | |||
62 | return 0; | |||
63 | } | |||
64 | ||||
65 | static int slice_add_default_dependencies(Slice *s) { | |||
66 | int r; | |||
67 | ||||
68 | assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("s"), "../src/core/slice.c", 68, __PRETTY_FUNCTION__ ); } while (0); | |||
69 | ||||
70 | if (!UNIT(s)({ typeof(s) _u_ = (s); Unit *_w_ = _u_ ? &(_u_)->meta : ((void*)0); _w_; })->default_dependencies) | |||
71 | return 0; | |||
72 | ||||
73 | /* Make sure slices are unloaded on shutdown */ | |||
74 | r = unit_add_two_dependencies_by_name( | |||
75 | UNIT(s)({ typeof(s) _u_ = (s); Unit *_w_ = _u_ ? &(_u_)->meta : ((void*)0); _w_; }), | |||
76 | UNIT_BEFORE, UNIT_CONFLICTS, | |||
77 | SPECIAL_SHUTDOWN_TARGET"shutdown.target", NULL((void*)0), true1, UNIT_DEPENDENCY_DEFAULT); | |||
78 | if (r < 0) | |||
79 | return r; | |||
80 | ||||
81 | return 0; | |||
82 | } | |||
83 | ||||
84 | static int slice_verify(Slice *s) { | |||
85 | _cleanup_free___attribute__((cleanup(freep))) char *parent = NULL((void*)0); | |||
86 | int r; | |||
87 | ||||
88 | assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("s"), "../src/core/slice.c", 88, __PRETTY_FUNCTION__ ); } while (0); | |||
89 | ||||
90 | if (UNIT(s)({ typeof(s) _u_ = (s); Unit *_w_ = _u_ ? &(_u_)->meta : ((void*)0); _w_; })->load_state != UNIT_LOADED) | |||
91 | return 0; | |||
92 | ||||
93 | if (!slice_name_is_valid(UNIT(s)({ typeof(s) _u_ = (s); Unit *_w_ = _u_ ? &(_u_)->meta : ((void*)0); _w_; })->id)) { | |||
94 | log_unit_error(UNIT(s), "Slice name %s is not valid. Refusing.", UNIT(s)->id)({ const Unit *_u = (({ typeof(s) _u_ = (s); Unit *_w_ = _u_ ? &(_u_)->meta : ((void*)0); _w_; })); _u ? log_object_internal (3, 0, "../src/core/slice.c", 94, __func__, _u->manager-> unit_log_field, _u->id, _u->manager->invocation_log_field , _u->invocation_id_string, "Slice name %s is not valid. Refusing." , ({ typeof(s) _u_ = (s); Unit *_w_ = _u_ ? &(_u_)->meta : ((void*)0); _w_; })->id) : log_internal_realm(((LOG_REALM_SYSTEMD ) << 10 | ((3))), 0, "../src/core/slice.c", 94, __func__ , "Slice name %s is not valid. Refusing.", ({ typeof(s) _u_ = (s); Unit *_w_ = _u_ ? &(_u_)->meta : ((void*)0); _w_ ; })->id); }); | |||
95 | return -ENOEXEC8; | |||
96 | } | |||
97 | ||||
98 | r = slice_build_parent_slice(UNIT(s)({ typeof(s) _u_ = (s); Unit *_w_ = _u_ ? &(_u_)->meta : ((void*)0); _w_; })->id, &parent); | |||
99 | if (r < 0) | |||
100 | return log_unit_error_errno(UNIT(s), r, "Failed to determine parent slice: %m")({ const Unit *_u = (({ typeof(s) _u_ = (s); Unit *_w_ = _u_ ? &(_u_)->meta : ((void*)0); _w_; })); _u ? log_object_internal (3, r, "../src/core/slice.c", 100, __func__, _u->manager-> unit_log_field, _u->id, _u->manager->invocation_log_field , _u->invocation_id_string, "Failed to determine parent slice: %m" ) : log_internal_realm(((LOG_REALM_SYSTEMD) << 10 | ((3 ))), r, "../src/core/slice.c", 100, __func__, "Failed to determine parent slice: %m" ); }); | |||
101 | ||||
102 | if (parent ? !unit_has_name(UNIT_DEREF(UNIT(s)->slice)((({ typeof(s) _u_ = (s); Unit *_w_ = _u_ ? &(_u_)->meta : ((void*)0); _w_; })->slice).target), parent) : UNIT_ISSET(UNIT(s)->slice)(!!(({ typeof(s) _u_ = (s); Unit *_w_ = _u_ ? &(_u_)-> meta : ((void*)0); _w_; })->slice).target)) { | |||
103 | log_unit_error(UNIT(s), "Located outside of parent slice. Refusing.")({ const Unit *_u = (({ typeof(s) _u_ = (s); Unit *_w_ = _u_ ? &(_u_)->meta : ((void*)0); _w_; })); _u ? log_object_internal (3, 0, "../src/core/slice.c", 103, __func__, _u->manager-> unit_log_field, _u->id, _u->manager->invocation_log_field , _u->invocation_id_string, "Located outside of parent slice. Refusing." ) : log_internal_realm(((LOG_REALM_SYSTEMD) << 10 | ((3 ))), 0, "../src/core/slice.c", 103, __func__, "Located outside of parent slice. Refusing." ); }); | |||
104 | return -ENOEXEC8; | |||
105 | } | |||
106 | ||||
107 | return 0; | |||
108 | } | |||
109 | ||||
110 | static int slice_load_root_slice(Unit *u) { | |||
111 | assert(u)do { if ((__builtin_expect(!!(!(u)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("u"), "../src/core/slice.c", 111, __PRETTY_FUNCTION__ ); } while (0); | |||
112 | ||||
113 | if (!unit_has_name(u, SPECIAL_ROOT_SLICE"-.slice")) | |||
114 | return 0; | |||
115 | ||||
116 | u->perpetual = true1; | |||
117 | ||||
118 | /* The root slice is a bit special. For example it is always running and cannot be terminated. Because of its | |||
119 | * special semantics we synthesize it here, instead of relying on the unit file on disk. */ | |||
120 | ||||
121 | u->default_dependencies = false0; | |||
122 | ||||
123 | if (!u->description) | |||
124 | u->description = strdup("Root Slice"); | |||
125 | if (!u->documentation) | |||
126 | u->documentation = strv_new("man:systemd.special(7)", NULL((void*)0)); | |||
127 | ||||
128 | return 1; | |||
129 | } | |||
130 | ||||
131 | static int slice_load_system_slice(Unit *u) { | |||
132 | assert(u)do { if ((__builtin_expect(!!(!(u)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("u"), "../src/core/slice.c", 132, __PRETTY_FUNCTION__ ); } while (0); | |||
133 | ||||
134 | if (!MANAGER_IS_SYSTEM(u->manager)((u->manager)->unit_file_scope == UNIT_FILE_SYSTEM)) | |||
135 | return 0; | |||
136 | if (!unit_has_name(u, SPECIAL_SYSTEM_SLICE"system.slice")) | |||
137 | return 0; | |||
138 | ||||
139 | u->perpetual = true1; | |||
140 | ||||
141 | /* The system slice is a bit special. For example it is always running and cannot be terminated. Because of its | |||
142 | * special semantics we synthesize it here, instead of relying on the unit file on disk. */ | |||
143 | ||||
144 | u->default_dependencies = false0; | |||
145 | ||||
146 | if (!u->description) | |||
147 | u->description = strdup("System Slice"); | |||
148 | if (!u->documentation) | |||
149 | u->documentation = strv_new("man:systemd.special(7)", NULL((void*)0)); | |||
150 | ||||
151 | return 1; | |||
152 | } | |||
153 | ||||
154 | static int slice_load(Unit *u) { | |||
155 | Slice *s = SLICE(u); | |||
156 | int r; | |||
157 | ||||
158 | assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("s"), "../src/core/slice.c", 158, __PRETTY_FUNCTION__ ); } while (0); | |||
159 | assert(u->load_state == UNIT_STUB)do { if ((__builtin_expect(!!(!(u->load_state == UNIT_STUB )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("u->load_state == UNIT_STUB" ), "../src/core/slice.c", 159, __PRETTY_FUNCTION__); } while ( 0); | |||
160 | ||||
161 | r = slice_load_root_slice(u); | |||
162 | if (r < 0) | |||
163 | return r; | |||
164 | r = slice_load_system_slice(u); | |||
165 | if (r < 0) | |||
166 | return r; | |||
167 | ||||
168 | r = unit_load_fragment_and_dropin_optional(u); | |||
169 | if (r < 0) | |||
170 | return r; | |||
171 | ||||
172 | /* This is a new unit? Then let's add in some extras */ | |||
173 | if (u->load_state == UNIT_LOADED) { | |||
174 | ||||
175 | r = unit_patch_contexts(u); | |||
176 | if (r < 0) | |||
177 | return r; | |||
178 | ||||
179 | r = slice_add_parent_slice(s); | |||
180 | if (r < 0) | |||
181 | return r; | |||
182 | ||||
183 | r = slice_add_default_dependencies(s); | |||
184 | if (r < 0) | |||
185 | return r; | |||
186 | } | |||
187 | ||||
188 | return slice_verify(s); | |||
189 | } | |||
190 | ||||
191 | static int slice_coldplug(Unit *u) { | |||
192 | Slice *t = SLICE(u); | |||
193 | ||||
194 | assert(t)do { if ((__builtin_expect(!!(!(t)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("t"), "../src/core/slice.c", 194, __PRETTY_FUNCTION__ ); } while (0); | |||
195 | assert(t->state == SLICE_DEAD)do { if ((__builtin_expect(!!(!(t->state == SLICE_DEAD)),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("t->state == SLICE_DEAD" ), "../src/core/slice.c", 195, __PRETTY_FUNCTION__); } while ( 0); | |||
196 | ||||
197 | if (t->deserialized_state != t->state) | |||
198 | slice_set_state(t, t->deserialized_state); | |||
199 | ||||
200 | return 0; | |||
201 | } | |||
202 | ||||
203 | static void slice_dump(Unit *u, FILE *f, const char *prefix) { | |||
204 | Slice *t = SLICE(u); | |||
205 | ||||
206 | assert(t)do { if ((__builtin_expect(!!(!(t)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("t"), "../src/core/slice.c", 206, __PRETTY_FUNCTION__ ); } while (0); | |||
207 | assert(f)do { if ((__builtin_expect(!!(!(f)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("f"), "../src/core/slice.c", 207, __PRETTY_FUNCTION__ ); } while (0); | |||
208 | ||||
209 | fprintf(f, | |||
210 | "%sSlice State: %s\n", | |||
211 | prefix, slice_state_to_string(t->state)); | |||
212 | ||||
213 | cgroup_context_dump(&t->cgroup_context, f, prefix); | |||
214 | } | |||
215 | ||||
216 | static int slice_start(Unit *u) { | |||
217 | Slice *t = SLICE(u); | |||
218 | int r; | |||
219 | ||||
220 | assert(t)do { if ((__builtin_expect(!!(!(t)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("t"), "../src/core/slice.c", 220, __PRETTY_FUNCTION__ ); } while (0); | |||
221 | assert(t->state == SLICE_DEAD)do { if ((__builtin_expect(!!(!(t->state == SLICE_DEAD)),0 ))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("t->state == SLICE_DEAD" ), "../src/core/slice.c", 221, __PRETTY_FUNCTION__); } while ( 0); | |||
222 | ||||
223 | r = unit_acquire_invocation_id(u); | |||
224 | if (r < 0) | |||
225 | return r; | |||
226 | ||||
227 | (void) unit_realize_cgroup(u); | |||
228 | (void) unit_reset_cpu_accounting(u); | |||
229 | (void) unit_reset_ip_accounting(u); | |||
230 | ||||
231 | slice_set_state(t, SLICE_ACTIVE); | |||
232 | return 1; | |||
233 | } | |||
234 | ||||
235 | static int slice_stop(Unit *u) { | |||
236 | Slice *t = SLICE(u); | |||
237 | ||||
238 | assert(t)do { if ((__builtin_expect(!!(!(t)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("t"), "../src/core/slice.c", 238, __PRETTY_FUNCTION__ ); } while (0); | |||
239 | assert(t->state == SLICE_ACTIVE)do { if ((__builtin_expect(!!(!(t->state == SLICE_ACTIVE)) ,0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("t->state == SLICE_ACTIVE" ), "../src/core/slice.c", 239, __PRETTY_FUNCTION__); } while ( 0); | |||
240 | ||||
241 | /* We do not need to destroy the cgroup explicitly, | |||
242 | * unit_notify() will do that for us anyway. */ | |||
243 | ||||
244 | slice_set_state(t, SLICE_DEAD); | |||
245 | return 1; | |||
246 | } | |||
247 | ||||
248 | static int slice_kill(Unit *u, KillWho who, int signo, sd_bus_error *error) { | |||
249 | return unit_kill_common(u, who, signo, -1, -1, error); | |||
250 | } | |||
251 | ||||
252 | static int slice_serialize(Unit *u, FILE *f, FDSet *fds) { | |||
253 | Slice *s = SLICE(u); | |||
254 | ||||
255 | assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("s"), "../src/core/slice.c", 255, __PRETTY_FUNCTION__ ); } while (0); | |||
256 | assert(f)do { if ((__builtin_expect(!!(!(f)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("f"), "../src/core/slice.c", 256, __PRETTY_FUNCTION__ ); } while (0); | |||
257 | assert(fds)do { if ((__builtin_expect(!!(!(fds)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fds"), "../src/core/slice.c", 257, __PRETTY_FUNCTION__ ); } while (0); | |||
258 | ||||
259 | unit_serialize_item(u, f, "state", slice_state_to_string(s->state)); | |||
260 | return 0; | |||
261 | } | |||
262 | ||||
263 | static int slice_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) { | |||
264 | Slice *s = SLICE(u); | |||
265 | ||||
266 | assert(u)do { if ((__builtin_expect(!!(!(u)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("u"), "../src/core/slice.c", 266, __PRETTY_FUNCTION__ ); } while (0); | |||
267 | assert(key)do { if ((__builtin_expect(!!(!(key)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("key"), "../src/core/slice.c", 267, __PRETTY_FUNCTION__ ); } while (0); | |||
268 | assert(value)do { if ((__builtin_expect(!!(!(value)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("value"), "../src/core/slice.c", 268, __PRETTY_FUNCTION__ ); } while (0); | |||
269 | assert(fds)do { if ((__builtin_expect(!!(!(fds)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("fds"), "../src/core/slice.c", 269, __PRETTY_FUNCTION__ ); } while (0); | |||
270 | ||||
271 | if (streq(key, "state")(strcmp((key),("state")) == 0)) { | |||
272 | SliceState state; | |||
273 | ||||
274 | state = slice_state_from_string(value); | |||
275 | if (state < 0) | |||
276 | log_debug("Failed to parse state value %s", value)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/slice.c", 276, __func__, "Failed to parse state value %s" , value) : -abs(_e); }); | |||
277 | else | |||
278 | s->deserialized_state = state; | |||
279 | ||||
280 | } else | |||
281 | log_debug("Unknown serialization key '%s'", key)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/slice.c", 281, __func__, "Unknown serialization key '%s'" , key) : -abs(_e); }); | |||
282 | ||||
283 | return 0; | |||
284 | } | |||
285 | ||||
286 | _pure___attribute__ ((pure)) static UnitActiveState slice_active_state(Unit *u) { | |||
287 | assert(u)do { if ((__builtin_expect(!!(!(u)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("u"), "../src/core/slice.c", 287, __PRETTY_FUNCTION__ ); } while (0); | |||
288 | ||||
289 | return state_translation_table[SLICE(u)->state]; | |||
290 | } | |||
291 | ||||
292 | _pure___attribute__ ((pure)) static const char *slice_sub_state_to_string(Unit *u) { | |||
293 | assert(u)do { if ((__builtin_expect(!!(!(u)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("u"), "../src/core/slice.c", 293, __PRETTY_FUNCTION__ ); } while (0); | |||
294 | ||||
295 | return slice_state_to_string(SLICE(u)->state); | |||
296 | } | |||
297 | ||||
298 | static int slice_make_perpetual(Manager *m, const char *name, Unit **ret) { | |||
299 | Unit *u; | |||
300 | int r; | |||
301 | ||||
302 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/core/slice.c", 302, __PRETTY_FUNCTION__ ); } while (0); | |||
303 | assert(name)do { if ((__builtin_expect(!!(!(name)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("name"), "../src/core/slice.c", 303, __PRETTY_FUNCTION__ ); } while (0); | |||
304 | ||||
305 | u = manager_get_unit(m, name); | |||
306 | if (!u) { | |||
307 | r = unit_new_for_name(m, sizeof(Slice), name, &u); | |||
308 | if (r < 0) | |||
309 | return log_error_errno(r, "Failed to allocate the special %s unit: %m", name)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/core/slice.c", 309, __func__, "Failed to allocate the special %s unit: %m" , name) : -abs(_e); }); | |||
310 | } | |||
311 | ||||
312 | u->perpetual = true1; | |||
313 | SLICE(u)->deserialized_state = SLICE_ACTIVE; | |||
314 | ||||
315 | unit_add_to_load_queue(u); | |||
316 | unit_add_to_dbus_queue(u); | |||
317 | ||||
318 | if (ret) | |||
319 | *ret = u; | |||
320 | ||||
321 | return 0; | |||
322 | } | |||
323 | ||||
324 | static void slice_enumerate_perpetual(Manager *m) { | |||
325 | Unit *u; | |||
| ||||
326 | int r; | |||
327 | ||||
328 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/core/slice.c", 328, __PRETTY_FUNCTION__ ); } while (0); | |||
329 | ||||
330 | r = slice_make_perpetual(m, SPECIAL_ROOT_SLICE"-.slice", &u); | |||
331 | if (r >= 0 && manager_owns_root_cgroup(m)) { | |||
332 | Slice *s = SLICE(u); | |||
| ||||
333 | ||||
334 | /* If we are managing the root cgroup then this means our root slice covers the whole system, which | |||
335 | * means the kernel will track CPU/tasks/memory for us anyway, and it is all available in /proc. Let's | |||
336 | * hence turn accounting on here, so that our APIs to query this data are available. */ | |||
337 | ||||
338 | s->cgroup_context.cpu_accounting = true1; | |||
339 | s->cgroup_context.tasks_accounting = true1; | |||
340 | s->cgroup_context.memory_accounting = true1; | |||
341 | } | |||
342 | ||||
343 | if (MANAGER_IS_SYSTEM(m)((m)->unit_file_scope == UNIT_FILE_SYSTEM)) | |||
344 | (void) slice_make_perpetual(m, SPECIAL_SYSTEM_SLICE"system.slice", NULL((void*)0)); | |||
345 | } | |||
346 | ||||
347 | static bool_Bool slice_freezer_action_supported_by_children(Unit *s) { | |||
348 | Unit *member; | |||
349 | void *v; | |||
350 | Iterator i; | |||
351 | ||||
352 | assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("s"), "../src/core/slice.c", 352, __PRETTY_FUNCTION__ ); } while (0); | |||
353 | ||||
354 | HASHMAP_FOREACH_KEY(v, member, s->dependencies[UNIT_BEFORE], i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), . next_key = ((void*)0) }); hashmap_iterate((s->dependencies [UNIT_BEFORE]), &(i), (void**)&(v), (const void**) & (member)); ) { | |||
355 | int r; | |||
356 | ||||
357 | if (UNIT_DEREF(member->slice)((member->slice).target) != s) | |||
358 | continue; | |||
359 | ||||
360 | if (member->type == UNIT_SLICE) { | |||
361 | r = slice_freezer_action_supported_by_children(member); | |||
362 | if (!r) | |||
363 | return r; | |||
364 | } | |||
365 | ||||
366 | if (!UNIT_VTABLE(member)unit_vtable[(member)->type]->freeze) | |||
367 | return false0; | |||
368 | } | |||
369 | ||||
370 | return true1; | |||
371 | } | |||
372 | ||||
373 | static int slice_freezer_action(Unit *s, FreezerAction action) { | |||
374 | Unit *member; | |||
375 | void *v; | |||
376 | Iterator i; | |||
377 | int r; | |||
378 | ||||
379 | assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("s"), "../src/core/slice.c", 379, __PRETTY_FUNCTION__ ); } while (0); | |||
380 | assert(IN_SET(action, FREEZER_FREEZE, FREEZER_THAW))do { if ((__builtin_expect(!!(!(({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended[20 - sizeof((int[]){FREEZER_FREEZE, FREEZER_THAW})/sizeof(int)] ; switch(action) { case FREEZER_FREEZE: case FREEZER_THAW: _found = 1; break; default: break; } _found; }))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("IN_SET(action, FREEZER_FREEZE, FREEZER_THAW)" ), "../src/core/slice.c", 380, __PRETTY_FUNCTION__); } while ( 0); | |||
381 | ||||
382 | if (!slice_freezer_action_supported_by_children(s)) | |||
383 | return log_unit_warning(s, "Requested freezer operation is not supported by all children of the slice")({ const Unit *_u = (s); _u ? log_object_internal(4, 0, "../src/core/slice.c" , 383, __func__, _u->manager->unit_log_field, _u->id , _u->manager->invocation_log_field, _u->invocation_id_string , "Requested freezer operation is not supported by all children of the slice" ) : log_internal_realm(((LOG_REALM_SYSTEMD) << 10 | ((4 ))), 0, "../src/core/slice.c", 383, __func__, "Requested freezer operation is not supported by all children of the slice" ); }); | |||
384 | ||||
385 | HASHMAP_FOREACH_KEY(v, member, s->dependencies[UNIT_BEFORE], i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), . next_key = ((void*)0) }); hashmap_iterate((s->dependencies [UNIT_BEFORE]), &(i), (void**)&(v), (const void**) & (member)); ) { | |||
386 | if (UNIT_DEREF(member->slice)((member->slice).target) != s) | |||
387 | continue; | |||
388 | ||||
389 | if (action == FREEZER_FREEZE) | |||
390 | r = UNIT_VTABLE(member)unit_vtable[(member)->type]->freeze(member); | |||
391 | else | |||
392 | r = UNIT_VTABLE(member)unit_vtable[(member)->type]->thaw(member); | |||
393 | ||||
394 | if (r < 0) | |||
395 | return r; | |||
396 | } | |||
397 | ||||
398 | r = unit_cgroup_freezer_action(s, action); | |||
399 | if (r < 0) | |||
400 | return r; | |||
401 | ||||
402 | return 1; | |||
403 | } | |||
404 | ||||
405 | static int slice_freeze(Unit *s) { | |||
406 | assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("s"), "../src/core/slice.c", 406, __PRETTY_FUNCTION__ ); } while (0); | |||
407 | ||||
408 | return slice_freezer_action(s, FREEZER_FREEZE); | |||
409 | } | |||
410 | ||||
411 | static int slice_thaw(Unit *s) { | |||
412 | assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("s"), "../src/core/slice.c", 412, __PRETTY_FUNCTION__ ); } while (0); | |||
413 | ||||
414 | return slice_freezer_action(s, FREEZER_THAW); | |||
415 | } | |||
416 | ||||
417 | static bool_Bool slice_can_freeze(Unit *s) { | |||
418 | assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("s"), "../src/core/slice.c", 418, __PRETTY_FUNCTION__ ); } while (0); | |||
419 | ||||
420 | return slice_freezer_action_supported_by_children(s); | |||
421 | } | |||
422 | ||||
423 | const UnitVTable slice_vtable = { | |||
424 | .object_size = sizeof(Slice), | |||
425 | .cgroup_context_offset = offsetof(Slice, cgroup_context)__builtin_offsetof(Slice, cgroup_context), | |||
426 | ||||
427 | .sections = | |||
428 | "Unit\0" | |||
429 | "Slice\0" | |||
430 | "Install\0", | |||
431 | .private_section = "Slice", | |||
432 | ||||
433 | .can_transient = true1, | |||
434 | ||||
435 | .init = slice_init, | |||
436 | .load = slice_load, | |||
437 | ||||
438 | .coldplug = slice_coldplug, | |||
439 | ||||
440 | .dump = slice_dump, | |||
441 | ||||
442 | .start = slice_start, | |||
443 | .stop = slice_stop, | |||
444 | ||||
445 | .kill = slice_kill, | |||
446 | ||||
447 | .freeze = slice_freeze, | |||
448 | .thaw = slice_thaw, | |||
449 | .can_freeze = slice_can_freeze, | |||
450 | ||||
451 | .serialize = slice_serialize, | |||
452 | .deserialize_item = slice_deserialize_item, | |||
453 | ||||
454 | .active_state = slice_active_state, | |||
455 | .sub_state_to_string = slice_sub_state_to_string, | |||
456 | ||||
457 | .bus_vtable = bus_slice_vtable, | |||
458 | .bus_set_property = bus_slice_set_property, | |||
459 | .bus_commit_properties = bus_slice_commit_properties, | |||
460 | ||||
461 | .enumerate_perpetual = slice_enumerate_perpetual, | |||
462 | ||||
463 | .status_message_formats = { | |||
464 | .finished_start_job = { | |||
465 | [JOB_DONE] = "Created slice %s.", | |||
466 | }, | |||
467 | .finished_stop_job = { | |||
468 | [JOB_DONE] = "Removed slice %s.", | |||
469 | }, | |||
470 | }, | |||
471 | }; |