]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
c2f1db8f | 2 | #pragma once |
60918275 | 3 | |
718db961 | 4 | #include "sd-event.h" |
71d35b6b | 5 | |
3a0f06c4 | 6 | #include "cgroup.h" |
4ea4abb6 | 7 | #include "common-signal.h" |
4ea4abb6 | 8 | #include "execute.h" |
836e4e7e DDM |
9 | #include "forward.h" |
10 | #include "log.h" | |
1e35e81b | 11 | #include "path-lookup.h" |
4ea4abb6 | 12 | #include "show-status.h" |
4ea4abb6 | 13 | #include "unit.h" |
a16e1123 | 14 | |
227b8a76 MO |
15 | struct libmnt_monitor; |
16 | ||
4f0f902f | 17 | /* Enforce upper limit how many names we allow */ |
59d1a833 | 18 | #define MANAGER_MAX_NAMES 131072 /* 128K */ |
4f0f902f | 19 | |
0112c37c LB |
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 | ||
89998745 LP |
28 | /* An externally visible state. We don't actually maintain this as state variable, but derive it from various fields |
29 | * when requested */ | |
f755e3b7 | 30 | typedef enum ManagerState { |
d81afec1 | 31 | MANAGER_INITIALIZING, |
f755e3b7 | 32 | MANAGER_STARTING, |
a16e1123 | 33 | MANAGER_RUNNING, |
f755e3b7 LP |
34 | MANAGER_DEGRADED, |
35 | MANAGER_MAINTENANCE, | |
36 | MANAGER_STOPPING, | |
37 | _MANAGER_STATE_MAX, | |
2d93c20e | 38 | _MANAGER_STATE_INVALID = -EINVAL, |
f755e3b7 LP |
39 | } ManagerState; |
40 | ||
af41e508 | 41 | typedef enum ManagerObjective { |
f755e3b7 | 42 | MANAGER_OK, |
a16e1123 LP |
43 | MANAGER_EXIT, |
44 | MANAGER_RELOAD, | |
45 | MANAGER_REEXECUTE, | |
b9080b03 | 46 | MANAGER_REBOOT, |
13ffc607 | 47 | MANAGER_SOFT_REBOOT, |
b9080b03 FF |
48 | MANAGER_POWEROFF, |
49 | MANAGER_HALT, | |
50 | MANAGER_KEXEC, | |
664f88a7 | 51 | MANAGER_SWITCH_ROOT, |
af41e508 | 52 | _MANAGER_OBJECTIVE_MAX, |
2d93c20e | 53 | _MANAGER_OBJECTIVE_INVALID = -EINVAL, |
af41e508 | 54 | } ManagerObjective; |
a16e1123 | 55 | |
7bc740f4 YW |
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 | ||
9f9f0342 LP |
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, | |
49fbe940 | 91 | MANAGER_TIMESTAMP_UNITS_LOAD, |
d4ee7bd8 YW |
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, | |
54f86b86 | 99 | |
b3f54861 | 100 | MANAGER_TIMESTAMP_SHUTDOWN_START, |
54f86b86 | 101 | |
9f9f0342 | 102 | _MANAGER_TIMESTAMP_MAX, |
2d93c20e | 103 | _MANAGER_TIMESTAMP_INVALID = -EINVAL, |
9f9f0342 LP |
104 | } ManagerTimestamp; |
105 | ||
986935cf FB |
106 | typedef enum WatchdogType { |
107 | WATCHDOG_RUNTIME, | |
108 | WATCHDOG_REBOOT, | |
109 | WATCHDOG_KEXEC, | |
5717062e | 110 | WATCHDOG_PRETIMEOUT, |
986935cf FB |
111 | _WATCHDOG_TYPE_MAX, |
112 | } WatchdogType; | |
113 | ||
638cece4 | 114 | typedef enum ManagerTestRunFlags { |
f14d6810 MG |
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 */ | |
bb5232b6 | 121 | MANAGER_TEST_DONT_OPEN_EXECUTOR = 1 << 5, /* avoid trying to load sd-executor */ |
e8112e67 | 122 | MANAGER_TEST_FULL = MANAGER_TEST_RUN_BASIC | MANAGER_TEST_RUN_ENV_GENERATORS | MANAGER_TEST_RUN_GENERATORS, |
638cece4 LP |
123 | } ManagerTestRunFlags; |
124 | ||
e0a3da1f ZJS |
125 | assert_cc((MANAGER_TEST_FULL & UINT8_MAX) == MANAGER_TEST_FULL); |
126 | ||
c9e120e0 LP |
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 | ||
14702b9c | 134 | RateLimit start_limit; |
c9e120e0 | 135 | |
c9e120e0 LP |
136 | bool memory_accounting; |
137 | bool io_accounting; | |
c9e120e0 LP |
138 | bool tasks_accounting; |
139 | bool ip_accounting; | |
140 | ||
94f0b13b | 141 | CGroupTasksMax tasks_max; |
c9e120e0 LP |
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 | ||
836e4e7e | 156 | typedef struct Manager { |
87f0e418 | 157 | /* Note that the set of units we know of is allowed to be |
35b8ca3a | 158 | * inconsistent. However the subset of it that is loaded may |
87d1515d LP |
159 | * not, and the list of jobs may neither. */ |
160 | ||
87f0e418 LP |
161 | /* Active jobs and units */ |
162 | Hashmap *units; /* name string => Unit object n:1 */ | |
4b58153d | 163 | Hashmap *units_by_invocation_id; |
60918275 LP |
164 | Hashmap *jobs; /* job id => Job object 1:1 */ |
165 | ||
ef734fd6 LP |
166 | /* To make it easy to iterate through the units of a specific |
167 | * type we maintain a per type linked list */ | |
ac155bb8 | 168 | LIST_HEAD(Unit, units_by_type[_UNIT_TYPE_MAX]); |
ef734fd6 | 169 | |
87f0e418 | 170 | /* Units that need to be loaded */ |
ac155bb8 | 171 | LIST_HEAD(Unit, load_queue); /* this is actually more a stack than a queue, but uh. */ |
60918275 | 172 | |
034c6ed7 | 173 | /* Jobs that need to be run */ |
da8e1782 | 174 | struct Prioq *run_queue; |
034c6ed7 | 175 | |
c1e1601e LP |
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. */ | |
ac155bb8 | 180 | LIST_HEAD(Unit, dbus_unit_queue); |
c1e1601e LP |
181 | LIST_HEAD(Job, dbus_job_queue); |
182 | ||
701cc384 | 183 | /* Units to remove */ |
ac155bb8 | 184 | LIST_HEAD(Unit, cleanup_queue); |
23a177ef | 185 | |
c5a97ed1 LP |
186 | /* Units and jobs to check when doing GC */ |
187 | LIST_HEAD(Unit, gc_unit_queue); | |
188 | LIST_HEAD(Job, gc_job_queue); | |
701cc384 | 189 | |
4ad49000 | 190 | /* Units that should be realized */ |
91a6073e | 191 | LIST_HEAD(Unit, cgroup_realize_queue); |
4ad49000 | 192 | |
09e24654 LP |
193 | /* Units whose cgroup ran empty */ |
194 | LIST_HEAD(Unit, cgroup_empty_queue); | |
195 | ||
afcfaa69 LP |
196 | /* Units whose memory.event fired */ |
197 | LIST_HEAD(Unit, cgroup_oom_queue); | |
198 | ||
19496554 MS |
199 | /* Target units whose default target dependencies haven't been set yet */ |
200 | LIST_HEAD(Unit, target_deps_queue); | |
201 | ||
a3c1168a LP |
202 | /* Units that might be subject to StopWhenUnneeded= clean-up */ |
203 | LIST_HEAD(Unit, stop_when_unneeded_queue); | |
204 | ||
0bc488c9 LP |
205 | /* Units which are upheld by another other which we might need to act on */ |
206 | LIST_HEAD(Unit, start_when_upheld_queue); | |
207 | ||
56c59592 LP |
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 | ||
6ac62d61 LP |
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 | ||
1b4ab5a2 MY |
214 | /* Units that perform certain actions after some other unit deactivates */ |
215 | LIST_HEAD(Unit, stop_notify_queue); | |
216 | ||
718db961 LP |
217 | sd_event *event; |
218 | ||
495e75ed LP |
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 | |
c06b8d96 MY |
225 | * interested in a PID we must look into both hashmaps. |
226 | * | |
227 | * NB: the ownership of PidRefs is held by Unit.pids! */ | |
495e75ed LP |
228 | Hashmap *watch_pids; /* PidRef* → Unit* */ |
229 | Hashmap *watch_pids_more; /* PidRef* → NUL terminated array of Unit* */ | |
9152c765 | 230 | |
95ae05c0 WC |
231 | /* A set contains all units which cgroup should be refreshed after startup */ |
232 | Set *startup_units; | |
233 | ||
f755e3b7 LP |
234 | /* A set which contains all currently failed units */ |
235 | Set *failed_units; | |
236 | ||
752b5905 LP |
237 | sd_event_source *run_queue_event_source; |
238 | ||
c952c6ec | 239 | char *notify_socket; |
718db961 LP |
240 | int notify_fd; |
241 | sd_event_source *notify_event_source; | |
242 | ||
243 | int signal_fd; | |
244 | sd_event_source *signal_event_source; | |
c952c6ec | 245 | |
575b300b LP |
246 | sd_event_source *sigchld_event_source; |
247 | ||
718db961 | 248 | sd_event_source *time_change_event_source; |
9d58f1db | 249 | |
bbf5fd8e LP |
250 | sd_event_source *timezone_change_event_source; |
251 | ||
718db961 | 252 | sd_event_source *jobs_in_progress_event_source; |
acbb0225 | 253 | |
00d9ef85 LP |
254 | int user_lookup_fds[2]; |
255 | sd_event_source *user_lookup_event_source; | |
256 | ||
817062e6 LP |
257 | int handoff_timestamp_fds[2]; |
258 | sd_event_source *handoff_timestamp_event_source; | |
259 | ||
406f1775 DDM |
260 | int pidref_transport_fds[2]; |
261 | sd_event_source *pidref_event_source; | |
262 | ||
4870133b LP |
263 | RuntimeScope runtime_scope; |
264 | ||
84e3543e | 265 | LookupPaths lookup_paths; |
e8630e69 ZJS |
266 | Hashmap *unit_id_map; |
267 | Hashmap *unit_name_map; | |
fe51822e | 268 | Set *unit_path_cache; |
c2911d48 | 269 | uint64_t unit_cache_timestamp_hash; |
036643a2 | 270 | |
a82b8b3d MY |
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 | ||
1ad6e8b3 LP |
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 */ | |
1137a57c | 279 | |
986935cf FB |
280 | usec_t watchdog[_WATCHDOG_TYPE_MAX]; |
281 | usec_t watchdog_overridden[_WATCHDOG_TYPE_MAX]; | |
aff3a9e1 LB |
282 | char *watchdog_pretimeout_governor; |
283 | char *watchdog_pretimeout_governor_overridden; | |
e96d6be7 | 284 | |
9f9f0342 | 285 | dual_timestamp timestamps[_MANAGER_TIMESTAMP_MAX]; |
8d567588 | 286 | |
9670d583 | 287 | /* Data specific to the device subsystem */ |
d0955f00 | 288 | sd_device_monitor *device_monitor; |
8fe914ec | 289 | Hashmap *devices_by_sysfs; |
ef734fd6 LP |
290 | |
291 | /* Data specific to the mount subsystem */ | |
d379d442 | 292 | struct libmnt_monitor *mount_monitor; |
718db961 | 293 | sd_event_source *mount_event_source; |
ea430986 | 294 | |
07b0b134 ML |
295 | /* Data specific to the swap filesystem */ |
296 | FILE *proc_swaps; | |
718db961 | 297 | sd_event_source *swap_event_source; |
9670d583 | 298 | Hashmap *swaps_by_devnode; |
07b0b134 | 299 | |
ea430986 | 300 | /* Data specific to the D-Bus subsystem */ |
718db961 LP |
301 | sd_bus *api_bus, *system_bus; |
302 | Set *private_buses; | |
303 | int private_listen_fd; | |
304 | sd_event_source *private_listen_event_source; | |
8f8f05a9 | 305 | |
1446e3c3 MY |
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. */ | |
8f8f05a9 | 309 | sd_bus_track *subscribed; |
e1315a62 | 310 | char **subscribed_as_strv; |
5e8d1c9a | 311 | |
1446e3c3 MY |
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 | ||
8f88ecf6 LP |
316 | /* This is used during reloading: before the reload we queue |
317 | * the reply message here, and afterwards we send it */ | |
209de525 | 318 | sd_bus_message *pending_reload_message; |
8e274523 | 319 | |
05e343b7 | 320 | Hashmap *watch_bus; /* D-Bus names => Unit object n:1 */ |
05e343b7 | 321 | |
71445ae7 LP |
322 | bool send_reloading_done; |
323 | ||
7fab9d01 | 324 | uint32_t current_job_id; |
bacbccb7 | 325 | uint32_t default_unit_job_id; |
7fab9d01 | 326 | |
9d58f1db LP |
327 | /* Data specific to the Automount subsystem */ |
328 | int dev_autofs_fd; | |
329 | ||
8e274523 | 330 | /* Data specific to the cgroup subsystem */ |
4ad49000 | 331 | Hashmap *cgroup_unit; |
efdb0237 | 332 | CGroupMask cgroup_supported; |
9444b1f2 | 333 | char *cgroup_root; |
e537352b | 334 | |
09e24654 | 335 | /* Notifications from cgroups, when the unified hierarchy is used is done via inotify. */ |
efdb0237 LP |
336 | int cgroup_inotify_fd; |
337 | sd_event_source *cgroup_inotify_event_source; | |
afcfaa69 LP |
338 | |
339 | /* Maps for finding the unit for each inotify watch descriptor for the cgroup.events and | |
340 | * memory.events cgroupv2 attributes. */ | |
0bb814c2 | 341 | Hashmap *cgroup_control_inotify_wd_unit; |
afcfaa69 | 342 | Hashmap *cgroup_memory_inotify_wd_unit; |
701cc384 | 343 | |
09e24654 LP |
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; | |
afcfaa69 | 346 | sd_event_source *cgroup_oom_event_source; |
09e24654 | 347 | |
35b8ca3a | 348 | /* Make sure the user cannot accidentally unmount our cgroup |
33be102a LP |
349 | * file system */ |
350 | int pin_cgroupfs_fd; | |
351 | ||
892a035c | 352 | unsigned gc_marker; |
efdb0237 | 353 | |
bbf5fd8e LP |
354 | /* The stat() data the last time we saw /etc/localtime */ |
355 | usec_t etc_localtime_mtime; | |
ec08f270 | 356 | bool etc_localtime_accessible; |
bbf5fd8e | 357 | |
ec08f270 | 358 | ManagerObjective objective; |
8c15bf36 LB |
359 | /* Objective as it was before serialization, mostly to detect soft-reboots */ |
360 | ManagerObjective previous_objective; | |
41447faf | 361 | |
af41e508 | 362 | /* Flags */ |
ec08f270 | 363 | bool dispatching_load_queue; |
1b4ab5a2 | 364 | int may_dispatch_stop_notify_queue; /* tristate */ |
9d58f1db | 365 | |
d8eb10d6 | 366 | /* Have we already sent out the READY=1 notification? */ |
ec08f270 | 367 | bool ready_sent; |
0c2826c6 | 368 | |
6d932659 ZJS |
369 | /* Was the last status sent "STATUS=Ready."? */ |
370 | bool status_ready; | |
371 | ||
d8eb10d6 | 372 | /* Have we already printed the taint line if necessary? */ |
ec08f270 | 373 | bool taint_logged; |
d8eb10d6 | 374 | |
00b5974f | 375 | /* Have we ever changed the "kernel.pid_max" sysctl? */ |
ec08f270 | 376 | bool sysctl_pid_max_changed; |
00b5974f | 377 | |
ec08f270 | 378 | ManagerTestRunFlags test_run_flags; |
0d8c31ff | 379 | |
287419c1 AC |
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 | ||
d450b6f2 | 385 | ShowStatus show_status; |
44a41954 | 386 | ShowStatus show_status_overridden; |
36cf4507 | 387 | StatusUnitFormat status_unit_format; |
7d5ceb64 | 388 | char *confirm_spawn; |
31a7eb86 | 389 | bool no_console_output; |
2a12e32e | 390 | bool service_watchdogs; |
d3689161 | 391 | |
c9e120e0 | 392 | UnitDefaults defaults; |
6bb00842 | 393 | |
a6ecbf83 | 394 | int original_log_level; |
bda7d78b | 395 | LogTarget original_log_target; |
ec08f270 ZJS |
396 | bool log_level_overridden; |
397 | bool log_target_overridden; | |
a6ecbf83 | 398 | |
a7556052 LP |
399 | /* non-zero if we are reloading or reexecuting, */ |
400 | int n_reloading; | |
e409f875 LP |
401 | |
402 | unsigned n_installed_jobs; | |
76bf48b7 | 403 | unsigned n_failed_jobs; |
f2b68789 | 404 | |
03b717a3 | 405 | /* Jobs in progress watching */ |
637f8b8e | 406 | unsigned n_running_jobs; |
7ed9f6cd | 407 | unsigned n_on_console; |
03b717a3 | 408 | unsigned jobs_in_progress_iteration; |
637f8b8e | 409 | |
e46b13c8 ZJS |
410 | /* Do we have any outstanding password prompts? */ |
411 | int have_ask_password; | |
e46b13c8 ZJS |
412 | sd_event_source *ask_password_event_source; |
413 | ||
f2b68789 | 414 | /* Type=idle pipes */ |
31a7eb86 | 415 | int idle_pipe[4]; |
718db961 | 416 | sd_event_source *idle_pipe_event_source; |
664f88a7 LP |
417 | |
418 | char *switch_root; | |
419 | char *switch_root_init; | |
a57f7e2c | 420 | |
d35fe8c0 FB |
421 | /* This is true before and after switching root. */ |
422 | bool switching_root; | |
423 | ||
9e615fa3 LB |
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]; | |
e3dd987c | 427 | |
283868e1 SW |
428 | /* Used for processing polkit authorization responses */ |
429 | Hashmap *polkit_registry; | |
2e5c94b9 | 430 | |
29206d46 LP |
431 | /* Dynamic users/groups, indexed by their name */ |
432 | Hashmap *dynamic_users; | |
433 | ||
00d9ef85 LP |
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 | ||
e76506b7 DDM |
438 | /* ExecSharedRuntime, indexed by their owner unit id */ |
439 | Hashmap *exec_shared_runtime_by_id; | |
e8a565cb | 440 | |
24dd31c1 | 441 | /* When the user hits C-A-D more than 7 times per 2s, do something immediately... */ |
2e5c94b9 | 442 | RateLimit ctrl_alt_del_ratelimit; |
ae8c7939 | 443 | EmergencyAction cad_burst_action; |
f2341e0a | 444 | |
463d0d15 | 445 | int first_boot; /* tri-state */ |
3536f49e | 446 | |
62a76913 | 447 | /* Prefixes of e.g. RuntimeDirectory= */ |
72fd1768 | 448 | char *prefix[_EXEC_DIRECTORY_TYPE_MAX]; |
2ad591a3 LP |
449 | char *received_credentials_directory; |
450 | char *received_encrypted_credentials_directory; | |
62a76913 LP |
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; | |
19d22d43 | 456 | |
25ff515b | 457 | sd_varlink_server *varlink_server; |
064a5c14 DDM |
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). */ | |
25ff515b | 462 | sd_varlink *managed_oom_varlink; |
184b4f78 ILG |
463 | |
464 | /* Reference to RestrictFileSystems= BPF program */ | |
465 | struct restrict_fs_bpf *restrict_fs; | |
aa5ae971 | 466 | |
8312b17a LB |
467 | /* Allow users to configure a rate limit for Reload()/Reexecute() operations */ |
468 | RateLimit reload_reexec_ratelimit; | |
d9365956 LB |
469 | /* Dump*() are slow, so always rate limit them to 10 per 10 minutes */ |
470 | RateLimit dump_ratelimit; | |
29e6b0c1 LP |
471 | |
472 | sd_event_source *memory_pressure_event_source; | |
dc7d69b3 TM |
473 | |
474 | /* For NFTSet= */ | |
475 | FirewallContext *fw_ctx; | |
bb5232b6 LB |
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. */ | |
b157a7e6 | 479 | char *executor_path; |
bb5232b6 | 480 | int executor_fd; |
66f35161 LB |
481 | |
482 | unsigned soft_reboots_count; | |
e0ebc81b ŁS |
483 | |
484 | /* Original ambient capabilities when we were initialized */ | |
b004393d | 485 | uint64_t saved_ambient_set; |
836e4e7e | 486 | } Manager; |
60918275 | 487 | |
dc653bf4 | 488 | static inline usec_t manager_default_timeout_abort_usec(Manager *m) { |
9c79f0e0 | 489 | assert(m); |
c9e120e0 | 490 | return m->defaults.timeout_abort_set ? m->defaults.timeout_abort_usec : m->defaults.timeout_stop_usec; |
dc653bf4 JK |
491 | } |
492 | ||
4870133b LP |
493 | #define MANAGER_IS_SYSTEM(m) ((m)->runtime_scope == RUNTIME_SCOPE_SYSTEM) |
494 | #define MANAGER_IS_USER(m) ((m)->runtime_scope == RUNTIME_SCOPE_USER) | |
463d0d15 | 495 | |
2c289ea8 LP |
496 | #define MANAGER_IS_RELOADING(m) ((m)->n_reloading > 0) |
497 | ||
49d5666c LP |
498 | #define MANAGER_IS_FINISHED(m) (dual_timestamp_is_set((m)->timestamps + MANAGER_TIMESTAMP_FINISH)) |
499 | ||
af41e508 LP |
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) | |
4259d202 | 502 | |
d35fe8c0 FB |
503 | #define MANAGER_IS_SWITCHING_ROOT(m) ((m)->switching_root) |
504 | ||
638cece4 LP |
505 | #define MANAGER_IS_TEST_RUN(m) ((m)->test_run_flags != 0) |
506 | ||
836e4e7e | 507 | usec_t manager_default_timeout(RuntimeScope scope); |
e4c7b5f5 | 508 | |
4870133b | 509 | int manager_new(RuntimeScope scope, ManagerTestRunFlags test_run_flags, Manager **m); |
06d8d842 | 510 | Manager* manager_free(Manager *m); |
c70cac54 | 511 | DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free); |
60918275 | 512 | |
2a7cf953 | 513 | int manager_startup(Manager *m, FILE *serialization, FDSet *fds, const char *root); |
f50e0a01 | 514 | |
60918275 | 515 | Job *manager_get_job(Manager *m, uint32_t id); |
87f0e418 | 516 | Unit *manager_get_unit(Manager *m, const char *name); |
60918275 | 517 | |
86fbf370 | 518 | int manager_get_job_from_dbus_path(Manager *m, const char *s, Job **_j); |
ea430986 | 519 | |
81be2388 | 520 | bool manager_unit_cache_should_retry_load(Unit *u); |
4b6a2b3f ZJS |
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); | |
4109ede7 | 523 | int manager_load_startable_unit_or_warn(Manager *m, const char *name, const char *path, Unit **ret); |
718db961 | 524 | int manager_load_unit_from_dbus_path(Manager *m, const char *s, sd_bus_error *e, Unit **_u); |
28247076 | 525 | |
d993ad6c MY |
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); | |
836e4e7e | 535 | int manager_add_job( |
d993ad6c MY |
536 | Manager *m, |
537 | JobType type, | |
538 | Unit *unit, | |
539 | JobMode mode, | |
540 | sd_bus_error *error, | |
836e4e7e DDM |
541 | Job **ret); |
542 | ||
d993ad6c MY |
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); | |
15d167f8 | 545 | int manager_propagate_reload(Manager *m, Unit *unit, JobMode mode, sd_bus_error *e); |
60918275 | 546 | |
7fad411c LP |
547 | void manager_clear_jobs(Manager *m); |
548 | ||
d70dfe1b | 549 | void manager_unwatch_pidref(Manager *m, const PidRef *pid); |
f75f613d | 550 | |
c1e1601e | 551 | unsigned manager_dispatch_load_queue(Manager *m); |
f50e0a01 | 552 | |
29e6b0c1 LP |
553 | int manager_setup_memory_pressure_event_source(Manager *m); |
554 | ||
79a224c4 | 555 | int manager_default_environment(Manager *m); |
1ad6e8b3 LP |
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 | ||
bfb27b06 | 560 | int manager_set_unit_defaults(Manager *m, const UnitDefaults *defaults); |
b2bb3dbe | 561 | |
b0c4b282 LP |
562 | void manager_trigger_run_queue(Manager *m); |
563 | ||
9152c765 | 564 | int manager_loop(Manager *m); |
83c60c9f | 565 | |
a16e1123 | 566 | int manager_reload(Manager *m); |
a01ba4b2 ZJS |
567 | Manager* manager_reloading_start(Manager *m); |
568 | void manager_reloading_stopp(Manager **m); | |
a16e1123 | 569 | |
fdf20a31 | 570 | void manager_reset_failed(Manager *m); |
5632e374 | 571 | |
4927fcae | 572 | void manager_send_unit_audit(Manager *m, Unit *u, int type, bool success); |
e983b760 | 573 | void manager_send_unit_plymouth(Manager *m, Unit *u); |
b2d6bb5b | 574 | void manager_send_unit_supervisor(Manager *m, Unit *u, bool active); |
4927fcae | 575 | |
31afa0a4 | 576 | bool manager_unit_inactive_or_pending(Manager *m, const char *name); |
8f6df3fa | 577 | |
b0c918b9 | 578 | void manager_check_finished(Manager *m); |
dd0ab174 | 579 | void manager_send_reloading(Manager *m); |
b0c918b9 | 580 | |
6123dfaa | 581 | void disable_printk_ratelimit(void); |
8559b3b7 | 582 | void manager_recheck_dbus(Manager *m); |
4cfa2c99 | 583 | void manager_recheck_journal(Manager *m); |
f1dd0c3f | 584 | |
44a41954 | 585 | bool manager_get_show_status_on(Manager *m); |
7365a296 | 586 | void manager_set_show_status(Manager *m, ShowStatus mode, const char *reason); |
43bba15a | 587 | void manager_override_show_status(Manager *m, ShowStatus mode, const char *reason); |
44a41954 | 588 | |
e2680723 | 589 | void manager_set_first_boot(Manager *m, bool b); |
d35fe8c0 | 590 | void manager_set_switching_root(Manager *m, bool switching_root); |
e2680723 | 591 | |
cc156539 DDM |
592 | double manager_get_progress(Manager *m); |
593 | ||
127d5fd1 | 594 | void manager_status_printf(Manager *m, StatusType type, const char *status, const char *format, ...) _printf_(4,5); |
68b29a9f | 595 | |
9e615fa3 | 596 | Set* manager_get_units_needing_mounts_for(Manager *m, const char *path, UnitMountDependencyType t); |
e66cf1a3 | 597 | |
f755e3b7 LP |
598 | ManagerState manager_state(Manager *m); |
599 | ||
5269eb6b | 600 | int manager_update_failed_units(Manager *m, Unit *u, bool failed); |
03455c28 | 601 | |
00d9ef85 LP |
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); | |
2571aafb | 606 | int manager_ref_gid(Manager *m, gid_t gid, bool clean_ipc); |
00d9ef85 | 607 | |
adefcf28 LP |
608 | void manager_ref_console(Manager *m); |
609 | void manager_unref_console(Manager *m); | |
610 | ||
a6ecbf83 FB |
611 | void manager_override_log_level(Manager *m, int level); |
612 | void manager_restore_original_log_level(Manager *m); | |
613 | ||
bda7d78b FB |
614 | void manager_override_log_target(Manager *m, LogTarget target); |
615 | void manager_restore_original_log_target(Manager *m); | |
616 | ||
37ca2ccf MY |
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_; | |
f755e3b7 | 621 | ManagerState manager_state_from_string(const char *s) _pure_; |
7d5ceb64 | 622 | |
37ca2ccf MY |
623 | const char* manager_objective_to_string(ManagerObjective m) _const_; |
624 | ManagerObjective manager_objective_from_string(const char *s) _pure_; | |
9f9f0342 | 625 | |
37ca2ccf | 626 | const char* manager_timestamp_to_string(ManagerTimestamp m) _const_; |
9f9f0342 | 627 | ManagerTimestamp manager_timestamp_from_string(const char *s) _pure_; |
d4ee7bd8 | 628 | ManagerTimestamp manager_timestamp_initrd_mangle(ManagerTimestamp s); |
afcfaa69 | 629 | |
986935cf FB |
630 | usec_t manager_get_watchdog(Manager *m, WatchdogType t); |
631 | void manager_set_watchdog(Manager *m, WatchdogType t, usec_t timeout); | |
aac47032 | 632 | void manager_override_watchdog(Manager *m, WatchdogType t, usec_t timeout); |
aff3a9e1 LB |
633 | int manager_set_watchdog_pretimeout_governor(Manager *m, const char *governor); |
634 | int manager_override_watchdog_pretimeout_governor(Manager *m, const char *governor); | |
986935cf | 635 | |
bb5232b6 LB |
636 | LogTarget manager_get_executor_log_target(Manager *m); |
637 | ||
06044356 LP |
638 | int manager_allocate_idle_pipe(Manager *m); |
639 | ||
ea09a416 | 640 | void unit_defaults_init(UnitDefaults *defaults, RuntimeScope scope); |
c9e120e0 | 641 | void unit_defaults_done(UnitDefaults *defaults); |
d42b61d2 LP |
642 | |
643 | enum { | |
644 | /* most important … */ | |
406f1775 DDM |
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, | |
be1d96db | 648 | EVENT_PRIORITY_CGROUP_INOTIFY = SD_EVENT_PRIORITY_NORMAL-10, |
406f1775 DDM |
649 | EVENT_PRIORITY_CGROUP_OOM = SD_EVENT_PRIORITY_NORMAL-9, |
650 | EVENT_PRIORITY_PIDREF = SD_EVENT_PRIORITY_NORMAL-8, | |
817062e6 LP |
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, | |
55e4df21 MY |
660 | EVENT_PRIORITY_SERVICE_WATCHDOG = SD_EVENT_PRIORITY_IDLE, |
661 | EVENT_PRIORITY_RUN_QUEUE = SD_EVENT_PRIORITY_IDLE+1, | |
d42b61d2 LP |
662 | /* … to least important */ |
663 | }; |