]>
Commit | Line | Data |
---|---|---|
03467c88 | 1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
87f0e418 | 2 | |
c2f1db8f | 3 | #pragma once |
87f0e418 | 4 | |
a7334b09 LP |
5 | /*** |
6 | This file is part of systemd. | |
7 | ||
8 | Copyright 2010 Lennart Poettering | |
9 | ||
10 | systemd is free software; you can redistribute it and/or modify it | |
5430f7f2 LP |
11 | under the terms of the GNU Lesser General Public License as published by |
12 | the Free Software Foundation; either version 2.1 of the License, or | |
a7334b09 LP |
13 | (at your option) any later version. |
14 | ||
15 | systemd is distributed in the hope that it will be useful, but | |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
5430f7f2 | 18 | Lesser General Public License for more details. |
a7334b09 | 19 | |
5430f7f2 | 20 | You should have received a copy of the GNU Lesser General Public License |
a7334b09 LP |
21 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
22 | ***/ | |
23 | ||
87f0e418 LP |
24 | #include <stdbool.h> |
25 | #include <stdlib.h> | |
bbc9006e | 26 | #include <unistd.h> |
87f0e418 | 27 | |
ac155bb8 | 28 | typedef struct Unit Unit; |
87f0e418 | 29 | typedef struct UnitVTable UnitVTable; |
87f0e418 | 30 | typedef enum UnitActiveState UnitActiveState; |
57020a3a | 31 | typedef struct UnitRef UnitRef; |
c6918296 | 32 | typedef struct UnitStatusMessageFormats UnitStatusMessageFormats; |
87f0e418 | 33 | |
718db961 | 34 | #include "sd-event.h" |
87f0e418 LP |
35 | #include "set.h" |
36 | #include "util.h" | |
37 | #include "list.h" | |
38 | #include "socket-util.h" | |
39 | #include "execute.h" | |
4ad49000 | 40 | #include "cgroup.h" |
52661efd | 41 | #include "condition.h" |
a4375746 | 42 | #include "install.h" |
0a9f8ed0 | 43 | #include "unit-name.h" |
87f0e418 | 44 | |
87f0e418 LP |
45 | enum UnitActiveState { |
46 | UNIT_ACTIVE, | |
032ff4af | 47 | UNIT_RELOADING, |
87f0e418 | 48 | UNIT_INACTIVE, |
fdf20a31 | 49 | UNIT_FAILED, |
87f0e418 LP |
50 | UNIT_ACTIVATING, |
51 | UNIT_DEACTIVATING, | |
94f04347 LP |
52 | _UNIT_ACTIVE_STATE_MAX, |
53 | _UNIT_ACTIVE_STATE_INVALID = -1 | |
87f0e418 LP |
54 | }; |
55 | ||
56 | static inline bool UNIT_IS_ACTIVE_OR_RELOADING(UnitActiveState t) { | |
032ff4af | 57 | return t == UNIT_ACTIVE || t == UNIT_RELOADING; |
87f0e418 LP |
58 | } |
59 | ||
60 | static inline bool UNIT_IS_ACTIVE_OR_ACTIVATING(UnitActiveState t) { | |
032ff4af | 61 | return t == UNIT_ACTIVE || t == UNIT_ACTIVATING || t == UNIT_RELOADING; |
87f0e418 LP |
62 | } |
63 | ||
64 | static inline bool UNIT_IS_INACTIVE_OR_DEACTIVATING(UnitActiveState t) { | |
fdf20a31 | 65 | return t == UNIT_INACTIVE || t == UNIT_FAILED || t == UNIT_DEACTIVATING; |
6124958c LP |
66 | } |
67 | ||
fdf20a31 MM |
68 | static inline bool UNIT_IS_INACTIVE_OR_FAILED(UnitActiveState t) { |
69 | return t == UNIT_INACTIVE || t == UNIT_FAILED; | |
87f0e418 LP |
70 | } |
71 | ||
ef734fd6 LP |
72 | #include "manager.h" |
73 | #include "job.h" | |
74 | ||
a016b922 LP |
75 | struct UnitRef { |
76 | /* Keeps tracks of references to a unit. This is useful so | |
77 | * that we can merge two units if necessary and correct all | |
78 | * references to them */ | |
79 | ||
80 | Unit* unit; | |
81 | LIST_FIELDS(UnitRef, refs); | |
82 | }; | |
83 | ||
ac155bb8 | 84 | struct Unit { |
87f0e418 | 85 | Manager *manager; |
23a177ef | 86 | |
87f0e418 LP |
87 | UnitType type; |
88 | UnitLoadState load_state; | |
23a177ef | 89 | Unit *merged_into; |
87f0e418 LP |
90 | |
91 | char *id; /* One name is special because we use it for identification. Points to an entry in the names set */ | |
9e2f7c11 | 92 | char *instance; |
87f0e418 LP |
93 | |
94 | Set *names; | |
95 | Set *dependencies[_UNIT_DEPENDENCY_MAX]; | |
96 | ||
7c8fa05c LP |
97 | char **requires_mounts_for; |
98 | ||
87f0e418 | 99 | char *description; |
49dbfa7b | 100 | char **documentation; |
faf919f1 | 101 | |
6be1e7d5 | 102 | char *fragment_path; /* if loaded from a config file this is the primary path to it */ |
1b64d026 | 103 | char *source_path; /* if converted, the source file */ |
ae7a7182 | 104 | char **dropin_paths; |
45fb0699 | 105 | usec_t fragment_mtime; |
1b64d026 | 106 | usec_t source_mtime; |
ae7a7182 | 107 | usec_t dropin_mtime; |
87f0e418 | 108 | |
e0209d83 | 109 | /* If there is something to do with this unit, then this is the installed job for it */ |
87f0e418 LP |
110 | Job *job; |
111 | ||
e0209d83 MS |
112 | /* JOB_NOP jobs are special and can be installed without disturbing the real job. */ |
113 | Job *nop_job; | |
114 | ||
faf919f1 LP |
115 | usec_t job_timeout; |
116 | ||
57020a3a LP |
117 | /* References to this */ |
118 | LIST_HEAD(UnitRef, refs); | |
119 | ||
52661efd LP |
120 | /* Conditions to check */ |
121 | LIST_HEAD(Condition, conditions); | |
122 | ||
90bbc946 LP |
123 | dual_timestamp condition_timestamp; |
124 | ||
63983207 LP |
125 | dual_timestamp inactive_exit_timestamp; |
126 | dual_timestamp active_enter_timestamp; | |
127 | dual_timestamp active_exit_timestamp; | |
128 | dual_timestamp inactive_enter_timestamp; | |
87f0e418 | 129 | |
a016b922 LP |
130 | UnitRef slice; |
131 | ||
ef734fd6 | 132 | /* Per type list */ |
ac155bb8 | 133 | LIST_FIELDS(Unit, units_by_type); |
c1e1601e | 134 | |
7c8fa05c LP |
135 | /* All units which have requires_mounts_for set */ |
136 | LIST_FIELDS(Unit, has_requires_mounts_for); | |
137 | ||
701cc384 | 138 | /* Load queue */ |
ac155bb8 | 139 | LIST_FIELDS(Unit, load_queue); |
701cc384 | 140 | |
c1e1601e | 141 | /* D-Bus queue */ |
ac155bb8 | 142 | LIST_FIELDS(Unit, dbus_queue); |
23a177ef LP |
143 | |
144 | /* Cleanup queue */ | |
ac155bb8 | 145 | LIST_FIELDS(Unit, cleanup_queue); |
9d58f1db | 146 | |
701cc384 | 147 | /* GC queue */ |
ac155bb8 | 148 | LIST_FIELDS(Unit, gc_queue); |
701cc384 | 149 | |
4ad49000 LP |
150 | /* CGroup realize members queue */ |
151 | LIST_FIELDS(Unit, cgroup_queue); | |
152 | ||
a911bb9a LP |
153 | /* PIDs we keep an eye on. Note that a unit might have many |
154 | * more, but these are the ones we care enough about to | |
155 | * process SIGCHLD for */ | |
156 | Set *pids; | |
157 | ||
701cc384 | 158 | /* Used during GC sweeps */ |
eced69b3 | 159 | unsigned gc_marker; |
701cc384 | 160 | |
7fab9d01 | 161 | /* When deserializing, temporarily store the job type for this |
39a18c60 MS |
162 | * unit here, if there was a job scheduled. |
163 | * Only for deserializing from a legacy version. New style uses full | |
164 | * serialized jobs. */ | |
7fab9d01 LP |
165 | int deserialized_job; /* This is actually of type JobType */ |
166 | ||
8821a00f LP |
167 | /* Error code when we didn't manage to load the unit (negative) */ |
168 | int load_error; | |
169 | ||
a4375746 LP |
170 | /* Cached unit file state */ |
171 | UnitFileState unit_file_state; | |
172 | ||
7c52a17b ZJS |
173 | /* Counterparts in the cgroup filesystem */ |
174 | char *cgroup_path; | |
175 | CGroupControllerMask cgroup_realized_mask; | |
176 | CGroupControllerMask cgroup_subtree_mask; | |
177 | CGroupControllerMask cgroup_members_mask; | |
178 | ||
179 | /* How to start OnFailure units */ | |
180 | JobMode on_failure_job_mode; | |
181 | ||
9d58f1db LP |
182 | /* Garbage collect us we nobody wants or requires us anymore */ |
183 | bool stop_when_unneeded; | |
184 | ||
35b8ca3a | 185 | /* Create default dependencies */ |
a40eb732 LP |
186 | bool default_dependencies; |
187 | ||
b5e9dba8 LP |
188 | /* Refuse manual starting, allow starting only indirectly via dependency. */ |
189 | bool refuse_manual_start; | |
190 | ||
191 | /* Don't allow the user to stop this unit manually, allow stopping only indirectly via dependency. */ | |
192 | bool refuse_manual_stop; | |
193 | ||
2528a7a6 LP |
194 | /* Allow isolation requests */ |
195 | bool allow_isolate; | |
196 | ||
c8f4d764 LP |
197 | /* Ignore this unit when isolating */ |
198 | bool ignore_on_isolate; | |
199 | ||
7a6000a6 LP |
200 | /* Ignore this unit when snapshotting */ |
201 | bool ignore_on_snapshot; | |
202 | ||
49f43d5f | 203 | /* Did the last condition check succeed? */ |
90bbc946 LP |
204 | bool condition_result; |
205 | ||
c2756a68 LP |
206 | /* Is this a transient unit? */ |
207 | bool transient; | |
208 | ||
9d58f1db LP |
209 | bool in_load_queue:1; |
210 | bool in_dbus_queue:1; | |
211 | bool in_cleanup_queue:1; | |
701cc384 | 212 | bool in_gc_queue:1; |
4ad49000 | 213 | bool in_cgroup_queue:1; |
701cc384 | 214 | |
9d58f1db | 215 | bool sent_dbus_new_signal:1; |
6c073082 LP |
216 | |
217 | bool no_gc:1; | |
cd6d0a45 LP |
218 | |
219 | bool in_audit:1; | |
a57f7e2c LP |
220 | |
221 | bool cgroup_realized:1; | |
bc432dc7 LP |
222 | bool cgroup_members_mask_valid:1; |
223 | bool cgroup_subtree_mask_valid:1; | |
87f0e418 LP |
224 | }; |
225 | ||
c6918296 MS |
226 | struct UnitStatusMessageFormats { |
227 | const char *starting_stopping[2]; | |
228 | const char *finished_start_job[_JOB_RESULT_MAX]; | |
229 | const char *finished_stop_job[_JOB_RESULT_MAX]; | |
230 | }; | |
231 | ||
8e2af478 LP |
232 | typedef enum UnitSetPropertiesMode { |
233 | UNIT_CHECK = 0, | |
234 | UNIT_RUNTIME = 1, | |
235 | UNIT_PERSISTENT = 2, | |
236 | } UnitSetPropertiesMode; | |
237 | ||
87f0e418 | 238 | #include "service.h" |
87f0e418 | 239 | #include "socket.h" |
e821075a | 240 | #include "busname.h" |
87f0e418 | 241 | #include "target.h" |
e821075a | 242 | #include "snapshot.h" |
87f0e418 LP |
243 | #include "device.h" |
244 | #include "mount.h" | |
245 | #include "automount.h" | |
07b0b134 | 246 | #include "swap.h" |
e821075a | 247 | #include "timer.h" |
01f78473 | 248 | #include "path.h" |
a016b922 | 249 | #include "slice.h" |
6c12b52e | 250 | #include "scope.h" |
87f0e418 | 251 | |
87f0e418 | 252 | struct UnitVTable { |
7d17cfbc MS |
253 | /* How much memory does an object of this unit type need */ |
254 | size_t object_size; | |
255 | ||
3ef63c31 LP |
256 | /* If greater than 0, the offset into the object where |
257 | * ExecContext is found, if the unit type has that */ | |
258 | size_t exec_context_offset; | |
259 | ||
4ad49000 LP |
260 | /* If greater than 0, the offset into the object where |
261 | * CGroupContext is found, if the unit type has that */ | |
262 | size_t cgroup_context_offset; | |
263 | ||
718db961 LP |
264 | /* If greater than 0, the offset into the object where |
265 | * KillContext is found, if the unit type has that */ | |
266 | size_t kill_context_offset; | |
267 | ||
613b411c LP |
268 | /* If greater than 0, the offset into the object where the |
269 | * pointer to ExecRuntime is found, if the unit type has | |
270 | * that */ | |
271 | size_t exec_runtime_offset; | |
272 | ||
4ad49000 LP |
273 | /* The name of the configuration file section with the private settings of this unit*/ |
274 | const char *private_section; | |
71645aca | 275 | |
f975e971 LP |
276 | /* Config file sections this unit type understands, separated |
277 | * by NUL chars */ | |
278 | const char *sections; | |
279 | ||
e537352b | 280 | /* This should reset all type-specific variables. This should |
a16e1123 LP |
281 | * not allocate memory, and is called with zero-initialized |
282 | * data. It should hence only initialize variables that need | |
283 | * to be set != 0. */ | |
e537352b LP |
284 | void (*init)(Unit *u); |
285 | ||
a16e1123 LP |
286 | /* This should free all type-specific variables. It should be |
287 | * idempotent. */ | |
288 | void (*done)(Unit *u); | |
289 | ||
e537352b LP |
290 | /* Actually load data from disk. This may fail, and should set |
291 | * load_state to UNIT_LOADED, UNIT_MERGED or leave it at | |
292 | * UNIT_STUB if no configuration could be found. */ | |
293 | int (*load)(Unit *u); | |
294 | ||
c5315881 | 295 | /* If a lot of units got created via enumerate(), this is |
e537352b | 296 | * where to actually set the state and call unit_notify(). */ |
f50e0a01 | 297 | int (*coldplug)(Unit *u); |
87f0e418 LP |
298 | |
299 | void (*dump)(Unit *u, FILE *f, const char *prefix); | |
300 | ||
301 | int (*start)(Unit *u); | |
302 | int (*stop)(Unit *u); | |
303 | int (*reload)(Unit *u); | |
304 | ||
718db961 | 305 | int (*kill)(Unit *u, KillWho w, int signo, sd_bus_error *error); |
8a0867d6 | 306 | |
87f0e418 LP |
307 | bool (*can_reload)(Unit *u); |
308 | ||
a16e1123 LP |
309 | /* Write all data that cannot be restored from other sources |
310 | * away using unit_serialize_item() */ | |
311 | int (*serialize)(Unit *u, FILE *f, FDSet *fds); | |
312 | ||
313 | /* Restore one item from the serialization */ | |
314 | int (*deserialize_item)(Unit *u, const char *key, const char *data, FDSet *fds); | |
315 | ||
01e10de3 LP |
316 | /* Try to match up fds with what we need for this unit */ |
317 | int (*distribute_fds)(Unit *u, FDSet *fds); | |
318 | ||
87f0e418 LP |
319 | /* Boils down the more complex internal state of this unit to |
320 | * a simpler one that the engine can understand */ | |
321 | UnitActiveState (*active_state)(Unit *u); | |
322 | ||
10a94420 LP |
323 | /* Returns the substate specific to this unit type as |
324 | * string. This is purely information so that we can give the | |
35b8ca3a | 325 | * user a more fine grained explanation in which actual state a |
10a94420 LP |
326 | * unit is in. */ |
327 | const char* (*sub_state_to_string)(Unit *u); | |
328 | ||
701cc384 LP |
329 | /* Return true when there is reason to keep this entry around |
330 | * even nothing references it and it isn't active in any | |
331 | * way */ | |
332 | bool (*check_gc)(Unit *u); | |
333 | ||
334 | /* Return true when this unit is suitable for snapshotting */ | |
335 | bool (*check_snapshot)(Unit *u); | |
336 | ||
718db961 | 337 | /* Invoked on every child that died */ |
87f0e418 | 338 | void (*sigchld_event)(Unit *u, pid_t pid, int code, int status); |
7824bbeb | 339 | |
fdf20a31 MM |
340 | /* Reset failed state if we are in failed state */ |
341 | void (*reset_failed)(Unit *u); | |
5632e374 | 342 | |
05e343b7 LP |
343 | /* Called whenever any of the cgroups this unit watches for |
344 | * ran empty */ | |
4ad49000 | 345 | void (*notify_cgroup_empty)(Unit *u); |
8e274523 | 346 | |
8c47c732 | 347 | /* Called whenever a process of this unit sends us a message */ |
c952c6ec | 348 | void (*notify_message)(Unit *u, pid_t pid, char **tags); |
8c47c732 | 349 | |
3ecaa09b | 350 | /* Called whenever a name this Unit registered for comes or |
05e343b7 LP |
351 | * goes away. */ |
352 | void (*bus_name_owner_change)(Unit *u, const char *name, const char *old_owner, const char *new_owner); | |
353 | ||
8e2af478 | 354 | /* Called for each property that is being set */ |
718db961 | 355 | int (*bus_set_property)(Unit *u, const char *name, sd_bus_message *message, UnitSetPropertiesMode mode, sd_bus_error *error); |
8e2af478 LP |
356 | |
357 | /* Called after at least one property got changed to apply the necessary change */ | |
358 | int (*bus_commit_properties)(Unit *u); | |
359 | ||
a7f241db LP |
360 | /* Return the unit this unit is following */ |
361 | Unit *(*following)(Unit *u); | |
362 | ||
6210e7fc LP |
363 | /* Return the set of units that are following each other */ |
364 | int (*following_set)(Unit *u, Set **s); | |
365 | ||
3ecaa09b LP |
366 | /* Invoked each time a unit this unit is triggering changes |
367 | * state or gains/loses a job */ | |
368 | void (*trigger_notify)(Unit *u, Unit *trigger); | |
369 | ||
8742514c LP |
370 | /* Called whenever CLOCK_REALTIME made a jump */ |
371 | void (*time_change)(Unit *u); | |
372 | ||
68db7a3b ZJS |
373 | int (*get_timeout)(Unit *u, uint64_t *timeout); |
374 | ||
f50e0a01 LP |
375 | /* This is called for each unit type and should be used to |
376 | * enumerate existing devices and load them. However, | |
377 | * everything that is loaded here should still stay in | |
378 | * inactive state. It is the job of the coldplug() call above | |
379 | * to put the units into the initial state. */ | |
7824bbeb | 380 | int (*enumerate)(Manager *m); |
f50e0a01 LP |
381 | |
382 | /* Type specific cleanups. */ | |
7824bbeb | 383 | void (*shutdown)(Manager *m); |
9d58f1db | 384 | |
c4e2ceae LP |
385 | /* The interface name */ |
386 | const char *bus_interface; | |
387 | ||
718db961 LP |
388 | /* The bus vtable */ |
389 | const sd_bus_vtable *bus_vtable; | |
390 | ||
718db961 | 391 | /* The strings to print in status messages */ |
c6918296 MS |
392 | UnitStatusMessageFormats status_message_formats; |
393 | ||
9d58f1db LP |
394 | /* Can units of this type have multiple names? */ |
395 | bool no_alias:1; | |
396 | ||
9d58f1db LP |
397 | /* Instances make no sense for this type */ |
398 | bool no_instances:1; | |
399 | ||
701cc384 LP |
400 | /* Exclude from automatic gc */ |
401 | bool no_gc:1; | |
c2756a68 LP |
402 | |
403 | /* True if transient units of this type are OK */ | |
404 | bool can_transient:1; | |
87f0e418 LP |
405 | }; |
406 | ||
407 | extern const UnitVTable * const unit_vtable[_UNIT_TYPE_MAX]; | |
408 | ||
ac155bb8 | 409 | #define UNIT_VTABLE(u) unit_vtable[(u)->type] |
87f0e418 LP |
410 | |
411 | /* For casting a unit into the various unit types */ | |
412 | #define DEFINE_CAST(UPPERCASE, MixedCase) \ | |
413 | static inline MixedCase* UPPERCASE(Unit *u) { \ | |
ac155bb8 | 414 | if (_unlikely_(!u || u->type != UNIT_##UPPERCASE)) \ |
87f0e418 LP |
415 | return NULL; \ |
416 | \ | |
417 | return (MixedCase*) u; \ | |
418 | } | |
419 | ||
420 | /* For casting the various unit types into a unit */ | |
ac155bb8 | 421 | #define UNIT(u) (&(u)->meta) |
87f0e418 | 422 | |
3ecaa09b LP |
423 | #define UNIT_TRIGGER(u) ((Unit*) set_first((u)->dependencies[UNIT_TRIGGERS])) |
424 | ||
87f0e418 | 425 | DEFINE_CAST(SERVICE, Service); |
e821075a LP |
426 | DEFINE_CAST(SOCKET, Socket); |
427 | DEFINE_CAST(BUSNAME, BusName); | |
87f0e418 | 428 | DEFINE_CAST(TARGET, Target); |
e821075a | 429 | DEFINE_CAST(SNAPSHOT, Snapshot); |
87f0e418 LP |
430 | DEFINE_CAST(DEVICE, Device); |
431 | DEFINE_CAST(MOUNT, Mount); | |
432 | DEFINE_CAST(AUTOMOUNT, Automount); | |
07b0b134 | 433 | DEFINE_CAST(SWAP, Swap); |
e821075a | 434 | DEFINE_CAST(TIMER, Timer); |
01f78473 | 435 | DEFINE_CAST(PATH, Path); |
a016b922 | 436 | DEFINE_CAST(SLICE, Slice); |
6c12b52e | 437 | DEFINE_CAST(SCOPE, Scope); |
87f0e418 | 438 | |
7d17cfbc | 439 | Unit *unit_new(Manager *m, size_t size); |
87f0e418 LP |
440 | void unit_free(Unit *u); |
441 | ||
442 | int unit_add_name(Unit *u, const char *name); | |
9e2f7c11 | 443 | |
701cc384 | 444 | int unit_add_dependency(Unit *u, UnitDependency d, Unit *other, bool add_reference); |
2c966c03 LP |
445 | int unit_add_two_dependencies(Unit *u, UnitDependency d, UnitDependency e, Unit *other, bool add_reference); |
446 | ||
701cc384 | 447 | int unit_add_dependency_by_name(Unit *u, UnitDependency d, const char *name, const char *filename, bool add_reference); |
2c966c03 LP |
448 | int unit_add_two_dependencies_by_name(Unit *u, UnitDependency d, UnitDependency e, const char *name, const char *path, bool add_reference); |
449 | ||
701cc384 | 450 | int unit_add_dependency_by_name_inverse(Unit *u, UnitDependency d, const char *name, const char *filename, bool add_reference); |
2c966c03 | 451 | int unit_add_two_dependencies_by_name_inverse(Unit *u, UnitDependency d, UnitDependency e, const char *name, const char *path, bool add_reference); |
0ae97ec1 | 452 | |
23a177ef LP |
453 | int unit_add_exec_dependencies(Unit *u, ExecContext *c); |
454 | ||
0ae97ec1 | 455 | int unit_choose_id(Unit *u, const char *name); |
f50e0a01 | 456 | int unit_set_description(Unit *u, const char *description); |
87f0e418 | 457 | |
701cc384 LP |
458 | bool unit_check_gc(Unit *u); |
459 | ||
87f0e418 | 460 | void unit_add_to_load_queue(Unit *u); |
c1e1601e | 461 | void unit_add_to_dbus_queue(Unit *u); |
23a177ef | 462 | void unit_add_to_cleanup_queue(Unit *u); |
701cc384 | 463 | void unit_add_to_gc_queue(Unit *u); |
87f0e418 LP |
464 | |
465 | int unit_merge(Unit *u, Unit *other); | |
23a177ef LP |
466 | int unit_merge_by_name(Unit *u, const char *other); |
467 | ||
44a6b1b6 | 468 | Unit *unit_follow_merge(Unit *u) _pure_; |
87f0e418 | 469 | |
e537352b LP |
470 | int unit_load_fragment_and_dropin(Unit *u); |
471 | int unit_load_fragment_and_dropin_optional(Unit *u); | |
87f0e418 LP |
472 | int unit_load(Unit *unit); |
473 | ||
598459ce | 474 | int unit_add_default_slice(Unit *u, CGroupContext *c); |
a016b922 | 475 | |
44a6b1b6 | 476 | const char *unit_description(Unit *u) _pure_; |
87f0e418 | 477 | |
f278026d LP |
478 | bool unit_has_name(Unit *u, const char *name); |
479 | ||
87f0e418 LP |
480 | UnitActiveState unit_active_state(Unit *u); |
481 | ||
10a94420 LP |
482 | const char* unit_sub_state_to_string(Unit *u); |
483 | ||
87f0e418 LP |
484 | void unit_dump(Unit *u, FILE *f, const char *prefix); |
485 | ||
44a6b1b6 ZJS |
486 | bool unit_can_reload(Unit *u) _pure_; |
487 | bool unit_can_start(Unit *u) _pure_; | |
488 | bool unit_can_isolate(Unit *u) _pure_; | |
87f0e418 LP |
489 | |
490 | int unit_start(Unit *u); | |
491 | int unit_stop(Unit *u); | |
492 | int unit_reload(Unit *u); | |
493 | ||
718db961 LP |
494 | int unit_kill(Unit *u, KillWho w, int signo, sd_bus_error *error); |
495 | int unit_kill_common(Unit *u, KillWho who, int signo, pid_t main_pid, pid_t control_pid, sd_bus_error *error); | |
8a0867d6 | 496 | |
e2f3b44c | 497 | void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_success); |
87f0e418 | 498 | |
87f0e418 LP |
499 | int unit_watch_pid(Unit *u, pid_t pid); |
500 | void unit_unwatch_pid(Unit *u, pid_t pid); | |
a911bb9a LP |
501 | int unit_watch_all_pids(Unit *u); |
502 | void unit_unwatch_all_pids(Unit *u); | |
503 | ||
504 | void unit_tidy_watch_pids(Unit *u, pid_t except1, pid_t except2); | |
87f0e418 | 505 | |
05e343b7 LP |
506 | int unit_watch_bus_name(Unit *u, const char *name); |
507 | void unit_unwatch_bus_name(Unit *u, const char *name); | |
508 | ||
87f0e418 LP |
509 | bool unit_job_is_applicable(Unit *u, JobType j); |
510 | ||
0301abf4 LP |
511 | int set_unit_path(const char *p); |
512 | ||
50159e6a LP |
513 | char *unit_dbus_path(Unit *u); |
514 | ||
f6ff8c29 LP |
515 | int unit_load_related_unit(Unit *u, const char *type, Unit **_found); |
516 | ||
44a6b1b6 | 517 | bool unit_can_serialize(Unit *u) _pure_; |
6b78f9b4 | 518 | int unit_serialize(Unit *u, FILE *f, FDSet *fds, bool serialize_jobs); |
44b601bc | 519 | void unit_serialize_item_format(Unit *u, FILE *f, const char *key, const char *value, ...) _printf_(4,5); |
a16e1123 LP |
520 | void unit_serialize_item(Unit *u, FILE *f, const char *key, const char *value); |
521 | int unit_deserialize(Unit *u, FILE *f, FDSet *fds); | |
522 | ||
6e2ef85b LP |
523 | int unit_add_node_link(Unit *u, const char *what, bool wants); |
524 | ||
cca098b0 LP |
525 | int unit_coldplug(Unit *u); |
526 | ||
44b601bc | 527 | void unit_status_printf(Unit *u, const char *status, const char *unit_status_msg_format) _printf_(3, 0); |
9e58ff9c | 528 | |
45fb0699 LP |
529 | bool unit_need_daemon_reload(Unit *u); |
530 | ||
fdf20a31 | 531 | void unit_reset_failed(Unit *u); |
5632e374 | 532 | |
a7f241db | 533 | Unit *unit_following(Unit *u); |
eeaedb7c | 534 | int unit_following_set(Unit *u, Set **s); |
a7f241db | 535 | |
9444b1f2 LP |
536 | const char *unit_slice_name(Unit *u); |
537 | ||
44a6b1b6 ZJS |
538 | bool unit_stop_pending(Unit *u) _pure_; |
539 | bool unit_inactive_or_pending(Unit *u) _pure_; | |
31afa0a4 | 540 | bool unit_active_or_pending(Unit *u); |
18ffdfda | 541 | |
bba34eed LP |
542 | int unit_add_default_target_dependency(Unit *u, Unit *target); |
543 | ||
41f9172f LP |
544 | char *unit_default_cgroup_path(Unit *u); |
545 | ||
3ecaa09b LP |
546 | void unit_start_on_failure(Unit *u); |
547 | void unit_trigger_notify(Unit *u); | |
c0daa706 | 548 | |
a4375746 LP |
549 | UnitFileState unit_get_unit_file_state(Unit *u); |
550 | ||
57020a3a LP |
551 | Unit* unit_ref_set(UnitRef *ref, Unit *u); |
552 | void unit_ref_unset(UnitRef *ref); | |
553 | ||
554 | #define UNIT_DEREF(ref) ((ref).unit) | |
9444b1f2 | 555 | #define UNIT_ISSET(ref) (!!(ref).unit) |
57020a3a | 556 | |
598459ce | 557 | int unit_patch_contexts(Unit *u); |
e06c73cc | 558 | |
44a6b1b6 | 559 | ExecContext *unit_get_exec_context(Unit *u) _pure_; |
718db961 | 560 | KillContext *unit_get_kill_context(Unit *u) _pure_; |
4ad49000 | 561 | CGroupContext *unit_get_cgroup_context(Unit *u) _pure_; |
598459ce | 562 | |
613b411c LP |
563 | ExecRuntime *unit_get_exec_runtime(Unit *u) _pure_; |
564 | ||
565 | int unit_setup_exec_runtime(Unit *u); | |
3ef63c31 | 566 | |
8e2af478 | 567 | int unit_write_drop_in(Unit *u, UnitSetPropertiesMode mode, const char *name, const char *data); |
44b601bc | 568 | int unit_write_drop_in_format(Unit *u, UnitSetPropertiesMode mode, const char *name, const char *format, ...) _printf_(4,5); |
b9ec9359 LP |
569 | |
570 | int unit_write_drop_in_private(Unit *u, UnitSetPropertiesMode mode, const char *name, const char *data); | |
44b601bc | 571 | int unit_write_drop_in_private_format(Unit *u, UnitSetPropertiesMode mode, const char *name, const char *format, ...) _printf_(4,5); |
b9ec9359 | 572 | |
8e2af478 | 573 | int unit_remove_drop_in(Unit *u, UnitSetPropertiesMode mode, const char *name); |
71645aca | 574 | |
cd2086fe LP |
575 | int unit_kill_context(Unit *u, KillContext *c, bool sigkill, pid_t main_pid, pid_t control_pid, bool main_pid_alien); |
576 | ||
c2756a68 LP |
577 | int unit_make_transient(Unit *u); |
578 | ||
a57f7e2c LP |
579 | int unit_require_mounts_for(Unit *u, const char *path); |
580 | ||
44a6b1b6 ZJS |
581 | const char *unit_active_state_to_string(UnitActiveState i) _const_; |
582 | UnitActiveState unit_active_state_from_string(const char *s) _pure_; | |
94f04347 | 583 | |
e8e581bf ZJS |
584 | /* Macros which append UNIT= or USER_UNIT= to the message */ |
585 | ||
bbc9006e | 586 | #define log_full_unit(level, unit, ...) log_meta_object(level, __FILE__, __LINE__, __func__, getpid() == 1 ? "UNIT=" : "USER_UNIT=", unit, __VA_ARGS__) |
fdf9f9bb ZJS |
587 | #define log_debug_unit(unit, ...) log_full_unit(LOG_DEBUG, unit, __VA_ARGS__) |
588 | #define log_info_unit(unit, ...) log_full_unit(LOG_INFO, unit, __VA_ARGS__) | |
589 | #define log_notice_unit(unit, ...) log_full_unit(LOG_NOTICE, unit, __VA_ARGS__) | |
590 | #define log_warning_unit(unit, ...) log_full_unit(LOG_WARNING, unit, __VA_ARGS__) | |
591 | #define log_error_unit(unit, ...) log_full_unit(LOG_ERR, unit, __VA_ARGS__) | |
bbc9006e MT |
592 | |
593 | #define log_struct_unit(level, unit, ...) log_struct(level, getpid() == 1 ? "UNIT=%s" : "USER_UNIT=%s", unit, __VA_ARGS__) |