Debian Codegraph @

src/core/manager.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "sd-event.h"
5
6 #include "bpf-restrict-fsaccess.h"
7 #include "cgroup.h"
8 #include "common-signal.h"
9 #include "execute.h"
10 #include "core-forward.h"
11 #include "log.h"
12 #include "path-lookup.h"
13 #include "show-status.h"
14 #include "unit.h"
15
16 struct libmnt_monitor;
17
18 /* Enforce upper limit on how many names we allow */
19 #define MANAGER_MAX_NAMES 131072 /* 128K */
20
21 /* Enforce upper limit on the number of patterns/states requested over IPC */
22 #define MANAGER_MAX_PATTERNS_PER_CALL 4096U
23 #define MANAGER_MAX_STATES_PER_CALL 256U
24
25 /* On sigrtmin+18, private commands */
26 enum {
27 MANAGER_SIGNAL_COMMAND_DUMP_JOBS = _COMMON_SIGNAL_COMMAND_PRIVATE_BASE + 0,
28 _MANAGER_SIGNAL_COMMAND_MAX,
29 };
30
31 assert_cc((int) _MANAGER_SIGNAL_COMMAND_MAX <= (int) _COMMON_SIGNAL_COMMAND_PRIVATE_END);
32
33 /* An externally visible state. We don't actually maintain this as state variable, but derive it from various fields
34 * when requested */
35 typedef enum ManagerState {
36 MANAGER_INITIALIZING,
37 MANAGER_STARTING,
38 MANAGER_RUNNING,
39 MANAGER_DEGRADED,
40 MANAGER_MAINTENANCE,
41 MANAGER_STOPPING,
42 _MANAGER_STATE_MAX,
43 _MANAGER_STATE_INVALID = -EINVAL,
44 } ManagerState;
45
46 typedef enum ManagerObjective {
47 MANAGER_OK,
48 MANAGER_EXIT,
49 MANAGER_RELOAD,
50 MANAGER_REEXECUTE,
51 MANAGER_REBOOT,
52 MANAGER_SOFT_REBOOT,
53 MANAGER_POWEROFF,
54 MANAGER_HALT,
55 MANAGER_KEXEC,
56 MANAGER_SWITCH_ROOT,
57 _MANAGER_OBJECTIVE_MAX,
58 _MANAGER_OBJECTIVE_INVALID = -EINVAL,
59 } ManagerObjective;
60
61 /* Notes:
62 * 1. TIMESTAMP_FIRMWARE, TIMESTAMP_LOADER, TIMESTAMP_KERNEL, TIMESTAMP_INITRD,
63 * TIMESTAMP_SECURITY_START, and TIMESTAMP_SECURITY_FINISH are set only when
64 * the manager is system and not running under container environment.
65 *
66 * 2. The monotonic timestamp of TIMESTAMP_KERNEL is always zero.
67 *
68 * 3. The realtime timestamp of TIMESTAMP_KERNEL will be unset if the system does not
69 * have RTC.
70 *
71 * 4. TIMESTAMP_FIRMWARE and TIMESTAMP_LOADER will be unset if the system does not
72 * have RTC, or systemd is built without EFI support.
73 *
74 * 5. The monotonic timestamps of TIMESTAMP_FIRMWARE and TIMESTAMP_LOADER are stored as
75 * negative of the actual value.
76 *
77 * 6. TIMESTAMP_USERSPACE is the timestamp of when the manager was started.
78 *
79 * 7. TIMESTAMP_INITRD_* are set only when the system is booted with an initrd.
80 */
81
82 typedef enum ManagerTimestamp {
83 MANAGER_TIMESTAMP_FIRMWARE,
84 MANAGER_TIMESTAMP_LOADER,
85 MANAGER_TIMESTAMP_KERNEL,
86 MANAGER_TIMESTAMP_INITRD,
87 MANAGER_TIMESTAMP_USERSPACE,
88 MANAGER_TIMESTAMP_FINISH,
89
90 MANAGER_TIMESTAMP_SECURITY_START,
91 MANAGER_TIMESTAMP_SECURITY_FINISH,
92 MANAGER_TIMESTAMP_GENERATORS_START,
93 MANAGER_TIMESTAMP_GENERATORS_FINISH,
94 MANAGER_TIMESTAMP_UNITS_LOAD_START,
95 MANAGER_TIMESTAMP_UNITS_LOAD_FINISH,
96 MANAGER_TIMESTAMP_UNITS_LOAD,
97
98 MANAGER_TIMESTAMP_INITRD_SECURITY_START,
99 MANAGER_TIMESTAMP_INITRD_SECURITY_FINISH,
100 MANAGER_TIMESTAMP_INITRD_GENERATORS_START,
101 MANAGER_TIMESTAMP_INITRD_GENERATORS_FINISH,
102 MANAGER_TIMESTAMP_INITRD_UNITS_LOAD_START,
103 MANAGER_TIMESTAMP_INITRD_UNITS_LOAD_FINISH,
104
105 MANAGER_TIMESTAMP_SHUTDOWN_START,
106
107 _MANAGER_TIMESTAMP_MAX,
108 _MANAGER_TIMESTAMP_INVALID = -EINVAL,
109 } ManagerTimestamp;
110
111 typedef enum WatchdogType {
112 WATCHDOG_RUNTIME,
113 WATCHDOG_REBOOT,
114 WATCHDOG_KEXEC,
115 WATCHDOG_PRETIMEOUT,
116 _WATCHDOG_TYPE_MAX,
117 } WatchdogType;
118
119 typedef enum ManagerTestRunFlags {
120 MANAGER_TEST_NORMAL = 0, /* run normally */
121 MANAGER_TEST_RUN_MINIMAL = 1 << 0, /* create basic data structures */
122 MANAGER_TEST_RUN_BASIC = 1 << 1, /* interact with the environment */
123 MANAGER_TEST_RUN_ENV_GENERATORS = 1 << 2, /* also run env generators */
124 MANAGER_TEST_RUN_GENERATORS = 1 << 3, /* also run unit generators */
125 MANAGER_TEST_RUN_IGNORE_DEPENDENCIES = 1 << 4, /* run while ignoring dependencies */
126 MANAGER_TEST_DONT_OPEN_EXECUTOR = 1 << 5, /* avoid trying to load sd-executor */
127 MANAGER_TEST_FULL = MANAGER_TEST_RUN_BASIC | MANAGER_TEST_RUN_ENV_GENERATORS | MANAGER_TEST_RUN_GENERATORS,
128 } ManagerTestRunFlags;
129
130 assert_cc((MANAGER_TEST_FULL & UINT8_MAX) == MANAGER_TEST_FULL);
131
132 /* Various defaults for unit file settings. */
133 typedef struct UnitDefaults {
134 ExecOutput std_output, std_error;
135
136 usec_t restart_usec, timeout_start_usec, timeout_stop_usec, timeout_abort_usec, device_timeout_usec;
137 bool timeout_abort_set;
138
139 RateLimit start_limit;
140
141 bool memory_accounting;
142 bool io_accounting;
143 bool tasks_accounting;
144 bool ip_accounting;
145
146 CGroupTasksMax tasks_max;
147 usec_t timer_accuracy_usec;
148
149 bool restrict_suid_sgid;
150
151 OOMPolicy oom_policy;
152 int oom_score_adjust;
153 bool oom_score_adjust_set;
154
155 bool memory_zswap_writeback;
156
157 CGroupPressure pressure[_PRESSURE_RESOURCE_MAX];
158
159 char *smack_process_label;
160
161 struct rlimit *rlimit[_RLIMIT_MAX];
162 } UnitDefaults;
163
164 typedef struct Manager {
165 /* Note that the set of units we know of is allowed to be
166 * inconsistent. However the subset of it that is loaded may
167 * not, and the list of jobs may neither. */
168
169 /* Active jobs and units */
170 Hashmap *units; /* name string => Unit object n:1 */
171 Hashmap *units_by_invocation_id;
172 Hashmap *jobs; /* job id => Job object 1:1 */
173
174 /* To make it easy to iterate through the units of a specific
175 * type we maintain a per type linked list */
176 LIST_HEAD(Unit, units_by_type[_UNIT_TYPE_MAX]);
177
178 /* Units that need to be loaded */
179 LIST_HEAD(Unit, load_queue); /* this is actually more a stack than a queue, but uh. */
180
181 /* Jobs that need to be run */
182 Prioq *run_queue;
183
184 /* Units and jobs that have not yet been announced via
185 * D-Bus. When something about a job changes it is added here
186 * if it is not in there yet. This allows easy coalescing of
187 * D-Bus change signals. */
188 LIST_HEAD(Unit, dbus_unit_queue);
189 LIST_HEAD(Job, dbus_job_queue);
190
191 /* Units to remove */
192 LIST_HEAD(Unit, cleanup_queue);
193
194 /* Units and jobs to check when doing GC */
195 LIST_HEAD(Unit, gc_unit_queue);
196 LIST_HEAD(Job, gc_job_queue);
197
198 /* Units that should be realized */
199 LIST_HEAD(Unit, cgroup_realize_queue);
200
201 /* Units whose cgroup ran empty */
202 LIST_HEAD(Unit, cgroup_empty_queue);
203
204 /* Units whose memory.event fired */
205 LIST_HEAD(Unit, cgroup_oom_queue);
206
207 /* Target units whose default target dependencies haven't been set yet */
208 LIST_HEAD(Unit, target_deps_queue);
209
210 /* Units that might be subject to StopWhenUnneeded= clean-up */
211 LIST_HEAD(Unit, stop_when_unneeded_queue);
212
213 /* Units which are upheld by another other which we might need to act on */
214 LIST_HEAD(Unit, start_when_upheld_queue);
215
216 /* Units that have BindsTo= another unit, and might need to be shutdown because the bound unit is not active. */
217 LIST_HEAD(Unit, stop_when_bound_queue);
218
219 /* Units that have resources open, and where it might be good to check if they can be released now */
220 LIST_HEAD(Unit, release_resources_queue);
221
222 /* Units that perform certain actions after some other unit deactivates */
223 LIST_HEAD(Unit, stop_notify_queue);
224
225 sd_event *event;
226
227 /* This maps PIDs we care about to units that are interested in them. We allow multiple units to be
228 * interested in the same PID and multiple PIDs to be relevant to the same unit. Since in most cases
229 * only a single unit will be interested in the same PID though, we use a somewhat special structure
230 * here: the first unit interested in a PID is stored in the hashmap 'watch_pids', keyed by the
231 * PID. If there are other units interested too they'll be stored in a NULL-terminated array, stored
232 * in the hashmap 'watch_pids_more', keyed by the PID. Thus to go through the full list of units
233 * interested in a PID we must look into both hashmaps.
234 *
235 * NB: the ownership of PidRefs is held by Unit.pids! */
236 Hashmap *watch_pids; /* PidRef* → Unit* */
237 Hashmap *watch_pids_more; /* PidRef* → NUL terminated array of Unit* */
238
239 /* A set contains all units which cgroup should be refreshed after startup */
240 Set *startup_units;
241
242 /* A set which contains all currently failed units */
243 Set *failed_units;
244
245 uint64_t last_transaction_id;
246
247 /* IDs of transactions that once encountered ordering cycle */
248 Set *transactions_with_cycle;
249
250 sd_event_source *run_queue_event_source;
251
252 char *notify_socket;
253 int notify_fd;
254 sd_event_source *notify_event_source;
255
256 int signal_fd;
257 sd_event_source *signal_event_source;
258
259 sd_event_source *sigchld_event_source;
260
261 sd_event_source *time_change_event_source;
262
263 sd_event_source *timezone_change_event_source;
264
265 sd_event_source *jobs_in_progress_event_source;
266
267 int user_lookup_fds[2];
268 sd_event_source *user_lookup_event_source;
269
270 int handoff_timestamp_fds[2];
271 sd_event_source *handoff_timestamp_event_source;
272
273 int pidref_transport_fds[2];
274 sd_event_source *pidref_event_source;
275
276 RuntimeScope runtime_scope;
277
278 LookupPaths lookup_paths;
279 Hashmap *unit_id_map;
280 Hashmap *unit_name_map;
281 Set *unit_path_cache;
282 uint64_t unit_cache_timestamp_hash;
283
284 /* We don't have support for atomically enabling/disabling units, and unit_file_state might become
285 * outdated if such operations failed half-way. Therefore, we set this flag if changes to unit files
286 * are made, and reset it after daemon-reload. If set, we report that daemon-reload is needed through
287 * unit's NeedDaemonReload property. */
288 bool unit_file_state_outdated;
289
290 char **transient_environment; /* The environment, as determined from config files, kernel cmdline and environment generators */
291 char **client_environment; /* Environment variables created by clients through the bus API */
292
293 usec_t watchdog[_WATCHDOG_TYPE_MAX];
294 usec_t watchdog_overridden[_WATCHDOG_TYPE_MAX];
295 char *watchdog_pretimeout_governor;
296 char *watchdog_pretimeout_governor_overridden;
297
298 dual_timestamp timestamps[_MANAGER_TIMESTAMP_MAX];
299
300 /* Data specific to the device subsystem */
301 sd_device_monitor *device_monitor;
302 Hashmap *devices_by_sysfs;
303
304 /* Data specific to the mount subsystem */
305 struct libmnt_monitor *mount_monitor;
306 sd_event_source *mount_event_source;
307
308 /* Data specific to the swap filesystem */
309 FILE *proc_swaps;
310 sd_event_source *swap_event_source;
311 Hashmap *swaps_by_devnode;
312
313 /* Data specific to the D-Bus subsystem */
314 sd_bus *api_bus, *system_bus;
315 Set *private_buses;
316 int private_listen_fd;
317 sd_event_source *private_listen_event_source;
318
319 /* Contains all the clients that are subscribed to signals via the API bus. Note that private bus
320 * connections are always considered subscribes, since they last for very short only, and it is
321 * much simpler that way. */
322 sd_bus_track *subscribed;
323 char **subscribed_as_strv;
324
325 /* The bus id of API bus acquired through org.freedesktop.DBus.GetId, which before deserializing
326 * subscriptions we'd use to verify the bus is still the same instance as before. */
327 sd_id128_t bus_id, deserialized_bus_id;
328
329 /* This is used during reloading: before the reload we queue
330 * the reply message here, and afterwards we send it.
331 * It can be either a D-Bus message or a Varlink message, but not both. */
332 sd_bus_message *pending_reload_message_dbus;
333 sd_varlink *pending_reload_message_vl;
334
335 Hashmap *watch_bus; /* D-Bus names => Unit object n:1 */
336
337 uint32_t current_job_id;
338
339 /* Data specific to the Automount subsystem */
340 int dev_autofs_fd;
341
342 /* Data specific to the cgroup subsystem */
343 Hashmap *cgroup_unit;
344 char *cgroup_root;
345 CGroupMask cgroup_supported;
346
347 /* Notifications from cgroups, when the unified hierarchy is used is done via inotify. */
348 int cgroup_inotify_fd;
349 sd_event_source *cgroup_inotify_event_source;
350
351 /* Maps for finding the unit for each inotify watch descriptor for the cgroup.events and
352 * memory.events cgroupv2 attributes. */
353 Hashmap *cgroup_control_inotify_wd_unit;
354 Hashmap *cgroup_memory_inotify_wd_unit;
355
356 /* A defer event for handling cgroup empty events and processing them after SIGCHLD in all cases. */
357 sd_event_source *cgroup_empty_event_source;
358 sd_event_source *cgroup_oom_event_source;
359
360 /* Make sure the user cannot accidentally unmount our cgroup
361 * file system */
362 int pin_cgroupfs_fd;
363
364 unsigned gc_marker;
365
366 /* The stat() data the last time we saw /etc/localtime */
367 usec_t etc_localtime_mtime;
368 bool etc_localtime_accessible;
369
370 ManagerObjective objective;
371 /* Objective as it was before serialization, mostly to detect soft-reboots */
372 ManagerObjective previous_objective;
373
374 /* Flags */
375 bool dispatching_load_queue;
376 int may_dispatch_stop_notify_queue; /* tristate */
377
378 bool send_reloading_done;
379
380 /* Have we already sent out the READY=1 notification? */
381 bool ready_sent;
382
383 /* Was the last status sent "STATUS=Ready."? */
384 bool status_ready;
385
386 /* Have we already printed the taint line if necessary? */
387 bool taint_logged;
388
389 /* Have we ever changed the "kernel.pid_max" sysctl? */
390 bool sysctl_pid_max_changed;
391
392 ManagerTestRunFlags test_run_flags;
393
394 /* If non-zero, exit with the following value when the systemd
395 * process terminate. Useful for containers: systemd-nspawn could get
396 * the return value. */
397 uint8_t return_value;
398
399 ShowStatus show_status;
400 ShowStatus show_status_overridden;
401 StatusUnitFormat status_unit_format;
402 char *confirm_spawn;
403 bool no_console_output;
404 bool service_watchdogs;
405
406 UnitDefaults defaults;
407
408 int original_log_level;
409 LogTarget original_log_target;
410 bool log_level_overridden;
411 bool log_target_overridden;
412
413 /* non-zero if we are reloading or reexecuting, */
414 int n_reloading;
415
416 unsigned n_installed_jobs;
417 unsigned n_failed_jobs;
418
419 /* Jobs in progress watching */
420 unsigned n_running_jobs;
421 unsigned n_on_console;
422 unsigned jobs_in_progress_iteration;
423
424 /* Do we have any outstanding password prompts? */
425 int have_ask_password;
426 sd_event_source *ask_password_event_source;
427
428 /* Type=idle pipes */
429 int idle_pipe[4];
430 sd_event_source *idle_pipe_event_source;
431
432 char *switch_root;
433 char *switch_root_init;
434
435 /* This is true before and after switching root. */
436 bool switching_root;
437
438 /* These map all possible path prefixes to the units needing them. They are hashmaps with a path
439 * string as key, and a Set as value where Unit objects are contained. */
440 Hashmap *units_needing_mounts_for[_UNIT_MOUNT_DEPENDENCY_TYPE_MAX];
441
442 /* Used for processing polkit authorization responses */
443 Hashmap *polkit_registry;
444
445 /* Dynamic users/groups, indexed by their name */
446 Hashmap *dynamic_users;
447
448 /* Keep track of all UIDs and GIDs any of our services currently use. This is useful for the RemoveIPC= logic. */
449 Hashmap *uid_refs;
450 Hashmap *gid_refs;
451
452 /* ExecSharedRuntime, indexed by their owner unit id */
453 Hashmap *exec_shared_runtime_by_id;
454
455 /* When the user hits C-A-D more than 7 times per 2s, do something immediately... */
456 RateLimit ctrl_alt_del_ratelimit;
457 EmergencyAction cad_burst_action;
458
459 int first_boot; /* tri-state */
460
461 /* Prefixes of e.g. RuntimeDirectory= */
462 char *prefix[_EXEC_DIRECTORY_TYPE_MAX];
463 char *received_credentials_directory;
464 char *received_encrypted_credentials_directory;
465
466 /* Used in the SIGCHLD and sd_notify() message invocation logic to avoid that we dispatch the same event
467 * multiple times on the same unit. */
468 unsigned sigchldgen;
469 unsigned notifygen;
470
471 sd_varlink_server *varlink_server;
472 /* When we're a system manager, this object manages the subscription from systemd-oomd to PID1 that's
473 * used to report changes in ManagedOOM settings (systemd server - oomd client). When
474 * we're a user manager, this object manages the client connection from the user manager to
475 * systemd-oomd to report changes in ManagedOOM settings (systemd client - oomd server). */
476 sd_varlink *managed_oom_varlink;
477
478 sd_varlink_server *metrics_varlink_server;
479
480 /* Reference to RestrictFileSystems= BPF program */
481 struct restrict_fs_bpf *restrict_fs;
482
483 /* Reference to RestrictFileSystemAccess= BPF LSM program */
484 RestrictFileSystemAccess restrict_filesystem_access;
485
486 /* Raw BPF FDs extracted from the skeleton after attach. The kernel
487 * reference chain (link FD -> bpf_link -> bpf_prog -> bpf_map) keeps
488 * programs attached and map data alive. The .bss map FD is used for
489 * targeted writes (clearing initramfs_s_dev after switch_root). */
490 int restrict_fsaccess_link_fds[_RESTRICT_FILESYSTEM_ACCESS_LINK_MAX];
491 int restrict_fsaccess_bss_map_fd;
492
493 /* Allow users to configure a rate limit for Reload()/Reexecute() operations */
494 RateLimit reload_reexec_ratelimit;
495 /* Dump*() are slow, so always rate limit them to 10 per 10 minutes */
496 RateLimit dump_ratelimit;
497
498 /* Rate limit for the manager event loop */
499 RateLimit event_loop_ratelimit;
500
501 sd_event_source *pressure_event_source[_PRESSURE_RESOURCE_MAX];
502
503 /* For NFTSet= */
504 sd_netlink *nfnl;
505
506 /* Pin the systemd-executor binary, so that it never changes until re-exec, ensuring we don't have
507 * serialization/deserialization compatibility issues during upgrades. */
508 char *executor_path;
509 int executor_fd;
510
511 unsigned soft_reboots_count;
512
513 /* The number of successfully completed configuration reloads. */
514 uint64_t reload_count;
515
516 /* Monotonic counter for fdstore entries propagated to a NOTIFY_SOCKET supervisor. Each propagated
517 * fd is sent upstream using this index as the FDNAME. The mapping (index -> unit_id + original fdname)
518 * is pushed alongside as a JSON memfd named "systemd-fdstore-mapping". */
519 uint64_t fd_store_upstream_next_index;
520
521 /* Original ambient capabilities when we were initialized */
522 uint64_t saved_ambient_set;
523 } Manager;
524
525 static inline usec_t manager_default_timeout_abort_usec(Manager *m) {
526 assert(m);
527 return m->defaults.timeout_abort_set ? m->defaults.timeout_abort_usec : m->defaults.timeout_stop_usec;
528 }
529
530 #define MANAGER_IS_SYSTEM(m) ((m)->runtime_scope == RUNTIME_SCOPE_SYSTEM)
531 #define MANAGER_IS_USER(m) ((m)->runtime_scope == RUNTIME_SCOPE_USER)
532
533 #define MANAGER_IS_RELOADING(m) ((m)->n_reloading > 0)
534
535 #define MANAGER_IS_FINISHED(m) (dual_timestamp_is_set((m)->timestamps + MANAGER_TIMESTAMP_FINISH))
536
537 /* The objective is set to OK as soon as we enter the main loop, and set otherwise as soon as we are done with it */
538 #define MANAGER_IS_RUNNING(m) ((m)->objective == MANAGER_OK)
539
540 #define MANAGER_IS_SWITCHING_ROOT(m) ((m)->switching_root)
541
542 #define MANAGER_IS_TEST_RUN(m) ((m)->test_run_flags != 0)
543
544 usec_t manager_default_timeout(RuntimeScope scope);
545
546 int manager_new(RuntimeScope scope, ManagerTestRunFlags test_run_flags, Manager **ret);
547 Manager* manager_free(Manager *m);
548 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
549
550 /* One entry parsed out of the upstream "systemd-fdstore-mapping" memfd. Pairs the numeric index from the
551 * JSON map to the (unit-id, original fdname) the fd was originally stored as. */
552 typedef struct ListenFDsTag {
553 char *unit_id;
554 char *fdname;
555 uint64_t index;
556 } ListenFDsTag;
557
558 ListenFDsTag* listen_fds_tag_free(ListenFDsTag *t);
559 DEFINE_TRIVIAL_CLEANUP_FUNC(ListenFDsTag*, listen_fds_tag_free);
560
561 extern const struct hash_ops fd_to_listen_fds_tag_hash_ops;
562
563 int manager_startup(Manager *m, FILE *serialization, FDSet *fds, Hashmap *named_listen_fds, const char *root);
564
565 Job *manager_get_job(Manager *m, uint32_t id);
566 Unit *manager_get_unit(Manager *m, const char *name);
567
568 int manager_get_job_from_dbus_path(Manager *m, const char *s, Job **_j);
569
570 bool manager_unit_cache_should_retry_load(Unit *u);
571 int manager_load_unit_prepare(Manager *m, const char *name, const char *path, sd_bus_error *e, Unit **ret);
572 int manager_load_unit(Manager *m, const char *name, const char *path, sd_bus_error *e, Unit **ret);
573 int manager_dispatch_external_fd_to_unit(Manager *m, const char *unit_id, const char *fdname, uint64_t index, int fd, const char *log_context);
574 int manager_load_startable_unit_or_warn(Manager *m, const char *name, const char *path, Unit **ret);
575 int manager_load_unit_from_dbus_path(Manager *m, const char *s, sd_bus_error *e, Unit **_u);
576
577 int manager_add_job_full(
578 Manager *m,
579 JobType type,
580 Unit *unit,
581 JobMode mode,
582 TransactionAddFlags extra_flags,
583 Set *affected_jobs,
584 sd_bus_error *reterr_error,
585 Job **ret);
586 int manager_add_job(
587 Manager *m,
588 JobType type,
589 Unit *unit,
590 JobMode mode,
591 sd_bus_error *reterr_error,
592 Job **ret);
593
594 int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode mode, Set *affected_jobs, sd_bus_error *e, Job **ret);
595 int manager_add_job_by_name_and_warn(Manager *m, JobType type, const char *name, JobMode mode, Set *affected_jobs, Job **ret);
596 int manager_propagate_reload(Manager *m, Unit *unit, JobMode mode, sd_bus_error *e);
597
598 void manager_clear_jobs(Manager *m);
599
600 void manager_unwatch_pidref(Manager *m, const PidRef *pid);
601
602 unsigned manager_dispatch_load_queue(Manager *m);
603
604 int manager_setup_pressure_event_source(Manager *m, PressureResource t);
605
606 int manager_default_environment(Manager *m);
607 int manager_transient_environment_add(Manager *m, char **plus);
608 int manager_client_environment_modify(Manager *m, char **minus, char **plus);
609 int manager_get_effective_environment(Manager *m, char ***ret);
610
611 int manager_set_unit_defaults(Manager *m, const UnitDefaults *defaults);
612
613 void manager_trigger_run_queue(Manager *m);
614
615 int manager_loop(Manager *m);
616
617 int manager_reload(Manager *m);
618 Manager* manager_reloading_start(Manager *m);
619 void manager_reloading_stopp(Manager **m);
620
621 void manager_reset_failed(Manager *m);
622
623 void manager_send_unit_audit(Manager *m, Unit *u, int type, bool success);
624 void manager_send_unit_plymouth(Manager *m, Unit *u);
625 void manager_send_unit_supervisor(Manager *m, Unit *u, bool active);
626
627 bool manager_unit_inactive_or_pending(Manager *m, const char *name);
628
629 void manager_check_finished(Manager *m);
630 void manager_send_reloading(Manager *m);
631
632 void disable_printk_ratelimit(void);
633 void manager_recheck_dbus(Manager *m);
634 void manager_recheck_journal(Manager *m);
635
636 bool manager_get_show_status_on(Manager *m);
637 void manager_set_show_status(Manager *m, ShowStatus mode, const char *reason);
638 void manager_override_show_status(Manager *m, ShowStatus mode, const char *reason);
639
640 void manager_set_first_boot(Manager *m, bool b);
641 void manager_set_switching_root(Manager *m, bool switching_root);
642
643 double manager_get_progress(Manager *m);
644
645 void manager_status_printf(Manager *m, StatusType type, const char *status, const char *format, ...) _printf_(4,5);
646
647 Set* manager_get_units_needing_mounts_for(Manager *m, const char *path, UnitMountDependencyType t);
648
649 ManagerState manager_state(Manager *m);
650
651 int manager_update_failed_units(Manager *m, Unit *u, bool failed);
652
653 void manager_unref_uid(Manager *m, uid_t uid, bool destroy_now);
654 int manager_ref_uid(Manager *m, uid_t uid, bool clean_ipc);
655
656 void manager_unref_gid(Manager *m, gid_t gid, bool destroy_now);
657 int manager_ref_gid(Manager *m, gid_t gid, bool clean_ipc);
658
659 void manager_ref_console(Manager *m);
660 void manager_unref_console(Manager *m);
661
662 void manager_override_log_level(Manager *m, int level);
663 void manager_restore_original_log_level(Manager *m);
664
665 void manager_override_log_target(Manager *m, LogTarget target);
666 void manager_restore_original_log_target(Manager *m);
667
668 const char* manager_get_confirm_spawn(Manager *m);
669 void manager_disable_confirm_spawn(void);
670
671 DECLARE_STRING_TABLE_LOOKUP(manager_state, ManagerState);
672
673 DECLARE_STRING_TABLE_LOOKUP(manager_objective, ManagerObjective);
674
675 DECLARE_STRING_TABLE_LOOKUP(manager_timestamp, ManagerTimestamp);
676 ManagerTimestamp manager_timestamp_initrd_mangle(ManagerTimestamp s);
677
678 usec_t manager_get_watchdog(Manager *m, WatchdogType t);
679 void manager_set_watchdog(Manager *m, WatchdogType t, usec_t timeout);
680 void manager_override_watchdog(Manager *m, WatchdogType t, usec_t timeout);
681 int manager_set_watchdog_pretimeout_governor(Manager *m, const char *governor);
682 int manager_override_watchdog_pretimeout_governor(Manager *m, const char *governor);
683
684 LogTarget manager_get_executor_log_target(Manager *m);
685
686 void manager_log_caller(Manager *manager, PidRef *caller, const char *method);
687
688 int manager_allocate_idle_pipe(Manager *m);
689
690 void unit_defaults_init(UnitDefaults *defaults, RuntimeScope scope);
691 void unit_defaults_done(UnitDefaults *defaults);
692
693 enum {
694 /* most important … */
695 EVENT_PRIORITY_USER_LOOKUP = SD_EVENT_PRIORITY_NORMAL-12,
696 EVENT_PRIORITY_MOUNT_TABLE = SD_EVENT_PRIORITY_NORMAL-11,
697 EVENT_PRIORITY_SWAP_TABLE = SD_EVENT_PRIORITY_NORMAL-11,
698 EVENT_PRIORITY_CGROUP_INOTIFY = SD_EVENT_PRIORITY_NORMAL-10,
699 EVENT_PRIORITY_CGROUP_OOM = SD_EVENT_PRIORITY_NORMAL-9,
700 EVENT_PRIORITY_PIDREF = SD_EVENT_PRIORITY_NORMAL-8,
701 EVENT_PRIORITY_HANDOFF_TIMESTAMP = SD_EVENT_PRIORITY_NORMAL-7,
702 EVENT_PRIORITY_EXEC_FD = SD_EVENT_PRIORITY_NORMAL-6,
703 EVENT_PRIORITY_NOTIFY = SD_EVENT_PRIORITY_NORMAL-5,
704 EVENT_PRIORITY_SIGCHLD = SD_EVENT_PRIORITY_NORMAL-4,
705 EVENT_PRIORITY_SIGNALS = SD_EVENT_PRIORITY_NORMAL-3,
706 EVENT_PRIORITY_CGROUP_EMPTY = SD_EVENT_PRIORITY_NORMAL-2,
707 EVENT_PRIORITY_TIME_CHANGE = SD_EVENT_PRIORITY_NORMAL-1,
708 EVENT_PRIORITY_TIME_ZONE = SD_EVENT_PRIORITY_NORMAL-1,
709 EVENT_PRIORITY_IPC = SD_EVENT_PRIORITY_NORMAL,
710 EVENT_PRIORITY_SERVICE_WATCHDOG = SD_EVENT_PRIORITY_IDLE,
711 EVENT_PRIORITY_RUN_QUEUE = SD_EVENT_PRIORITY_IDLE+1,
712 /* … to least important */
713 };