]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
c2f1db8f | 2 | #pragma once |
5cb5a6ff | 3 | |
836e4e7e | 4 | #include "sd-id128.h" |
5cb5a6ff | 5 | |
890bdd1d | 6 | #include "bus-unit-util.h" |
9ce93478 | 7 | #include "cgroup-util.h" |
836e4e7e | 8 | #include "core-forward.h" |
0985c7c4 | 9 | #include "cpu-set-util.h" |
b3d59367 | 10 | #include "exec-util.h" |
71d35b6b | 11 | #include "list.h" |
4ea4abb6 | 12 | #include "log-context.h" |
417116f2 | 13 | #include "namespace.h" |
1808f768 | 14 | #include "numa-util.h" |
40d60725 | 15 | #include "ratelimit.h" |
a7cb43d8 | 16 | #include "rlimit-util.h" |
ca78ad1d | 17 | #include "time-util.h" |
5cb5a6ff | 18 | |
08f3be7a LP |
19 | #define EXEC_STDIN_DATA_MAX (64U*1024U*1024U) |
20 | ||
023a4f67 LP |
21 | typedef enum ExecUtmpMode { |
22 | EXEC_UTMP_INIT, | |
23 | EXEC_UTMP_LOGIN, | |
24 | EXEC_UTMP_USER, | |
25 | _EXEC_UTMP_MODE_MAX, | |
2d93c20e | 26 | _EXEC_UTMP_MODE_INVALID = -EINVAL, |
023a4f67 LP |
27 | } ExecUtmpMode; |
28 | ||
80876c20 LP |
29 | typedef enum ExecInput { |
30 | EXEC_INPUT_NULL, | |
31 | EXEC_INPUT_TTY, | |
32 | EXEC_INPUT_TTY_FORCE, | |
33 | EXEC_INPUT_TTY_FAIL, | |
4f2d528d | 34 | EXEC_INPUT_SOCKET, |
52c239d7 | 35 | EXEC_INPUT_NAMED_FD, |
08f3be7a | 36 | EXEC_INPUT_DATA, |
2038c3f5 | 37 | EXEC_INPUT_FILE, |
80876c20 | 38 | _EXEC_INPUT_MAX, |
2d93c20e | 39 | _EXEC_INPUT_INVALID = -EINVAL, |
80876c20 LP |
40 | } ExecInput; |
41 | ||
071830ff | 42 | typedef enum ExecOutput { |
80876c20 | 43 | EXEC_OUTPUT_INHERIT, |
94f04347 | 44 | EXEC_OUTPUT_NULL, |
80876c20 | 45 | EXEC_OUTPUT_TTY, |
9a6bca7a | 46 | EXEC_OUTPUT_KMSG, |
28dbc1e8 | 47 | EXEC_OUTPUT_KMSG_AND_CONSOLE, |
706343f4 LP |
48 | EXEC_OUTPUT_JOURNAL, |
49 | EXEC_OUTPUT_JOURNAL_AND_CONSOLE, | |
4f2d528d | 50 | EXEC_OUTPUT_SOCKET, |
52c239d7 | 51 | EXEC_OUTPUT_NAMED_FD, |
2038c3f5 | 52 | EXEC_OUTPUT_FILE, |
566b7d23 | 53 | EXEC_OUTPUT_FILE_APPEND, |
8d7dab1f | 54 | EXEC_OUTPUT_FILE_TRUNCATE, |
94f04347 | 55 | _EXEC_OUTPUT_MAX, |
2d93c20e | 56 | _EXEC_OUTPUT_INVALID = -EINVAL, |
071830ff LP |
57 | } ExecOutput; |
58 | ||
53f47dfc YW |
59 | typedef enum ExecPreserveMode { |
60 | EXEC_PRESERVE_NO, | |
61 | EXEC_PRESERVE_YES, | |
62 | EXEC_PRESERVE_RESTART, | |
63 | _EXEC_PRESERVE_MODE_MAX, | |
2d93c20e | 64 | _EXEC_PRESERVE_MODE_INVALID = -EINVAL, |
53f47dfc YW |
65 | } ExecPreserveMode; |
66 | ||
b1edf445 LP |
67 | typedef enum ExecKeyringMode { |
68 | EXEC_KEYRING_INHERIT, | |
69 | EXEC_KEYRING_PRIVATE, | |
70 | EXEC_KEYRING_SHARED, | |
71 | _EXEC_KEYRING_MODE_MAX, | |
2d93c20e | 72 | _EXEC_KEYRING_MODE_INVALID = -EINVAL, |
b1edf445 LP |
73 | } ExecKeyringMode; |
74 | ||
42cb05d5 | 75 | /* Contains start and exit information about an executed command. */ |
836e4e7e | 76 | typedef struct ExecStatus { |
63983207 LP |
77 | dual_timestamp start_timestamp; |
78 | dual_timestamp exit_timestamp; | |
3c1d1ca1 | 79 | dual_timestamp handoff_timestamp; |
0a6991e0 | 80 | pid_t pid; |
9152c765 | 81 | int code; /* as in siginfo_t::si_code */ |
fcb7138c | 82 | int status; /* as in siginfo_t::si_status */ |
836e4e7e | 83 | } ExecStatus; |
5cb5a6ff | 84 | |
42cb05d5 | 85 | /* Stores information about commands we execute. Covers both configuration settings as well as runtime data. */ |
836e4e7e | 86 | typedef struct ExecCommand { |
5cb5a6ff LP |
87 | char *path; |
88 | char **argv; | |
b806a5d3 | 89 | ExecStatus exec_status; /* Note that this is not serialized to sd-executor */ |
3ed0cd26 | 90 | ExecCommandFlags flags; |
034c6ed7 | 91 | LIST_FIELDS(ExecCommand, command); /* useful for chaining commands */ |
836e4e7e | 92 | } ExecCommand; |
5cb5a6ff | 93 | |
42cb05d5 LP |
94 | /* Encapsulates certain aspects of the runtime environment that is to be shared between multiple otherwise separate |
95 | * invocations of commands. Specifically, this allows sharing of /tmp and /var/tmp data as well as network namespaces | |
96 | * between invocations of commands. This is a reference counted object, with one reference taken by each currently | |
97 | * active command invocation that wants to share this runtime. */ | |
836e4e7e | 98 | typedef struct ExecSharedRuntime { |
cf4b2f99 | 99 | unsigned n_ref; |
613b411c | 100 | |
e8a565cb YW |
101 | Manager *manager; |
102 | ||
42cb05d5 | 103 | char *id; /* Unit id of the owner */ |
e8a565cb | 104 | |
613b411c LP |
105 | char *tmp_dir; |
106 | char *var_tmp_dir; | |
107 | ||
29206d46 LP |
108 | /* An AF_UNIX socket pair, that contains a datagram containing a file descriptor referring to the network |
109 | * namespace. */ | |
613b411c | 110 | int netns_storage_socket[2]; |
a70581ff XR |
111 | |
112 | /* Like netns_storage_socket, but the file descriptor is referring to the IPC namespace. */ | |
113 | int ipcns_storage_socket[2]; | |
836e4e7e | 114 | } ExecSharedRuntime; |
613b411c | 115 | |
836e4e7e | 116 | typedef struct ExecRuntime { |
28135da3 | 117 | ExecSharedRuntime *shared; |
15220772 | 118 | DynamicCreds *dynamic_creds; |
9c0c6701 DDM |
119 | |
120 | /* The path to the ephemeral snapshot of the root directory or root image if one was requested. */ | |
121 | char *ephemeral_copy; | |
122 | ||
123 | /* An AF_UNIX socket pair that receives the locked file descriptor referring to the ephemeral copy of | |
124 | * the root directory or root image. The lock prevents tmpfiles from removing the ephemeral snapshot | |
125 | * until we're done using it. */ | |
126 | int ephemeral_storage_socket[2]; | |
836e4e7e | 127 | } ExecRuntime; |
28135da3 | 128 | |
3536f49e | 129 | typedef enum ExecDirectoryType { |
d9e51371 | 130 | EXEC_DIRECTORY_RUNTIME, |
3536f49e YW |
131 | EXEC_DIRECTORY_STATE, |
132 | EXEC_DIRECTORY_CACHE, | |
133 | EXEC_DIRECTORY_LOGS, | |
134 | EXEC_DIRECTORY_CONFIGURATION, | |
72fd1768 | 135 | _EXEC_DIRECTORY_TYPE_MAX, |
2d93c20e | 136 | _EXEC_DIRECTORY_TYPE_INVALID = -EINVAL, |
3536f49e YW |
137 | } ExecDirectoryType; |
138 | ||
2ef87de9 LP |
139 | static inline bool EXEC_DIRECTORY_TYPE_SHALL_CHOWN(ExecDirectoryType t) { |
140 | /* Returns true for the ExecDirectoryTypes that we shall chown()ing for the user to. We do this for | |
141 | * all of them, except for configuration */ | |
142 | return t >= 0 && t < _EXEC_DIRECTORY_TYPE_MAX && t != EXEC_DIRECTORY_CONFIGURATION; | |
143 | } | |
144 | ||
211a3d87 LB |
145 | typedef struct ExecDirectoryItem { |
146 | char *path; | |
147 | char **symlinks; | |
890bdd1d | 148 | ExecDirectoryFlags flags; |
eae51272 | 149 | bool idmapped; |
211a3d87 LB |
150 | } ExecDirectoryItem; |
151 | ||
3536f49e | 152 | typedef struct ExecDirectory { |
3536f49e | 153 | mode_t mode; |
211a3d87 LB |
154 | size_t n_items; |
155 | ExecDirectoryItem *items; | |
3536f49e YW |
156 | } ExecDirectory; |
157 | ||
380dc8b0 LP |
158 | typedef enum ExecCleanMask { |
159 | /* In case you wonder why the bitmask below doesn't use "directory" in its name: we want to keep this | |
160 | * generic so that .timer timestamp files can nicely be covered by this too, and similar. */ | |
161 | EXEC_CLEAN_RUNTIME = 1U << EXEC_DIRECTORY_RUNTIME, | |
162 | EXEC_CLEAN_STATE = 1U << EXEC_DIRECTORY_STATE, | |
163 | EXEC_CLEAN_CACHE = 1U << EXEC_DIRECTORY_CACHE, | |
164 | EXEC_CLEAN_LOGS = 1U << EXEC_DIRECTORY_LOGS, | |
165 | EXEC_CLEAN_CONFIGURATION = 1U << EXEC_DIRECTORY_CONFIGURATION, | |
4fb8f1e8 | 166 | EXEC_CLEAN_FDSTORE = 1U << _EXEC_DIRECTORY_TYPE_MAX, |
380dc8b0 | 167 | EXEC_CLEAN_NONE = 0, |
4fb8f1e8 | 168 | EXEC_CLEAN_ALL = (1U << (_EXEC_DIRECTORY_TYPE_MAX+1)) - 1, |
2d93c20e | 169 | _EXEC_CLEAN_MASK_INVALID = -EINVAL, |
380dc8b0 LP |
170 | } ExecCleanMask; |
171 | ||
42cb05d5 LP |
172 | /* Encodes configuration parameters applied to invoked commands. Does not carry runtime data, but only configuration |
173 | * changes sourced from unit files and suchlike. ExecContext objects are usually embedded into Unit objects, and do not | |
174 | * change after being loaded. */ | |
836e4e7e | 175 | typedef struct ExecContext { |
5cb5a6ff | 176 | char **environment; |
8c7be95e | 177 | char **environment_files; |
b4c14404 | 178 | char **pass_environment; |
00819cc1 | 179 | char **unset_environment; |
8c7be95e | 180 | |
517d56b1 | 181 | struct rlimit *rlimit[_RLIMIT_MAX]; |
d4d55b0d LB |
182 | char *working_directory, *root_directory, *root_image, *root_verity, *root_hash_path, *root_hash_sig_path; |
183 | void *root_hash, *root_hash_sig; | |
184 | size_t root_hash_size, root_hash_sig_size; | |
18d73705 | 185 | LIST_HEAD(MountOptions, root_image_options); |
9c0c6701 | 186 | bool root_ephemeral; |
0a6991e0 LP |
187 | bool working_directory_missing_ok:1; |
188 | bool working_directory_home:1; | |
189 | ||
190 | bool oom_score_adjust_set:1; | |
ad21e542 | 191 | bool coredump_filter_set:1; |
0a6991e0 LP |
192 | bool nice_set:1; |
193 | bool ioprio_set:1; | |
194 | bool cpu_sched_set:1; | |
195 | ||
196 | /* This is not exposed to the user but available internally. We need it to make sure that whenever we | |
197 | * spawn /usr/bin/mount it is run in the same process group as us so that the autofs logic detects | |
198 | * that it belongs to us and we don't enter a trigger loop. */ | |
199 | bool same_pgrp; | |
200 | ||
201 | bool cpu_sched_reset_on_fork; | |
202 | bool non_blocking; | |
9d58f1db LP |
203 | |
204 | mode_t umask; | |
dd6c17b1 | 205 | int oom_score_adjust; |
5cb5a6ff | 206 | int nice; |
9eba9da4 | 207 | int ioprio; |
94f04347 LP |
208 | int cpu_sched_policy; |
209 | int cpu_sched_priority; | |
ad21e542 | 210 | uint64_t coredump_filter; |
9d58f1db | 211 | |
0985c7c4 | 212 | CPUSet cpu_set; |
b070c7c0 | 213 | NUMAPolicy numa_policy; |
e2b2fb7f | 214 | bool cpu_affinity_from_numa; |
fb33a393 | 215 | |
80876c20 LP |
216 | ExecInput std_input; |
217 | ExecOutput std_output; | |
218 | ExecOutput std_error; | |
561c1529 LP |
219 | |
220 | /* At least one of stdin/stdout/stderr was initialized from an fd passed in. This boolean survives | |
221 | * the fds being closed. This only makes sense for transient units. */ | |
0a6991e0 | 222 | bool stdio_as_fds; |
561c1529 | 223 | |
52c239d7 | 224 | char *stdio_fdname[3]; |
2038c3f5 | 225 | char *stdio_file[3]; |
80876c20 | 226 | |
08f3be7a LP |
227 | void *stdin_data; |
228 | size_t stdin_data_size; | |
80876c20 | 229 | |
d88a251b | 230 | nsec_t timer_slack_nsec; |
071830ff | 231 | |
9d58f1db | 232 | char *tty_path; |
5cb5a6ff | 233 | |
6ea832a2 LP |
234 | bool tty_reset; |
235 | bool tty_vhangup; | |
236 | bool tty_vt_disallocate; | |
237 | ||
51462135 DDM |
238 | unsigned tty_rows; |
239 | unsigned tty_cols; | |
240 | ||
353e12c2 LP |
241 | bool ignore_sigpipe; |
242 | ||
0a6991e0 LP |
243 | ExecKeyringMode keyring_mode; |
244 | ||
61233823 | 245 | /* Since resolving these names might involve socket |
5cb5a6ff | 246 | * connections and we don't want to deadlock ourselves these |
94f04347 LP |
247 | * names are resolved on execution only and in the child |
248 | * process. */ | |
5cb5a6ff LP |
249 | char *user; |
250 | char *group; | |
251 | char **supplementary_groups; | |
9d58f1db | 252 | |
854eca4a MY |
253 | int set_login_environment; |
254 | ||
5b6319dc LP |
255 | char *pam_name; |
256 | ||
169c1bda | 257 | char *utmp_id; |
023a4f67 | 258 | ExecUtmpMode utmp_mode; |
169c1bda | 259 | |
0a6991e0 | 260 | bool no_new_privileges; |
7b52a628 | 261 | |
0a6991e0 | 262 | bool selinux_context_ignore; |
eef65bf3 | 263 | bool apparmor_profile_ignore; |
2ca620c4 | 264 | bool smack_process_label_ignore; |
2ca620c4 | 265 | |
0a6991e0 LP |
266 | char *selinux_context; |
267 | char *apparmor_profile; | |
268 | char *smack_process_label; | |
b1edf445 | 269 | |
ddc155b2 | 270 | char **read_write_paths, **read_only_paths, **inaccessible_paths, **exec_paths, **no_exec_paths; |
8c35c10d | 271 | char **exec_search_path; |
874cdcbc | 272 | unsigned long mount_propagation_flag; |
d2d6c096 | 273 | BindMount *bind_mounts; |
da6053d0 | 274 | size_t n_bind_mounts; |
2abd4e38 | 275 | TemporaryFileSystem *temporary_filesystems; |
da6053d0 | 276 | size_t n_temporary_filesystems; |
b3d13314 LB |
277 | MountImage *mount_images; |
278 | size_t n_mount_images; | |
93f59701 LB |
279 | MountImage *extension_images; |
280 | size_t n_extension_images; | |
a07b9926 | 281 | char **extension_directories; |
15ae422b | 282 | |
a103496c | 283 | uint64_t capability_bounding_set; |
755d4b67 | 284 | uint64_t capability_ambient_set; |
9d58f1db LP |
285 | int secure_bits; |
286 | ||
7fab9d01 | 287 | int syslog_priority; |
7fab9d01 | 288 | bool syslog_level_prefix; |
0a6991e0 | 289 | char *syslog_identifier; |
d3070fbd LP |
290 | |
291 | struct iovec* log_extra_fields; | |
292 | size_t n_log_extra_fields; | |
523ea123 QD |
293 | Set *log_filter_allowed_patterns; |
294 | Set *log_filter_denied_patterns; | |
d3070fbd | 295 | |
14702b9c | 296 | RateLimit log_ratelimit; |
90fc172e | 297 | |
0a6991e0 LP |
298 | int log_level_max; |
299 | ||
91dd5f7c LP |
300 | char *log_namespace; |
301 | ||
4e399953 LP |
302 | ProtectProc protect_proc; /* hidepid= */ |
303 | ProcSubset proc_subset; /* subset= */ | |
304 | ||
24002121 | 305 | int private_mounts; |
0afd4d21 | 306 | int mount_apivfs; |
7a9f0125 | 307 | int bind_log_sockets; |
85614c6e | 308 | int memory_ksm; |
0e551b04 | 309 | PrivateTmp private_tmp; |
6156bec7 YW |
310 | PrivateTmp private_var_tmp; /* This is not an independent parameter, but calculated from other |
311 | * parameters in unit_patch_contexts(). */ | |
ff01d048 | 312 | bool private_network; |
7f112f50 | 313 | bool private_devices; |
fa693fdc | 314 | PrivateUsers private_users; |
a70581ff | 315 | bool private_ipc; |
59eeb84b | 316 | bool protect_kernel_tunables; |
502d704e | 317 | bool protect_kernel_modules; |
84703040 | 318 | bool protect_kernel_logs; |
fc64760d | 319 | bool protect_clock; |
5fe29238 | 320 | ProtectControlGroups protect_control_groups; |
0a6991e0 LP |
321 | ProtectSystem protect_system; |
322 | ProtectHome protect_home; | |
406f1775 | 323 | PrivatePIDs private_pids; |
6746f288 | 324 | ProtectHostname protect_hostname; |
e76fcd0e | 325 | char *private_hostname; |
9d58f1db | 326 | |
29206d46 | 327 | bool dynamic_user; |
00d9ef85 | 328 | bool remove_ipc; |
29206d46 | 329 | |
0a6991e0 LP |
330 | bool memory_deny_write_execute; |
331 | bool restrict_realtime; | |
f69567cb | 332 | bool restrict_suid_sgid; |
2e22afe9 | 333 | |
78e864e5 | 334 | bool lock_personality; |
0a6991e0 | 335 | unsigned long personality; |
ac45f971 | 336 | |
add00535 | 337 | unsigned long restrict_namespaces; /* The CLONE_NEWxyz flags permitted to the unit's processes */ |
8234cd99 | 338 | unsigned long delegate_namespaces; /* The CLONE_NEWxyz flags delegated to the unit's processes */ |
add00535 | 339 | |
b1994387 ILG |
340 | Set *restrict_filesystems; |
341 | bool restrict_filesystems_allow_list:1; | |
342 | ||
8cfa775f | 343 | Hashmap *syscall_filter; |
57183d11 | 344 | Set *syscall_archs; |
17df7223 | 345 | int syscall_errno; |
6b000af4 | 346 | bool syscall_allow_list:1; |
8351ceae | 347 | |
9df2cdd8 TM |
348 | Hashmap *syscall_log; |
349 | bool syscall_log_allow_list:1; /* Log listed system calls */ | |
350 | ||
6b000af4 | 351 | bool address_families_allow_list:1; |
0a6991e0 | 352 | Set *address_families; |
a8d08f39 LP |
353 | |
354 | char *network_namespace_path; | |
a70581ff | 355 | char *ipc_namespace_path; |
0a6991e0 LP |
356 | |
357 | ExecDirectory directories[_EXEC_DIRECTORY_TYPE_MAX]; | |
358 | ExecPreserveMode runtime_directory_preserve_mode; | |
12213aed | 359 | usec_t timeout_clean_usec; |
bb0c0d6f LP |
360 | |
361 | Hashmap *set_credentials; /* output id → ExecSetCredential */ | |
43144be4 | 362 | Hashmap *load_credentials; /* output id → ExecLoadCredential */ |
831f2087 | 363 | OrderedSet *import_credentials; /* ExecImportCredential */ |
84be0c71 LP |
364 | |
365 | ImagePolicy *root_image_policy, *mount_image_policy, *extension_image_policy; | |
836e4e7e | 366 | } ExecContext; |
74e12520 | 367 | |
c39f1ce2 | 368 | typedef enum ExecFlags { |
cfbf7538 MY |
369 | EXEC_APPLY_SANDBOXING = 1 << 0, |
370 | EXEC_APPLY_CHROOT = 1 << 1, | |
371 | EXEC_APPLY_TTY_STDIN = 1 << 2, | |
372 | EXEC_PASS_LOG_UNIT = 1 << 3, /* Whether to pass the unit name to the service's journal stream connection */ | |
373 | EXEC_CHOWN_DIRECTORIES = 1 << 4, /* chown() the runtime/state/cache/log directories to the user we run as, under all conditions */ | |
374 | EXEC_NSS_DYNAMIC_BYPASS = 1 << 5, /* Set the SYSTEMD_NSS_DYNAMIC_BYPASS environment variable, to disable nss-systemd blocking on PID 1, for use by dbus-daemon */ | |
375 | EXEC_CGROUP_DELEGATE = 1 << 6, | |
376 | EXEC_IS_CONTROL = 1 << 7, | |
377 | EXEC_CONTROL_CGROUP = 1 << 8, /* Place the process not in the indicated cgroup but in a subcgroup '/.control', but only EXEC_CGROUP_DELEGATE and EXEC_IS_CONTROL is set, too */ | |
378 | EXEC_SETUP_CREDENTIALS = 1 << 9, /* Set up the credential store logic */ | |
379 | EXEC_SETUP_CREDENTIALS_FRESH = 1 << 10, /* Set up a new credential store (disable reuse) */ | |
c39f1ce2 | 380 | |
9c1a61ad | 381 | /* The following are not used by execute.c, but by consumers internally */ |
cfbf7538 MY |
382 | EXEC_PASS_FDS = 1 << 11, |
383 | EXEC_SETENV_RESULT = 1 << 12, | |
384 | EXEC_SET_WATCHDOG = 1 << 13, | |
385 | EXEC_SETENV_MONITOR_RESULT = 1 << 14, /* Pass exit status to OnFailure= and OnSuccess= dependencies. */ | |
c39f1ce2 LP |
386 | } ExecFlags; |
387 | ||
42cb05d5 LP |
388 | /* Parameters for a specific invocation of a command. This structure is put together right before a command is |
389 | * executed. */ | |
836e4e7e | 390 | typedef struct ExecParameters { |
170d978b LP |
391 | RuntimeScope runtime_scope; |
392 | ||
a34ceba6 | 393 | char **environment; |
8dd4c05b LP |
394 | |
395 | int *fds; | |
396 | char **fd_names; | |
da6053d0 | 397 | size_t n_socket_fds; |
25b583d7 | 398 | size_t n_storage_fds; |
3543456f | 399 | size_t n_extra_fds; |
8dd4c05b | 400 | |
c39f1ce2 | 401 | ExecFlags flags; |
a34ceba6 | 402 | bool selinux_context_net:1; |
8dd4c05b | 403 | |
efdb0237 | 404 | CGroupMask cgroup_supported; |
beb4ae87 | 405 | char *cgroup_path; |
b646fc32 | 406 | uint64_t cgroup_id; |
8dd4c05b | 407 | |
3536f49e | 408 | char **prefix; |
beb4ae87 LB |
409 | char *received_credentials_directory; |
410 | char *received_encrypted_credentials_directory; | |
8dd4c05b | 411 | |
beb4ae87 | 412 | char *confirm_spawn; |
154eb43f | 413 | bool shall_confirm_spawn; |
7d5ceb64 | 414 | |
9fa95f85 | 415 | usec_t watchdog_usec; |
8dd4c05b | 416 | |
9fa95f85 | 417 | int *idle_pipe; |
8dd4c05b | 418 | |
a34ceba6 LP |
419 | int stdin_fd; |
420 | int stdout_fd; | |
421 | int stderr_fd; | |
5686391b | 422 | |
3c1d1ca1 | 423 | /* An fd that is closed by the execve(), and thus will result in EOF when the execve() is done. */ |
5686391b | 424 | int exec_fd; |
3bdc25a4 | 425 | |
beb4ae87 | 426 | char *notify_socket; |
cd48e23f RP |
427 | |
428 | LIST_HEAD(OpenFile, open_files); | |
154eb43f | 429 | |
beb4ae87 | 430 | char *fallback_smack_process_label; |
154eb43f LB |
431 | |
432 | char **files_env; | |
433 | int user_lookup_fd; | |
12001b1b | 434 | int handoff_timestamp_fd; |
406f1775 | 435 | int pidref_transport_fd; |
352ec23c LP |
436 | |
437 | int bpf_restrict_fs_map_fd; | |
b646fc32 LB |
438 | |
439 | /* Used for logging in the executor functions */ | |
440 | char *unit_id; | |
441 | sd_id128_t invocation_id; | |
442 | char invocation_id_string[SD_ID128_STRING_MAX]; | |
7d8bbfbe LB |
443 | |
444 | bool debug_invocation; | |
836e4e7e | 445 | } ExecParameters; |
9fa95f85 | 446 | |
352ec23c LP |
447 | #define EXEC_PARAMETERS_INIT(_flags) \ |
448 | (ExecParameters) { \ | |
449 | .flags = (_flags), \ | |
450 | .stdin_fd = -EBADF, \ | |
451 | .stdout_fd = -EBADF, \ | |
452 | .stderr_fd = -EBADF, \ | |
453 | .exec_fd = -EBADF, \ | |
454 | .bpf_restrict_fs_map_fd = -EBADF, \ | |
455 | .user_lookup_fd = -EBADF, \ | |
12001b1b | 456 | .handoff_timestamp_fd = -EBADF, \ |
406f1775 | 457 | .pidref_transport_fd = -EBADF, \ |
352ec23c | 458 | } |
b646fc32 | 459 | |
dddc0602 MY |
460 | int exec_spawn( |
461 | Unit *unit, | |
462 | ExecCommand *command, | |
463 | const ExecContext *context, | |
464 | ExecParameters *exec_params, | |
465 | ExecRuntime *runtime, | |
466 | const CGroupContext *cgroup_context, | |
467 | PidRef *ret); | |
5cb5a6ff | 468 | |
bb5232b6 | 469 | void exec_command_done(ExecCommand *c); |
da6053d0 | 470 | void exec_command_done_array(ExecCommand *c, size_t n); |
f09604b0 MY |
471 | ExecCommand* exec_command_free(ExecCommand *c); |
472 | DEFINE_TRIVIAL_CLEANUP_FUNC(ExecCommand*, exec_command_free); | |
f1acf85a | 473 | ExecCommand* exec_command_free_list(ExecCommand *c); |
da6053d0 | 474 | void exec_command_free_array(ExecCommand **c, size_t n); |
6a1d4d9f LP |
475 | void exec_command_reset_status_array(ExecCommand *c, size_t n); |
476 | void exec_command_reset_status_list_array(ExecCommand **c, size_t n); | |
f09604b0 | 477 | |
b9e4d9ba | 478 | void exec_command_dump(ExecCommand *c, FILE *f, const char *prefix); |
44d8db9e | 479 | void exec_command_dump_list(ExecCommand *c, FILE *f, const char *prefix); |
a6a80b4f | 480 | void exec_command_append_list(ExecCommand **l, ExecCommand *e); |
7593c3ec LP |
481 | int exec_command_set(ExecCommand *c, const char *path, ...) _sentinel_; |
482 | int exec_command_append(ExecCommand *c, const char *path, ...) _sentinel_; | |
44d8db9e | 483 | |
034c6ed7 | 484 | void exec_context_init(ExecContext *c); |
613b411c | 485 | void exec_context_done(ExecContext *c); |
34cf6c43 | 486 | void exec_context_dump(const ExecContext *c, FILE* f, const char *prefix); |
5cb5a6ff | 487 | |
34cf6c43 | 488 | int exec_context_destroy_runtime_directory(const ExecContext *c, const char *runtime_root); |
b9f976fb | 489 | int exec_context_destroy_mount_ns_dir(Unit *u); |
e66cf1a3 | 490 | |
52c239d7 | 491 | const char* exec_context_fdname(const ExecContext *c, int fd_index); |
8c7be95e | 492 | |
34cf6c43 YW |
493 | bool exec_context_may_touch_console(const ExecContext *c); |
494 | bool exec_context_maintains_privileges(const ExecContext *c); | |
5b3eaf9e | 495 | bool exec_context_shall_ansi_seq_reset(const ExecContext *c); |
6ac8fdc9 | 496 | |
34cf6c43 | 497 | int exec_context_get_effective_ioprio(const ExecContext *c); |
5e98086d | 498 | bool exec_context_get_effective_mount_apivfs(const ExecContext *c); |
7a9f0125 | 499 | bool exec_context_get_effective_bind_log_sockets(const ExecContext *c); |
7f452159 | 500 | |
d3070fbd LP |
501 | void exec_context_free_log_extra_fields(ExecContext *c); |
502 | ||
bbdad5c0 | 503 | void exec_context_revert_tty(ExecContext *c, sd_id128_t invocation_id); |
6f765baf | 504 | |
4c2f5842 LP |
505 | int exec_context_get_clean_directories(ExecContext *c, char **prefix, ExecCleanMask mask, char ***ret); |
506 | int exec_context_get_clean_mask(ExecContext *c, ExecCleanMask *ret); | |
507 | ||
bfd5a068 | 508 | const char* exec_context_tty_path(const ExecContext *context); |
3f2e8e95 | 509 | int exec_context_apply_tty_size(const ExecContext *context, int input_fd, int output_fd, const char *tty_path); |
6333b3b8 | 510 | void exec_context_tty_reset(const ExecContext *context, const ExecParameters *parameters, sd_id128_t invocation_id); |
75689fb2 | 511 | |
ef44aa83 DDM |
512 | uint64_t exec_context_get_rlimit(const ExecContext *c, const char *name); |
513 | int exec_context_get_oom_score_adjust(const ExecContext *c); | |
514 | uint64_t exec_context_get_coredump_filter(const ExecContext *c); | |
515 | int exec_context_get_nice(const ExecContext *c); | |
516 | int exec_context_get_cpu_sched_policy(const ExecContext *c); | |
517 | int exec_context_get_cpu_sched_priority(const ExecContext *c); | |
518 | uint64_t exec_context_get_timer_slack_nsec(const ExecContext *c); | |
d1a5be82 | 519 | bool exec_context_get_set_login_environment(const ExecContext *c); |
ef44aa83 DDM |
520 | char** exec_context_get_syscall_filter(const ExecContext *c); |
521 | char** exec_context_get_syscall_archs(const ExecContext *c); | |
522 | char** exec_context_get_syscall_log(const ExecContext *c); | |
523 | char** exec_context_get_address_families(const ExecContext *c); | |
524 | char** exec_context_get_restrict_filesystems(const ExecContext *c); | |
836e4e7e DDM |
525 | bool exec_context_restrict_namespaces_set(const ExecContext *c); |
526 | bool exec_context_restrict_filesystems_set(const ExecContext *c); | |
527 | bool exec_context_with_rootfs(const ExecContext *c); | |
ef44aa83 | 528 | |
dfdeb0b1 | 529 | int exec_context_has_vpicked_extensions(const ExecContext *context); |
530 | ||
7e0e6b50 | 531 | void exec_status_start(ExecStatus *s, pid_t pid, const dual_timestamp *ts); |
34cf6c43 | 532 | void exec_status_exit(ExecStatus *s, const ExecContext *context, pid_t pid, int code, int status); |
3c1d1ca1 | 533 | void exec_status_handoff(ExecStatus *s, const struct ucred *ucred, const dual_timestamp *ts); |
34cf6c43 | 534 | void exec_status_dump(const ExecStatus *s, FILE *f, const char *prefix); |
6a1d4d9f | 535 | void exec_status_reset(ExecStatus *s); |
5cb5a6ff | 536 | |
e76506b7 | 537 | int exec_shared_runtime_acquire(Manager *m, const ExecContext *c, const char *name, bool create, ExecSharedRuntime **ret); |
e52a696a DDM |
538 | ExecSharedRuntime *exec_shared_runtime_destroy(ExecSharedRuntime *r); |
539 | ExecSharedRuntime *exec_shared_runtime_unref(ExecSharedRuntime *r); | |
28135da3 | 540 | DEFINE_TRIVIAL_CLEANUP_FUNC(ExecSharedRuntime*, exec_shared_runtime_unref); |
613b411c | 541 | |
e76506b7 DDM |
542 | int exec_shared_runtime_serialize(const Manager *m, FILE *f, FDSet *fds); |
543 | int exec_shared_runtime_deserialize_compat(Unit *u, const char *key, const char *value, FDSet *fds); | |
544 | int exec_shared_runtime_deserialize_one(Manager *m, const char *value, FDSet *fds); | |
bb5232b6 | 545 | void exec_shared_runtime_done(ExecSharedRuntime *rt); |
e76506b7 | 546 | void exec_shared_runtime_vacuum(Manager *m); |
613b411c | 547 | |
9c0c6701 | 548 | int exec_runtime_make(const Unit *unit, const ExecContext *context, ExecSharedRuntime *shared, DynamicCreds *creds, ExecRuntime **ret); |
28135da3 DDM |
549 | ExecRuntime* exec_runtime_free(ExecRuntime *rt); |
550 | DEFINE_TRIVIAL_CLEANUP_FUNC(ExecRuntime*, exec_runtime_free); | |
551 | ExecRuntime* exec_runtime_destroy(ExecRuntime *rt); | |
bb5232b6 | 552 | void exec_runtime_clear(ExecRuntime *rt); |
28135da3 | 553 | |
f8f67eab DDM |
554 | int exec_params_needs_control_subcgroup(const ExecParameters *params); |
555 | int exec_params_get_cgroup_path(const ExecParameters *params, const CGroupContext *c, const char *prefix, char **ret); | |
fba173ff | 556 | void exec_params_shallow_clear(ExecParameters *p); |
97f53fec | 557 | void exec_params_dump(const ExecParameters *p, FILE* f, const char *prefix); |
fba173ff | 558 | void exec_params_deep_clear(ExecParameters *p); |
b9c04eaf | 559 | |
e2b2fb7f MS |
560 | bool exec_context_get_cpu_affinity_from_numa(const ExecContext *c); |
561 | ||
211a3d87 | 562 | void exec_directory_done(ExecDirectory *d); |
890bdd1d | 563 | int exec_directory_add(ExecDirectory *d, const char *path, const char *symlink, ExecDirectoryFlags flags); |
a2ab603c | 564 | void exec_directory_sort(ExecDirectory *d); |
75689fb2 | 565 | bool exec_directory_is_private(const ExecContext *context, ExecDirectoryType type); |
211a3d87 | 566 | |
4fb8f1e8 LP |
567 | ExecCleanMask exec_clean_mask_from_string(const char *s); |
568 | ||
44a6b1b6 ZJS |
569 | const char* exec_output_to_string(ExecOutput i) _const_; |
570 | ExecOutput exec_output_from_string(const char *s) _pure_; | |
94f04347 | 571 | |
44a6b1b6 ZJS |
572 | const char* exec_input_to_string(ExecInput i) _const_; |
573 | ExecInput exec_input_from_string(const char *s) _pure_; | |
023a4f67 LP |
574 | |
575 | const char* exec_utmp_mode_to_string(ExecUtmpMode i) _const_; | |
576 | ExecUtmpMode exec_utmp_mode_from_string(const char *s) _pure_; | |
53f47dfc YW |
577 | |
578 | const char* exec_preserve_mode_to_string(ExecPreserveMode i) _const_; | |
579 | ExecPreserveMode exec_preserve_mode_from_string(const char *s) _pure_; | |
3536f49e | 580 | |
b1edf445 LP |
581 | const char* exec_keyring_mode_to_string(ExecKeyringMode i) _const_; |
582 | ExecKeyringMode exec_keyring_mode_from_string(const char *s) _pure_; | |
583 | ||
3536f49e YW |
584 | const char* exec_directory_type_to_string(ExecDirectoryType i) _const_; |
585 | ExecDirectoryType exec_directory_type_from_string(const char *s) _pure_; | |
6b7b2ed9 | 586 | |
211a3d87 LB |
587 | const char* exec_directory_type_symlink_to_string(ExecDirectoryType i) _const_; |
588 | ExecDirectoryType exec_directory_type_symlink_from_string(const char *s) _pure_; | |
589 | ||
ef44aa83 DDM |
590 | const char* exec_directory_type_mode_to_string(ExecDirectoryType i) _const_; |
591 | ExecDirectoryType exec_directory_type_mode_from_string(const char *s) _pure_; | |
592 | ||
6b7b2ed9 LP |
593 | const char* exec_resource_type_to_string(ExecDirectoryType i) _const_; |
594 | ExecDirectoryType exec_resource_type_from_string(const char *s) _pure_; | |
5e8deb94 | 595 | |
28135da3 | 596 | bool exec_needs_mount_namespace(const ExecContext *context, const ExecParameters *params, const ExecRuntime *runtime); |
fbbb9697 | 597 | bool exec_needs_network_namespace(const ExecContext *context); |
75689fb2 | 598 | bool exec_needs_ipc_namespace(const ExecContext *context); |
2d8191f4 | 599 | bool exec_needs_pid_namespace(const ExecContext *context, const ExecParameters *params); |
b646fc32 | 600 | |
2b4cfbf9 MY |
601 | ProtectControlGroups exec_get_protect_control_groups(const ExecContext *context); |
602 | bool exec_needs_cgroup_namespace(const ExecContext *context); | |
603 | bool exec_needs_cgroup_mount(const ExecContext *context); | |
604 | bool exec_is_cgroup_mount_read_only(const ExecContext *context); | |
605 | ||
284dd31e | 606 | const char* exec_get_private_notify_socket_path(const ExecContext *context, const ExecParameters *params, bool needs_sandboxing); |
cd58b5a1 | 607 | |
836e4e7e | 608 | int exec_log_level_max(const ExecContext *context, const ExecParameters *params); |
44d50ba8 | 609 | |
b646fc32 LB |
610 | /* These logging macros do the same logging as those in unit.h, but using ExecContext and ExecParameters |
611 | * instead of the unit object, so that it can be used in the sd-executor context (where the unit object is | |
612 | * not available). */ | |
613 | ||
614 | #define LOG_EXEC_ID_FIELD(ep) \ | |
615 | ((ep)->runtime_scope == RUNTIME_SCOPE_USER ? "USER_UNIT=" : "UNIT=") | |
b646fc32 LB |
616 | #define LOG_EXEC_INVOCATION_ID_FIELD(ep) \ |
617 | ((ep)->runtime_scope == RUNTIME_SCOPE_USER ? "USER_INVOCATION_ID=" : "INVOCATION_ID=") | |
b646fc32 | 618 | |
de12b8d1 MY |
619 | /* Like LOG_MESSAGE(), but with the unit name prefixed. */ |
620 | #define LOG_EXEC_MESSAGE(ep, fmt, ...) LOG_MESSAGE("%s: " fmt, (ep)->unit_id, ##__VA_ARGS__) | |
3cf6a3a3 YW |
621 | #define LOG_EXEC_ID(ep) LOG_ITEM("%s%s", LOG_EXEC_ID_FIELD(ep), (ep)->unit_id) |
622 | #define LOG_EXEC_INVOCATION_ID(ep) LOG_ITEM("%s%s", LOG_EXEC_INVOCATION_ID_FIELD(ep), (ep)->invocation_id_string) | |
de12b8d1 | 623 | |
210ca71c MY |
624 | #define _LOG_CONTEXT_PUSH_EXEC(ec, ep, p, c) \ |
625 | const ExecContext *c = (ec); \ | |
626 | const ExecParameters *p = (ep); \ | |
b646fc32 | 627 | LOG_CONTEXT_PUSH_KEY_VALUE(LOG_EXEC_ID_FIELD(p), p->unit_id); \ |
210ca71c | 628 | LOG_CONTEXT_PUSH_KEY_VALUE(LOG_EXEC_INVOCATION_ID_FIELD(p), p->invocation_id_string); \ |
44d50ba8 DDM |
629 | LOG_CONTEXT_PUSH_IOV(c->log_extra_fields, c->n_log_extra_fields) \ |
630 | LOG_CONTEXT_SET_LOG_LEVEL(exec_log_level_max(c, p)) \ | |
631 | LOG_SET_PREFIX(p->unit_id); | |
b646fc32 LB |
632 | |
633 | #define LOG_CONTEXT_PUSH_EXEC(ec, ep) \ | |
634 | _LOG_CONTEXT_PUSH_EXEC(ec, ep, UNIQ_T(p, UNIQ), UNIQ_T(c, UNIQ)) |