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