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