]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
a7334b09 | 2 | /*** |
96b2fb93 | 3 | Copyright © 2012 Holger Hans Peter Freyther |
a7334b09 LP |
4 | ***/ |
5 | ||
3efd4195 | 6 | #include <errno.h> |
87f0e418 | 7 | #include <fcntl.h> |
25e870b5 | 8 | #include <linux/fs.h> |
5f5d8eab LP |
9 | #include <linux/oom.h> |
10 | #include <sched.h> | |
3d57c6ab | 11 | #include <sys/resource.h> |
3efd4195 | 12 | |
bed0b7df LP |
13 | #include "sd-messages.h" |
14 | ||
5f5d8eab | 15 | #include "af-list.h" |
57b7a260 | 16 | #include "all-units.h" |
786d19fd | 17 | #include "alloc-util.h" |
fab34748 | 18 | #include "bpf-firewall.h" |
0879da98 | 19 | #include "bpf-program.h" |
169b5675 | 20 | #include "bpf-restrict-fs.h" |
cd09a5f3 | 21 | #include "bpf-socket-bind.h" |
5f5d8eab LP |
22 | #include "bus-error.h" |
23 | #include "bus-internal.h" | |
24 | #include "bus-util.h" | |
25 | #include "cap-list.h" | |
a103496c | 26 | #include "capability-util.h" |
fdb3deca | 27 | #include "cgroup-setup.h" |
3efd4195 | 28 | #include "conf-parser.h" |
e30bbc90 | 29 | #include "core-varlink.h" |
618234a5 | 30 | #include "cpu-set-util.h" |
786d19fd | 31 | #include "creds-util.h" |
5f5d8eab LP |
32 | #include "env-util.h" |
33 | #include "errno-list.h" | |
4f5dd394 | 34 | #include "escape.h" |
43962c30 | 35 | #include "exec-credential.h" |
dc7d69b3 | 36 | #include "execute.h" |
3ffd4af2 | 37 | #include "fd-util.h" |
0389f4fa | 38 | #include "fileio.h" |
dc7d69b3 | 39 | #include "firewall-util.h" |
f4f15635 | 40 | #include "fs-util.h" |
435e1098 | 41 | #include "fstab-util.h" |
08f3be7a | 42 | #include "hexdecoct.h" |
bd1ae178 | 43 | #include "iovec-util.h" |
032b3afb | 44 | #include "ioprio-util.h" |
da96ad5a | 45 | #include "ip-protocol-list.h" |
adce225a | 46 | #include "journal-file.h" |
eefc66aa | 47 | #include "limits-util.h" |
3ffd4af2 | 48 | #include "load-fragment.h" |
5f5d8eab | 49 | #include "log.h" |
5bead76e | 50 | #include "missing_ioprio.h" |
049af8ad | 51 | #include "mountpoint-util.h" |
d8b4d14d | 52 | #include "nulstr-util.h" |
cd48e23f | 53 | #include "open-file.h" |
c3eaba2d | 54 | #include "parse-helpers.h" |
6bedfcbb | 55 | #include "parse-util.h" |
9eb977db | 56 | #include "path-util.h" |
523ea123 | 57 | #include "pcre2-util.h" |
ed5033fd | 58 | #include "percent-util.h" |
7b3e062c | 59 | #include "process-util.h" |
57183d11 | 60 | #include "seccomp-util.h" |
07d46372 | 61 | #include "securebits-util.h" |
23e9a7dd | 62 | #include "selinux-util.h" |
5f5d8eab | 63 | #include "signal-util.h" |
5c3fa98d | 64 | #include "socket-netlink.h" |
46a9ee5d | 65 | #include "specifier.h" |
8fcde012 | 66 | #include "stat-util.h" |
07630cea | 67 | #include "string-util.h" |
5f5d8eab | 68 | #include "strv.h" |
91dd5f7c LP |
69 | #include "syslog-util.h" |
70 | #include "time-util.h" | |
5f5d8eab LP |
71 | #include "unit-name.h" |
72 | #include "unit-printf.h" | |
66dccd8d | 73 | #include "user-util.h" |
bb0c0d6f | 74 | #include "utf8.h" |
49cf4170 | 75 | #include "web-util.h" |
57183d11 | 76 | |
d2b42d63 | 77 | static int parse_socket_protocol(const char *s) { |
53577580 YW |
78 | int r; |
79 | ||
d2b42d63 | 80 | r = parse_ip_protocol(s); |
53577580 | 81 | if (r < 0) |
acf4d158 | 82 | return r; |
53577580 YW |
83 | if (!IN_SET(r, IPPROTO_UDPLITE, IPPROTO_SCTP)) |
84 | return -EPROTONOSUPPORT; | |
85 | ||
86 | return r; | |
87 | } | |
88 | ||
a07a7324 FS |
89 | int parse_crash_chvt(const char *value, int *data) { |
90 | int b; | |
91 | ||
92 | if (safe_atoi(value, data) >= 0) | |
93 | return 0; | |
94 | ||
95 | b = parse_boolean(value); | |
96 | if (b < 0) | |
97 | return b; | |
98 | ||
99 | if (b > 0) | |
100 | *data = 0; /* switch to where kmsg goes */ | |
101 | else | |
102 | *data = -1; /* turn off switching */ | |
103 | ||
104 | return 0; | |
105 | } | |
106 | ||
107 | int parse_confirm_spawn(const char *value, char **console) { | |
108 | char *s; | |
109 | int r; | |
110 | ||
111 | r = value ? parse_boolean(value) : 1; | |
112 | if (r == 0) { | |
113 | *console = NULL; | |
114 | return 0; | |
4a8daee7 | 115 | } else if (r > 0) /* on with default tty */ |
a07a7324 FS |
116 | s = strdup("/dev/console"); |
117 | else if (is_path(value)) /* on with fully qualified path */ | |
118 | s = strdup(value); | |
119 | else /* on with only a tty file name, not a fully qualified path */ | |
4a8daee7 | 120 | s = path_join("/dev/", value); |
a07a7324 FS |
121 | if (!s) |
122 | return -ENOMEM; | |
123 | ||
124 | *console = s; | |
125 | return 0; | |
126 | } | |
127 | ||
d2b42d63 | 128 | DEFINE_CONFIG_PARSE(config_parse_socket_protocol, parse_socket_protocol, "Failed to parse socket protocol"); |
53577580 | 129 | DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits, secure_bits_from_string, "Failed to parse secure bits"); |
5afe510c | 130 | DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode, collect_mode, CollectMode, "Failed to parse garbage collection mode"); |
53577580 | 131 | DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy, cgroup_device_policy, CGroupDevicePolicy, "Failed to parse device policy"); |
53577580 | 132 | DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode, exec_keyring_mode, ExecKeyringMode, "Failed to parse keyring mode"); |
4e399953 LP |
133 | DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_proc, protect_proc, ProtectProc, "Failed to parse /proc/ protection mode"); |
134 | DEFINE_CONFIG_PARSE_ENUM(config_parse_proc_subset, proc_subset, ProcSubset, "Failed to parse /proc/ subset mode"); | |
53577580 YW |
135 | DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode, exec_utmp_mode, ExecUtmpMode, "Failed to parse utmp mode"); |
136 | DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode, job_mode, JobMode, "Failed to parse job mode"); | |
53577580 | 137 | DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access, notify_access, NotifyAccess, "Failed to parse notify access specifier"); |
1e8c7bd5 YW |
138 | DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home, protect_home, ProtectHome, "Failed to parse protect home value"); |
139 | DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system, protect_system, ProtectSystem, "Failed to parse protect system value"); | |
b9c1883a | 140 | DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_preserve_mode, exec_preserve_mode, ExecPreserveMode, "Failed to parse resource preserve mode"); |
53577580 | 141 | DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type, service_type, ServiceType, "Failed to parse service type"); |
596e4470 | 142 | DEFINE_CONFIG_PARSE_ENUM(config_parse_service_exit_type, service_exit_type, ServiceExitType, "Failed to parse service exit type"); |
53577580 | 143 | DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart, service_restart, ServiceRestart, "Failed to parse service restart specifier"); |
e568fea9 | 144 | DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart_mode, service_restart_mode, ServiceRestartMode, "Failed to parse service restart mode"); |
bf760801 | 145 | DEFINE_CONFIG_PARSE_ENUM(config_parse_service_timeout_failure_mode, service_timeout_failure_mode, ServiceTimeoutFailureMode, "Failed to parse timeout failure mode"); |
53577580 | 146 | DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind, socket_address_bind_ipv6_only_or_bool, SocketAddressBindIPv6Only, "Failed to parse bind IPv6 only value"); |
afcfaa69 | 147 | DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy, oom_policy, OOMPolicy, "Failed to parse OOM policy"); |
4e806bfa | 148 | DEFINE_CONFIG_PARSE_ENUM(config_parse_managed_oom_preference, managed_oom_preference, ManagedOOMPreference, "Failed to parse ManagedOOMPreference="); |
054749e4 | 149 | DEFINE_CONFIG_PARSE_ENUM(config_parse_memory_pressure_watch, cgroup_pressure_watch, CGroupPressureWatch, "Failed to parse memory pressure watch setting"); |
53577580 YW |
150 | DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos, ip_tos, int, -1, "Failed to parse IP TOS value"); |
151 | DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight, cg_blkio_weight_parse, uint64_t, "Invalid block IO weight"); | |
152 | DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight, cg_weight_parse, uint64_t, "Invalid weight"); | |
c8340822 | 153 | DEFINE_CONFIG_PARSE_PTR(config_parse_cg_cpu_weight, cg_cpu_weight_parse, uint64_t, "Invalid CPU weight"); |
c1e701e2 | 154 | static DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares_internal, cg_cpu_shares_parse, uint64_t, "Invalid CPU shares"); |
874cdcbc | 155 | DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_propagation_flag, mount_propagation_flag_from_string, unsigned long, "Failed to parse mount propagation flag"); |
b070c7c0 | 156 | DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy, mpol, int, -1, "Invalid NUMA policy type"); |
6327aa9f | 157 | DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format, status_unit_format, StatusUnitFormat, "Failed to parse status unit format"); |
9b191525 | 158 | DEFINE_CONFIG_PARSE_ENUM_FULL(config_parse_socket_timestamping, socket_timestamping_from_string_harder, SocketTimestamping, "Failed to parse timestamping precision"); |
5afe510c | 159 | |
c1e701e2 LP |
160 | int config_parse_cpu_shares( |
161 | const char *unit, | |
162 | const char *filename, | |
163 | unsigned line, | |
164 | const char *section, | |
165 | unsigned section_line, | |
166 | const char *lvalue, | |
167 | int ltype, | |
168 | const char *rvalue, | |
169 | void *data, | |
170 | void *userdata) { | |
171 | ||
172 | assert(filename); | |
173 | assert(lvalue); | |
174 | assert(rvalue); | |
175 | ||
176 | ||
177 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
178 | "Unit uses %s=; please use CPUWeight= instead. Support for %s= will be removed soon.", | |
179 | lvalue, lvalue); | |
180 | ||
181 | return config_parse_cpu_shares_internal(unit, filename, line, section, section_line, lvalue, ltype, rvalue, data, userdata); | |
182 | } | |
183 | ||
88022148 DDM |
184 | bool contains_instance_specifier_superset(const char *s) { |
185 | const char *p, *q; | |
186 | bool percent = false; | |
187 | ||
188 | assert(s); | |
189 | ||
190 | p = strchr(s, '@'); | |
191 | if (!p) | |
192 | return false; | |
193 | ||
194 | p++; /* Skip '@' */ | |
195 | ||
196 | q = strrchr(p, '.'); | |
197 | if (!q) | |
198 | q = p + strlen(p); | |
199 | ||
200 | /* If the string is just the instance specifier, it's not a superset of the instance. */ | |
201 | if (memcmp_nn(p, q - p, "%i", strlen("%i")) == 0) | |
202 | return false; | |
203 | ||
204 | /* %i, %n and %N all expand to the instance or a superset of it. */ | |
24aaf6c6 | 205 | for (; p < q; p++) |
88022148 DDM |
206 | if (*p == '%') |
207 | percent = !percent; | |
208 | else if (percent) { | |
209 | if (IN_SET(*p, 'n', 'N', 'i')) | |
210 | return true; | |
211 | percent = false; | |
212 | } | |
88022148 DDM |
213 | |
214 | return false; | |
215 | } | |
216 | ||
217 | /* `name` is the rendered version of `format` via `unit_printf` or similar functions. */ | |
218 | int unit_is_likely_recursive_template_dependency(Unit *u, const char *name, const char *format) { | |
219 | const char *fragment_path; | |
220 | int r; | |
221 | ||
222 | assert(u); | |
223 | assert(name); | |
224 | ||
225 | /* If a template unit has a direct dependency on itself that includes the unit instance as part of | |
226 | * the template instance via a unit specifier (%i, %n or %N), this will almost certainly lead to | |
227 | * infinite recursion as systemd will keep instantiating new instances of the template unit. | |
228 | * https://github.com/systemd/systemd/issues/17602 shows a good example of how this can happen in | |
229 | * practice. To guard against this, we check for templates that depend on themselves and have the | |
230 | * instantiated unit instance included as part of the template instance of the dependency via a | |
231 | * specifier. | |
232 | * | |
233 | * For example, if systemd-notify@.service depends on systemd-notify@%n.service, this will result in | |
234 | * infinite recursion. | |
235 | */ | |
236 | ||
237 | if (!unit_name_is_valid(name, UNIT_NAME_INSTANCE)) | |
238 | return false; | |
239 | ||
240 | if (!unit_name_prefix_equal(u->id, name)) | |
241 | return false; | |
242 | ||
243 | if (u->type != unit_name_to_type(name)) | |
244 | return false; | |
245 | ||
246 | r = unit_file_find_fragment(u->manager->unit_id_map, u->manager->unit_name_map, name, &fragment_path, NULL); | |
247 | if (r < 0) | |
248 | return r; | |
249 | ||
250 | /* Fragment paths should also be equal as a custom fragment for a specific template instance | |
251 | * wouldn't necessarily lead to infinite recursion. */ | |
252 | if (!path_equal_ptr(u->fragment_path, fragment_path)) | |
253 | return false; | |
254 | ||
255 | if (!contains_instance_specifier_superset(format)) | |
256 | return false; | |
257 | ||
258 | return true; | |
259 | } | |
260 | ||
f32b43bd LP |
261 | int config_parse_unit_deps( |
262 | const char *unit, | |
263 | const char *filename, | |
264 | unsigned line, | |
265 | const char *section, | |
266 | unsigned section_line, | |
267 | const char *lvalue, | |
268 | int ltype, | |
269 | const char *rvalue, | |
270 | void *data, | |
271 | void *userdata) { | |
3efd4195 | 272 | |
f975e971 | 273 | UnitDependency d = ltype; |
87f0e418 | 274 | Unit *u = userdata; |
3efd4195 LP |
275 | |
276 | assert(filename); | |
277 | assert(lvalue); | |
278 | assert(rvalue); | |
3efd4195 | 279 | |
323dda78 | 280 | for (const char *p = rvalue;;) { |
3d793d29 | 281 | _cleanup_free_ char *word = NULL, *k = NULL; |
3efd4195 | 282 | int r; |
3efd4195 | 283 | |
c89f52ac | 284 | r = extract_first_word(&p, &word, NULL, EXTRACT_RETAIN_ESCAPE); |
3d793d29 | 285 | if (r == 0) |
323dda78 | 286 | return 0; |
3d793d29 | 287 | if (r == -ENOMEM) |
74051b9b | 288 | return log_oom(); |
3d793d29 | 289 | if (r < 0) { |
323dda78 YW |
290 | log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue); |
291 | return 0; | |
3d793d29 | 292 | } |
3efd4195 | 293 | |
3d793d29 | 294 | r = unit_name_printf(u, word, &k); |
19f6d710 | 295 | if (r < 0) { |
323dda78 | 296 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", word); |
19f6d710 LP |
297 | continue; |
298 | } | |
9e2f7c11 | 299 | |
88022148 DDM |
300 | r = unit_is_likely_recursive_template_dependency(u, k, word); |
301 | if (r < 0) { | |
302 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to determine if '%s' is a recursive dependency, ignoring: %m", k); | |
303 | continue; | |
304 | } | |
305 | if (r > 0) { | |
306 | log_syntax(unit, LOG_DEBUG, filename, line, 0, | |
307 | "Dropping dependency %s=%s that likely leads to infinite recursion.", | |
308 | unit_dependency_to_string(d), word); | |
309 | continue; | |
310 | } | |
311 | ||
35d8c19a | 312 | r = unit_add_dependency_by_name(u, d, k, true, UNIT_DEPENDENCY_FILE); |
57020a3a | 313 | if (r < 0) |
323dda78 | 314 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to add dependency on %s, ignoring: %m", k); |
3efd4195 | 315 | } |
3efd4195 LP |
316 | } |
317 | ||
f32b43bd LP |
318 | int config_parse_obsolete_unit_deps( |
319 | const char *unit, | |
320 | const char *filename, | |
321 | unsigned line, | |
322 | const char *section, | |
323 | unsigned section_line, | |
324 | const char *lvalue, | |
325 | int ltype, | |
326 | const char *rvalue, | |
327 | void *data, | |
328 | void *userdata) { | |
329 | ||
330 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
331 | "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue, unit_dependency_to_string(ltype)); | |
332 | ||
333 | return config_parse_unit_deps(unit, filename, line, section, section_line, lvalue, ltype, rvalue, data, userdata); | |
334 | } | |
335 | ||
b02cb41c LP |
336 | int config_parse_unit_string_printf( |
337 | const char *unit, | |
338 | const char *filename, | |
339 | unsigned line, | |
340 | const char *section, | |
341 | unsigned section_line, | |
342 | const char *lvalue, | |
343 | int ltype, | |
344 | const char *rvalue, | |
345 | void *data, | |
346 | void *userdata) { | |
932921b5 | 347 | |
74051b9b | 348 | _cleanup_free_ char *k = NULL; |
99534007 | 349 | const Unit *u = ASSERT_PTR(userdata); |
19f6d710 | 350 | int r; |
932921b5 LP |
351 | |
352 | assert(filename); | |
353 | assert(lvalue); | |
354 | assert(rvalue); | |
932921b5 | 355 | |
19f6d710 | 356 | r = unit_full_printf(u, rvalue, &k); |
b02cb41c | 357 | if (r < 0) { |
323dda78 | 358 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
b02cb41c LP |
359 | return 0; |
360 | } | |
932921b5 | 361 | |
b02cb41c | 362 | return config_parse_string(unit, filename, line, section, section_line, lvalue, ltype, k, data, userdata); |
932921b5 LP |
363 | } |
364 | ||
12ca818f LP |
365 | int config_parse_unit_strv_printf( |
366 | const char *unit, | |
367 | const char *filename, | |
368 | unsigned line, | |
369 | const char *section, | |
370 | unsigned section_line, | |
371 | const char *lvalue, | |
372 | int ltype, | |
373 | const char *rvalue, | |
374 | void *data, | |
375 | void *userdata) { | |
8fef7659 | 376 | |
99534007 | 377 | const Unit *u = ASSERT_PTR(userdata); |
74051b9b | 378 | _cleanup_free_ char *k = NULL; |
19f6d710 | 379 | int r; |
8fef7659 LP |
380 | |
381 | assert(filename); | |
382 | assert(lvalue); | |
383 | assert(rvalue); | |
8fef7659 | 384 | |
19f6d710 | 385 | r = unit_full_printf(u, rvalue, &k); |
12ca818f | 386 | if (r < 0) { |
323dda78 | 387 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
12ca818f LP |
388 | return 0; |
389 | } | |
8fef7659 | 390 | |
12ca818f | 391 | return config_parse_strv(unit, filename, line, section, section_line, lvalue, ltype, k, data, userdata); |
8fef7659 LP |
392 | } |
393 | ||
5f5d8eab LP |
394 | int config_parse_unit_path_printf( |
395 | const char *unit, | |
396 | const char *filename, | |
397 | unsigned line, | |
398 | const char *section, | |
399 | unsigned section_line, | |
400 | const char *lvalue, | |
401 | int ltype, | |
402 | const char *rvalue, | |
403 | void *data, | |
404 | void *userdata) { | |
6ea832a2 | 405 | |
74051b9b | 406 | _cleanup_free_ char *k = NULL; |
99534007 | 407 | const Unit *u = ASSERT_PTR(userdata); |
19f6d710 | 408 | int r; |
2c75fb73 | 409 | bool fatal = ltype; |
6ea832a2 LP |
410 | |
411 | assert(filename); | |
412 | assert(lvalue); | |
413 | assert(rvalue); | |
6ea832a2 | 414 | |
06536492 | 415 | r = unit_path_printf(u, rvalue, &k); |
811ba7a0 | 416 | if (r < 0) { |
323dda78 | 417 | log_syntax(unit, fatal ? LOG_ERR : LOG_WARNING, filename, line, r, |
063c4b1a | 418 | "Failed to resolve unit specifiers in '%s'%s: %m", |
e3c3d676 | 419 | rvalue, fatal ? "" : ", ignoring"); |
2c75fb73 | 420 | return fatal ? -ENOEXEC : 0; |
811ba7a0 | 421 | } |
6ea832a2 | 422 | |
811ba7a0 LP |
423 | return config_parse_path(unit, filename, line, section, section_line, lvalue, ltype, k, data, userdata); |
424 | } | |
425 | ||
8c35c10d | 426 | int config_parse_colon_separated_paths( |
427 | const char *unit, | |
428 | const char *filename, | |
429 | unsigned line, | |
430 | const char *section, | |
431 | unsigned section_line, | |
432 | const char *lvalue, | |
433 | int ltype, | |
434 | const char *rvalue, | |
435 | void *data, | |
436 | void *userdata) { | |
99534007 | 437 | char ***sv = ASSERT_PTR(data); |
8c35c10d | 438 | const Unit *u = userdata; |
439 | int r; | |
440 | ||
441 | assert(filename); | |
442 | assert(lvalue); | |
443 | assert(rvalue); | |
8c35c10d | 444 | |
445 | if (isempty(rvalue)) { | |
446 | /* Empty assignment resets the list */ | |
447 | *sv = strv_free(*sv); | |
448 | return 0; | |
449 | } | |
450 | ||
451 | for (const char *p = rvalue;;) { | |
452 | _cleanup_free_ char *word = NULL, *k = NULL; | |
453 | ||
454 | r = extract_first_word(&p, &word, ":", EXTRACT_DONT_COALESCE_SEPARATORS); | |
455 | if (r == -ENOMEM) | |
456 | return log_oom(); | |
457 | if (r < 0) { | |
458 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to extract first word, ignoring: %s", rvalue); | |
459 | return 0; | |
460 | } | |
461 | if (r == 0) | |
462 | break; | |
463 | ||
464 | r = unit_path_printf(u, word, &k); | |
465 | if (r < 0) { | |
466 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
467 | "Failed to resolve unit specifiers in '%s', ignoring: %m", word); | |
468 | return 0; | |
469 | } | |
470 | ||
471 | r = path_simplify_and_warn(k, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); | |
472 | if (r < 0) | |
473 | return 0; | |
474 | ||
475 | r = strv_consume(sv, TAKE_PTR(k)); | |
476 | if (r < 0) | |
477 | return log_oom(); | |
478 | } | |
479 | ||
480 | return 0; | |
481 | } | |
482 | ||
811ba7a0 LP |
483 | int config_parse_unit_path_strv_printf( |
484 | const char *unit, | |
485 | const char *filename, | |
486 | unsigned line, | |
487 | const char *section, | |
488 | unsigned section_line, | |
489 | const char *lvalue, | |
490 | int ltype, | |
491 | const char *rvalue, | |
492 | void *data, | |
493 | void *userdata) { | |
494 | ||
a2a5291b | 495 | char ***x = data; |
99534007 | 496 | const Unit *u = ASSERT_PTR(userdata); |
811ba7a0 LP |
497 | int r; |
498 | ||
499 | assert(filename); | |
500 | assert(lvalue); | |
501 | assert(rvalue); | |
811ba7a0 | 502 | |
499295fb | 503 | if (isempty(rvalue)) { |
9f2d41a6 | 504 | *x = strv_free(*x); |
499295fb YW |
505 | return 0; |
506 | } | |
507 | ||
323dda78 | 508 | for (const char *p = rvalue;;) { |
035fe294 | 509 | _cleanup_free_ char *word = NULL, *k = NULL; |
811ba7a0 | 510 | |
4ec85141 | 511 | r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); |
035fe294 ZJS |
512 | if (r == 0) |
513 | return 0; | |
514 | if (r == -ENOMEM) | |
515 | return log_oom(); | |
516 | if (r < 0) { | |
517 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
518 | "Invalid syntax, ignoring: %s", rvalue); | |
519 | return 0; | |
520 | } | |
811ba7a0 | 521 | |
06536492 | 522 | r = unit_path_printf(u, word, &k); |
811ba7a0 | 523 | if (r < 0) { |
323dda78 | 524 | log_syntax(unit, LOG_WARNING, filename, line, r, |
063c4b1a | 525 | "Failed to resolve unit specifiers in '%s', ignoring: %m", word); |
811ba7a0 LP |
526 | return 0; |
527 | } | |
528 | ||
2f4d31c1 YW |
529 | r = path_simplify_and_warn(k, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
530 | if (r < 0) | |
811ba7a0 | 531 | return 0; |
811ba7a0 | 532 | |
7d2c9c6b | 533 | r = strv_consume(x, TAKE_PTR(k)); |
811ba7a0 LP |
534 | if (r < 0) |
535 | return log_oom(); | |
811ba7a0 | 536 | } |
6ea832a2 LP |
537 | } |
538 | ||
4a66b5c9 LP |
539 | static int patch_var_run( |
540 | const char *unit, | |
541 | const char *filename, | |
542 | unsigned line, | |
543 | const char *lvalue, | |
544 | char **path) { | |
545 | ||
546 | const char *e; | |
547 | char *z; | |
548 | ||
549 | e = path_startswith(*path, "/var/run/"); | |
550 | if (!e) | |
551 | return 0; | |
552 | ||
553 | z = path_join("/run/", e); | |
554 | if (!z) | |
555 | return log_oom(); | |
556 | ||
557 | log_syntax(unit, LOG_NOTICE, filename, line, 0, | |
558 | "%s= references a path below legacy directory /var/run/, updating %s → %s; " | |
559 | "please update the unit file accordingly.", lvalue, *path, z); | |
560 | ||
561 | free_and_replace(*path, z); | |
562 | ||
563 | return 1; | |
564 | } | |
565 | ||
566 | int config_parse_socket_listen( | |
567 | const char *unit, | |
568 | const char *filename, | |
569 | unsigned line, | |
570 | const char *section, | |
571 | unsigned section_line, | |
572 | const char *lvalue, | |
573 | int ltype, | |
574 | const char *rvalue, | |
575 | void *data, | |
576 | void *userdata) { | |
42f4e3c4 | 577 | |
b1389b0d ZJS |
578 | _cleanup_free_ SocketPort *p = NULL; |
579 | SocketPort *tail; | |
542563ba | 580 | Socket *s; |
19f6d710 | 581 | int r; |
16354eff | 582 | |
42f4e3c4 LP |
583 | assert(filename); |
584 | assert(lvalue); | |
585 | assert(rvalue); | |
586 | assert(data); | |
587 | ||
595ed347 | 588 | s = SOCKET(data); |
542563ba | 589 | |
74051b9b LP |
590 | if (isempty(rvalue)) { |
591 | /* An empty assignment removes all ports */ | |
592 | socket_free_ports(s); | |
593 | return 0; | |
594 | } | |
595 | ||
7f110ff9 LP |
596 | p = new0(SocketPort, 1); |
597 | if (!p) | |
74051b9b | 598 | return log_oom(); |
916abb21 | 599 | |
74051b9b | 600 | if (ltype != SOCKET_SOCKET) { |
2f4d31c1 | 601 | _cleanup_free_ char *k = NULL; |
916abb21 | 602 | |
06536492 | 603 | r = unit_path_printf(UNIT(s), rvalue, &k); |
19f6d710 | 604 | if (r < 0) { |
323dda78 | 605 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
12ca818f | 606 | return 0; |
916abb21 LP |
607 | } |
608 | ||
2f4d31c1 YW |
609 | r = path_simplify_and_warn(k, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
610 | if (r < 0) | |
611 | return 0; | |
612 | ||
4a66b5c9 LP |
613 | if (ltype == SOCKET_FIFO) { |
614 | r = patch_var_run(unit, filename, line, lvalue, &k); | |
615 | if (r < 0) | |
616 | return r; | |
617 | } | |
618 | ||
2f4d31c1 YW |
619 | free_and_replace(p->path, k); |
620 | p->type = ltype; | |
916abb21 | 621 | |
7a22745a | 622 | } else if (streq(lvalue, "ListenNetlink")) { |
74051b9b | 623 | _cleanup_free_ char *k = NULL; |
1fd45a90 | 624 | |
06536492 | 625 | r = unit_path_printf(UNIT(s), rvalue, &k); |
12ca818f | 626 | if (r < 0) { |
323dda78 | 627 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
12ca818f LP |
628 | return 0; |
629 | } | |
7a22745a | 630 | |
12ca818f | 631 | r = socket_address_parse_netlink(&p->address, k); |
1fd45a90 | 632 | if (r < 0) { |
323dda78 | 633 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse address value in '%s', ignoring: %m", k); |
7a22745a LP |
634 | return 0; |
635 | } | |
636 | ||
2f4d31c1 YW |
637 | p->type = SOCKET_SOCKET; |
638 | ||
542563ba | 639 | } else { |
74051b9b | 640 | _cleanup_free_ char *k = NULL; |
1fd45a90 | 641 | |
06536492 | 642 | r = unit_path_printf(UNIT(s), rvalue, &k); |
12ca818f | 643 | if (r < 0) { |
323dda78 | 644 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
12ca818f LP |
645 | return 0; |
646 | } | |
542563ba | 647 | |
4a66b5c9 LP |
648 | if (k[0] == '/') { /* Only for AF_UNIX file system sockets… */ |
649 | r = patch_var_run(unit, filename, line, lvalue, &k); | |
650 | if (r < 0) | |
651 | return r; | |
652 | } | |
653 | ||
12ca818f | 654 | r = socket_address_parse_and_warn(&p->address, k); |
1fd45a90 | 655 | if (r < 0) { |
f847b8b7 | 656 | if (r != -EAFNOSUPPORT) |
323dda78 | 657 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse address value in '%s', ignoring: %m", k); |
c0b34696 | 658 | return 0; |
542563ba LP |
659 | } |
660 | ||
661 | if (streq(lvalue, "ListenStream")) | |
662 | p->address.type = SOCK_STREAM; | |
663 | else if (streq(lvalue, "ListenDatagram")) | |
664 | p->address.type = SOCK_DGRAM; | |
665 | else { | |
666 | assert(streq(lvalue, "ListenSequentialPacket")); | |
667 | p->address.type = SOCK_SEQPACKET; | |
668 | } | |
669 | ||
618b3642 | 670 | if (socket_address_family(&p->address) != AF_UNIX && p->address.type == SOCK_SEQPACKET) { |
323dda78 | 671 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Address family not supported, ignoring: %s", rvalue); |
c0b34696 | 672 | return 0; |
542563ba | 673 | } |
2f4d31c1 YW |
674 | |
675 | p->type = SOCKET_SOCKET; | |
16354eff LP |
676 | } |
677 | ||
254d1313 | 678 | p->fd = -EBADF; |
15087cdb PS |
679 | p->auxiliary_fds = NULL; |
680 | p->n_auxiliary_fds = 0; | |
2e41a51e | 681 | p->socket = s; |
49f91047 | 682 | |
cc232fa0 | 683 | tail = LIST_FIND_TAIL(port, s->ports); |
533f8a67 YW |
684 | LIST_INSERT_AFTER(port, s->ports, tail, p); |
685 | ||
b1389b0d | 686 | p = NULL; |
542563ba | 687 | |
16354eff | 688 | return 0; |
42f4e3c4 LP |
689 | } |
690 | ||
41bf0590 LP |
691 | int config_parse_exec_nice( |
692 | const char *unit, | |
693 | const char *filename, | |
694 | unsigned line, | |
695 | const char *section, | |
696 | unsigned section_line, | |
697 | const char *lvalue, | |
698 | int ltype, | |
699 | const char *rvalue, | |
700 | void *data, | |
701 | void *userdata) { | |
034c6ed7 | 702 | |
99534007 | 703 | ExecContext *c = ASSERT_PTR(data); |
e8e581bf | 704 | int priority, r; |
034c6ed7 LP |
705 | |
706 | assert(filename); | |
707 | assert(lvalue); | |
708 | assert(rvalue); | |
034c6ed7 | 709 | |
de5e6038 YW |
710 | if (isempty(rvalue)) { |
711 | c->nice_set = false; | |
712 | return 0; | |
713 | } | |
714 | ||
41bf0590 | 715 | r = parse_nice(rvalue, &priority); |
e8e581bf | 716 | if (r < 0) { |
41bf0590 | 717 | if (r == -ERANGE) |
323dda78 | 718 | log_syntax(unit, LOG_WARNING, filename, line, r, "Nice priority out of range, ignoring: %s", rvalue); |
41bf0590 | 719 | else |
323dda78 | 720 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse nice priority '%s', ignoring: %m", rvalue); |
c0b34696 | 721 | return 0; |
034c6ed7 LP |
722 | } |
723 | ||
fb33a393 | 724 | c->nice = priority; |
71155933 | 725 | c->nice_set = true; |
fb33a393 | 726 | |
034c6ed7 LP |
727 | return 0; |
728 | } | |
729 | ||
e9eb2c02 LP |
730 | int config_parse_exec_oom_score_adjust( |
731 | const char* unit, | |
732 | const char *filename, | |
733 | unsigned line, | |
734 | const char *section, | |
735 | unsigned section_line, | |
736 | const char *lvalue, | |
737 | int ltype, | |
738 | const char *rvalue, | |
739 | void *data, | |
740 | void *userdata) { | |
034c6ed7 | 741 | |
99534007 | 742 | ExecContext *c = ASSERT_PTR(data); |
e8e581bf | 743 | int oa, r; |
034c6ed7 LP |
744 | |
745 | assert(filename); | |
746 | assert(lvalue); | |
747 | assert(rvalue); | |
034c6ed7 | 748 | |
e9eb2c02 LP |
749 | if (isempty(rvalue)) { |
750 | c->oom_score_adjust_set = false; | |
c0b34696 | 751 | return 0; |
034c6ed7 LP |
752 | } |
753 | ||
e9eb2c02 | 754 | r = parse_oom_score_adjust(rvalue, &oa); |
e9eb2c02 | 755 | if (r < 0) { |
063c4b1a | 756 | if (r == -ERANGE) |
323dda78 | 757 | log_syntax(unit, LOG_WARNING, filename, line, r, "OOM score adjust value out of range, ignoring: %s", rvalue); |
063c4b1a | 758 | else |
323dda78 | 759 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue); |
c0b34696 | 760 | return 0; |
034c6ed7 LP |
761 | } |
762 | ||
dd6c17b1 LP |
763 | c->oom_score_adjust = oa; |
764 | c->oom_score_adjust_set = true; | |
fb33a393 | 765 | |
034c6ed7 LP |
766 | return 0; |
767 | } | |
768 | ||
ad21e542 ZJS |
769 | int config_parse_exec_coredump_filter( |
770 | const char* unit, | |
771 | const char *filename, | |
772 | unsigned line, | |
773 | const char *section, | |
774 | unsigned section_line, | |
775 | const char *lvalue, | |
776 | int ltype, | |
777 | const char *rvalue, | |
778 | void *data, | |
779 | void *userdata) { | |
780 | ||
99534007 | 781 | ExecContext *c = ASSERT_PTR(data); |
ad21e542 ZJS |
782 | int r; |
783 | ||
784 | assert(filename); | |
785 | assert(lvalue); | |
786 | assert(rvalue); | |
ad21e542 ZJS |
787 | |
788 | if (isempty(rvalue)) { | |
789 | c->coredump_filter = 0; | |
790 | c->coredump_filter_set = false; | |
791 | return 0; | |
792 | } | |
793 | ||
794 | uint64_t f; | |
795 | r = coredump_filter_mask_from_string(rvalue, &f); | |
796 | if (r < 0) { | |
797 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
798 | "Failed to parse the CoredumpFilter=%s, ignoring: %m", rvalue); | |
799 | return 0; | |
800 | } | |
801 | ||
802 | c->coredump_filter |= f; | |
9c669abb | 803 | c->coredump_filter_set = true; |
ad21e542 ZJS |
804 | return 0; |
805 | } | |
806 | ||
d068765b LP |
807 | int config_parse_kill_mode( |
808 | const char* unit, | |
809 | const char *filename, | |
810 | unsigned line, | |
811 | const char *section, | |
812 | unsigned section_line, | |
813 | const char *lvalue, | |
814 | int ltype, | |
815 | const char *rvalue, | |
816 | void *data, | |
817 | void *userdata) { | |
818 | ||
819 | KillMode *k = data, m; | |
820 | ||
821 | assert(filename); | |
822 | assert(lvalue); | |
823 | assert(rvalue); | |
824 | assert(data); | |
825 | ||
826 | if (isempty(rvalue)) { | |
827 | *k = KILL_CONTROL_GROUP; | |
828 | return 0; | |
829 | } | |
830 | ||
831 | m = kill_mode_from_string(rvalue); | |
832 | if (m < 0) { | |
b98680b2 | 833 | log_syntax(unit, LOG_WARNING, filename, line, m, |
d068765b LP |
834 | "Failed to parse kill mode specification, ignoring: %s", rvalue); |
835 | return 0; | |
836 | } | |
837 | ||
838 | if (m == KILL_NONE) | |
839 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
af9d5d50 | 840 | "Unit uses KillMode=none. " |
15e6a6e8 | 841 | "This is unsafe, as it disables systemd's process lifecycle management for the service. " |
af9d5d50 | 842 | "Please update the service to use a safer KillMode=, such as 'mixed' or 'control-group'. " |
d068765b LP |
843 | "Support for KillMode=none is deprecated and will eventually be removed."); |
844 | ||
845 | *k = m; | |
846 | return 0; | |
847 | } | |
848 | ||
527b7a42 LP |
849 | int config_parse_exec( |
850 | const char *unit, | |
851 | const char *filename, | |
852 | unsigned line, | |
853 | const char *section, | |
854 | unsigned section_line, | |
855 | const char *lvalue, | |
856 | int ltype, | |
857 | const char *rvalue, | |
858 | void *data, | |
859 | void *userdata) { | |
034c6ed7 | 860 | |
99534007 | 861 | ExecCommand **e = ASSERT_PTR(data); |
47538b76 | 862 | const Unit *u = userdata; |
46a0d98a FB |
863 | const char *p; |
864 | bool semicolon; | |
7f110ff9 | 865 | int r; |
034c6ed7 LP |
866 | |
867 | assert(filename); | |
868 | assert(lvalue); | |
869 | assert(rvalue); | |
034c6ed7 | 870 | |
74051b9b | 871 | e += ltype; |
c83f1f30 | 872 | |
74051b9b LP |
873 | if (isempty(rvalue)) { |
874 | /* An empty assignment resets the list */ | |
f1acf85a | 875 | *e = exec_command_free_list(*e); |
74051b9b LP |
876 | return 0; |
877 | } | |
878 | ||
bd1b973f | 879 | p = rvalue; |
46a0d98a | 880 | do { |
dea7b6b0 | 881 | _cleanup_free_ char *path = NULL, *firstword = NULL; |
165a31c0 LP |
882 | ExecCommandFlags flags = 0; |
883 | bool ignore = false, separate_argv0 = false; | |
dea7b6b0 | 884 | _cleanup_free_ ExecCommand *nce = NULL; |
46a0d98a | 885 | _cleanup_strv_free_ char **n = NULL; |
319a4f4b | 886 | size_t nlen = 0; |
5125e762 | 887 | const char *f; |
6c666e26 | 888 | |
46a0d98a FB |
889 | semicolon = false; |
890 | ||
4ec85141 | 891 | r = extract_first_word_and_warn(&p, &firstword, NULL, EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE, unit, filename, line, rvalue); |
46a0d98a FB |
892 | if (r <= 0) |
893 | return 0; | |
6c666e26 | 894 | |
598c47c8 ZJS |
895 | /* A lone ";" is a separator. Let's make sure we don't treat it as an executable name. */ |
896 | if (streq(firstword, ";")) { | |
897 | semicolon = true; | |
898 | continue; | |
899 | } | |
900 | ||
46a0d98a | 901 | f = firstword; |
007f48bb | 902 | for (;;) { |
165a31c0 LP |
903 | /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't |
904 | * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of | |
7ca69792 AZ |
905 | * argv[0]; if it's prefixed with :, we will not do environment variable substitution; |
906 | * if it's prefixed with +, it will be run with full privileges and no sandboxing; if | |
165a31c0 LP |
907 | * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if |
908 | * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient | |
909 | * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most | |
910 | * other sandboxing, with some special exceptions for changing UID. | |
911 | * | |
912 | * The idea is that '!!' may be used to write services that can take benefit of systemd's | |
913 | * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to | |
914 | * privilege dropping within the daemon if the kernel does not offer that. */ | |
915 | ||
916 | if (*f == '-' && !(flags & EXEC_COMMAND_IGNORE_FAILURE)) { | |
917 | flags |= EXEC_COMMAND_IGNORE_FAILURE; | |
46a0d98a | 918 | ignore = true; |
165a31c0 | 919 | } else if (*f == '@' && !separate_argv0) |
46a0d98a | 920 | separate_argv0 = true; |
7ca69792 AZ |
921 | else if (*f == ':' && !(flags & EXEC_COMMAND_NO_ENV_EXPAND)) |
922 | flags |= EXEC_COMMAND_NO_ENV_EXPAND; | |
165a31c0 LP |
923 | else if (*f == '+' && !(flags & (EXEC_COMMAND_FULLY_PRIVILEGED|EXEC_COMMAND_NO_SETUID|EXEC_COMMAND_AMBIENT_MAGIC))) |
924 | flags |= EXEC_COMMAND_FULLY_PRIVILEGED; | |
925 | else if (*f == '!' && !(flags & (EXEC_COMMAND_FULLY_PRIVILEGED|EXEC_COMMAND_NO_SETUID|EXEC_COMMAND_AMBIENT_MAGIC))) | |
926 | flags |= EXEC_COMMAND_NO_SETUID; | |
927 | else if (*f == '!' && !(flags & (EXEC_COMMAND_FULLY_PRIVILEGED|EXEC_COMMAND_AMBIENT_MAGIC))) { | |
928 | flags &= ~EXEC_COMMAND_NO_SETUID; | |
929 | flags |= EXEC_COMMAND_AMBIENT_MAGIC; | |
930 | } else | |
46a0d98a | 931 | break; |
313cefa1 | 932 | f++; |
61e5d8ed | 933 | } |
46a0d98a | 934 | |
06536492 | 935 | r = unit_path_printf(u, f, &path); |
5125e762 | 936 | if (r < 0) { |
323dda78 | 937 | log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, r, |
063c4b1a | 938 | "Failed to resolve unit specifiers in '%s'%s: %m", |
bb28e684 ZJS |
939 | f, ignore ? ", ignoring" : ""); |
940 | return ignore ? 0 : -ENOEXEC; | |
5125e762 LP |
941 | } |
942 | ||
943 | if (isempty(path)) { | |
46a0d98a | 944 | /* First word is either "-" or "@" with no command. */ |
323dda78 | 945 | log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, 0, |
063c4b1a | 946 | "Empty path in command line%s: '%s'", |
bb28e684 ZJS |
947 | ignore ? ", ignoring" : "", rvalue); |
948 | return ignore ? 0 : -ENOEXEC; | |
b2fadec6 | 949 | } |
5125e762 | 950 | if (!string_is_safe(path)) { |
323dda78 | 951 | log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, 0, |
5008da1e ZJS |
952 | "Executable name contains special characters%s: %s", |
953 | ignore ? ", ignoring" : "", path); | |
bb28e684 | 954 | return ignore ? 0 : -ENOEXEC; |
46a0d98a | 955 | } |
5125e762 | 956 | if (endswith(path, "/")) { |
323dda78 | 957 | log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, 0, |
bb28e684 | 958 | "Executable path specifies a directory%s: %s", |
5008da1e | 959 | ignore ? ", ignoring" : "", path); |
bb28e684 | 960 | return ignore ? 0 : -ENOEXEC; |
46a0d98a | 961 | } |
61e5d8ed | 962 | |
108144ad | 963 | if (!(path_is_absolute(path) ? path_is_valid(path) : filename_is_valid(path))) { |
9f71ba8d ZJS |
964 | log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, 0, |
965 | "Neither a valid executable name nor an absolute path%s: %s", | |
966 | ignore ? ", ignoring" : "", path); | |
967 | return ignore ? 0 : -ENOEXEC; | |
5008da1e ZJS |
968 | } |
969 | ||
46a0d98a | 970 | if (!separate_argv0) { |
5125e762 LP |
971 | char *w = NULL; |
972 | ||
15092743 | 973 | if (!GREEDY_REALLOC0(n, nlen + 2)) |
46a0d98a | 974 | return log_oom(); |
5125e762 LP |
975 | |
976 | w = strdup(path); | |
977 | if (!w) | |
46a0d98a | 978 | return log_oom(); |
5125e762 | 979 | n[nlen++] = w; |
46a0d98a FB |
980 | n[nlen] = NULL; |
981 | } | |
7f110ff9 | 982 | |
4ff361cc | 983 | path_simplify(path); |
46a0d98a | 984 | |
4b1c1753 | 985 | while (!isempty(p)) { |
5125e762 | 986 | _cleanup_free_ char *word = NULL, *resolved = NULL; |
46a0d98a FB |
987 | |
988 | /* Check explicitly for an unquoted semicolon as | |
989 | * command separator token. */ | |
990 | if (p[0] == ';' && (!p[1] || strchr(WHITESPACE, p[1]))) { | |
313cefa1 | 991 | p++; |
46a0d98a FB |
992 | p += strspn(p, WHITESPACE); |
993 | semicolon = true; | |
994 | break; | |
c8539536 | 995 | } |
7f110ff9 | 996 | |
5125e762 LP |
997 | /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc. |
998 | * extract_first_word() would return the same for all of those. */ | |
46a0d98a | 999 | if (p[0] == '\\' && p[1] == ';' && (!p[2] || strchr(WHITESPACE, p[2]))) { |
5125e762 LP |
1000 | char *w; |
1001 | ||
46a0d98a FB |
1002 | p += 2; |
1003 | p += strspn(p, WHITESPACE); | |
5125e762 | 1004 | |
15092743 | 1005 | if (!GREEDY_REALLOC0(n, nlen + 2)) |
46a0d98a | 1006 | return log_oom(); |
5125e762 LP |
1007 | |
1008 | w = strdup(";"); | |
1009 | if (!w) | |
46a0d98a | 1010 | return log_oom(); |
5125e762 | 1011 | n[nlen++] = w; |
46a0d98a FB |
1012 | n[nlen] = NULL; |
1013 | continue; | |
61e5d8ed | 1014 | } |
c8539536 | 1015 | |
4ec85141 | 1016 | r = extract_first_word_and_warn(&p, &word, NULL, EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE, unit, filename, line, rvalue); |
46a0d98a FB |
1017 | if (r == 0) |
1018 | break; | |
5125e762 | 1019 | if (r < 0) |
bb28e684 | 1020 | return ignore ? 0 : -ENOEXEC; |
5125e762 | 1021 | |
58dd4999 | 1022 | r = unit_full_printf(u, word, &resolved); |
5125e762 | 1023 | if (r < 0) { |
323dda78 | 1024 | log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, r, |
063c4b1a | 1025 | "Failed to resolve unit specifiers in %s%s: %m", |
bb28e684 ZJS |
1026 | word, ignore ? ", ignoring" : ""); |
1027 | return ignore ? 0 : -ENOEXEC; | |
5125e762 | 1028 | } |
46a0d98a | 1029 | |
319a4f4b | 1030 | if (!GREEDY_REALLOC(n, nlen + 2)) |
46a0d98a | 1031 | return log_oom(); |
1cc6c93a YW |
1032 | |
1033 | n[nlen++] = TAKE_PTR(resolved); | |
46a0d98a | 1034 | n[nlen] = NULL; |
61e5d8ed LP |
1035 | } |
1036 | ||
46a0d98a | 1037 | if (!n || !n[0]) { |
323dda78 | 1038 | log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, 0, |
bb28e684 ZJS |
1039 | "Empty executable name or zeroeth argument%s: %s", |
1040 | ignore ? ", ignoring" : "", rvalue); | |
1041 | return ignore ? 0 : -ENOEXEC; | |
7f110ff9 | 1042 | } |
6c666e26 | 1043 | |
7f110ff9 | 1044 | nce = new0(ExecCommand, 1); |
46a0d98a FB |
1045 | if (!nce) |
1046 | return log_oom(); | |
61e5d8ed | 1047 | |
1cc6c93a YW |
1048 | nce->argv = TAKE_PTR(n); |
1049 | nce->path = TAKE_PTR(path); | |
165a31c0 | 1050 | nce->flags = flags; |
034c6ed7 | 1051 | |
61e5d8ed | 1052 | exec_command_append_list(e, nce); |
01f78473 | 1053 | |
46a0d98a | 1054 | /* Do not _cleanup_free_ these. */ |
46a0d98a | 1055 | nce = NULL; |
034c6ed7 | 1056 | |
46a0d98a FB |
1057 | rvalue = p; |
1058 | } while (semicolon); | |
034c6ed7 | 1059 | |
46a0d98a | 1060 | return 0; |
034c6ed7 LP |
1061 | } |
1062 | ||
d31645ad LP |
1063 | int config_parse_socket_bindtodevice( |
1064 | const char* unit, | |
1065 | const char *filename, | |
1066 | unsigned line, | |
1067 | const char *section, | |
1068 | unsigned section_line, | |
1069 | const char *lvalue, | |
1070 | int ltype, | |
1071 | const char *rvalue, | |
1072 | void *data, | |
1073 | void *userdata) { | |
acbb0225 | 1074 | |
99534007 | 1075 | Socket *s = ASSERT_PTR(data); |
acbb0225 LP |
1076 | |
1077 | assert(filename); | |
1078 | assert(lvalue); | |
1079 | assert(rvalue); | |
acbb0225 | 1080 | |
063c4b1a YW |
1081 | if (isempty(rvalue) || streq(rvalue, "*")) { |
1082 | s->bind_to_device = mfree(s->bind_to_device); | |
1083 | return 0; | |
1084 | } | |
d31645ad | 1085 | |
063c4b1a | 1086 | if (!ifname_valid(rvalue)) { |
323dda78 | 1087 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid interface name, ignoring: %s", rvalue); |
063c4b1a YW |
1088 | return 0; |
1089 | } | |
acbb0225 | 1090 | |
b3f9c17a | 1091 | return free_and_strdup_warn(&s->bind_to_device, rvalue); |
acbb0225 LP |
1092 | } |
1093 | ||
9bd6a50e LP |
1094 | int config_parse_exec_input( |
1095 | const char *unit, | |
1096 | const char *filename, | |
1097 | unsigned line, | |
1098 | const char *section, | |
1099 | unsigned section_line, | |
1100 | const char *lvalue, | |
1101 | int ltype, | |
1102 | const char *rvalue, | |
1103 | void *data, | |
1104 | void *userdata) { | |
52c239d7 | 1105 | |
99534007 | 1106 | ExecContext *c = ASSERT_PTR(data); |
47538b76 | 1107 | const Unit *u = userdata; |
2038c3f5 LP |
1108 | const char *n; |
1109 | ExecInput ei; | |
52c239d7 LB |
1110 | int r; |
1111 | ||
52c239d7 LB |
1112 | assert(filename); |
1113 | assert(line); | |
1114 | assert(rvalue); | |
1115 | ||
2038c3f5 LP |
1116 | n = startswith(rvalue, "fd:"); |
1117 | if (n) { | |
1118 | _cleanup_free_ char *resolved = NULL; | |
1119 | ||
06536492 | 1120 | r = unit_fd_printf(u, n, &resolved); |
323dda78 YW |
1121 | if (r < 0) { |
1122 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", n); | |
1123 | return 0; | |
1124 | } | |
2038c3f5 LP |
1125 | |
1126 | if (isempty(resolved)) | |
1127 | resolved = mfree(resolved); | |
1128 | else if (!fdname_is_valid(resolved)) { | |
323dda78 YW |
1129 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid file descriptor name, ignoring: %s", resolved); |
1130 | return 0; | |
52c239d7 | 1131 | } |
9bd6a50e | 1132 | |
2038c3f5 LP |
1133 | free_and_replace(c->stdio_fdname[STDIN_FILENO], resolved); |
1134 | ||
1135 | ei = EXEC_INPUT_NAMED_FD; | |
1136 | ||
1137 | } else if ((n = startswith(rvalue, "file:"))) { | |
1138 | _cleanup_free_ char *resolved = NULL; | |
1139 | ||
06536492 | 1140 | r = unit_path_printf(u, n, &resolved); |
323dda78 YW |
1141 | if (r < 0) { |
1142 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", n); | |
1143 | return 0; | |
1144 | } | |
9bd6a50e | 1145 | |
2f4d31c1 YW |
1146 | r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE | PATH_CHECK_FATAL, unit, filename, line, lvalue); |
1147 | if (r < 0) | |
323dda78 | 1148 | return 0; |
2038c3f5 LP |
1149 | |
1150 | free_and_replace(c->stdio_file[STDIN_FILENO], resolved); | |
1151 | ||
1152 | ei = EXEC_INPUT_FILE; | |
9bd6a50e | 1153 | |
52c239d7 | 1154 | } else { |
9bd6a50e LP |
1155 | ei = exec_input_from_string(rvalue); |
1156 | if (ei < 0) { | |
b98680b2 | 1157 | log_syntax(unit, LOG_WARNING, filename, line, ei, "Failed to parse input specifier, ignoring: %s", rvalue); |
9bd6a50e LP |
1158 | return 0; |
1159 | } | |
52c239d7 | 1160 | } |
9bd6a50e | 1161 | |
2038c3f5 | 1162 | c->std_input = ei; |
9bd6a50e | 1163 | return 0; |
52c239d7 LB |
1164 | } |
1165 | ||
08f3be7a LP |
1166 | int config_parse_exec_input_text( |
1167 | const char *unit, | |
1168 | const char *filename, | |
1169 | unsigned line, | |
1170 | const char *section, | |
1171 | unsigned section_line, | |
1172 | const char *lvalue, | |
1173 | int ltype, | |
1174 | const char *rvalue, | |
1175 | void *data, | |
1176 | void *userdata) { | |
1177 | ||
1178 | _cleanup_free_ char *unescaped = NULL, *resolved = NULL; | |
99534007 | 1179 | ExecContext *c = ASSERT_PTR(data); |
47538b76 | 1180 | const Unit *u = userdata; |
08f3be7a LP |
1181 | int r; |
1182 | ||
08f3be7a LP |
1183 | assert(filename); |
1184 | assert(line); | |
1185 | assert(rvalue); | |
1186 | ||
1187 | if (isempty(rvalue)) { | |
1188 | /* Reset if the empty string is assigned */ | |
1189 | c->stdin_data = mfree(c->stdin_data); | |
1190 | c->stdin_data_size = 0; | |
52c239d7 LB |
1191 | return 0; |
1192 | } | |
08f3be7a | 1193 | |
e437538f ZJS |
1194 | ssize_t l = cunescape(rvalue, 0, &unescaped); |
1195 | if (l < 0) { | |
1196 | log_syntax(unit, LOG_WARNING, filename, line, l, | |
323dda78 YW |
1197 | "Failed to decode C escaped text '%s', ignoring: %m", rvalue); |
1198 | return 0; | |
1199 | } | |
08f3be7a | 1200 | |
06536492 | 1201 | r = unit_full_printf_full(u, unescaped, EXEC_STDIN_DATA_MAX, &resolved); |
323dda78 YW |
1202 | if (r < 0) { |
1203 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
1204 | "Failed to resolve unit specifiers in '%s', ignoring: %m", unescaped); | |
1205 | return 0; | |
1206 | } | |
08f3be7a | 1207 | |
e437538f | 1208 | size_t sz = strlen(resolved); |
08f3be7a LP |
1209 | if (c->stdin_data_size + sz + 1 < c->stdin_data_size || /* check for overflow */ |
1210 | c->stdin_data_size + sz + 1 > EXEC_STDIN_DATA_MAX) { | |
323dda78 YW |
1211 | log_syntax(unit, LOG_WARNING, filename, line, 0, |
1212 | "Standard input data too large (%zu), maximum of %zu permitted, ignoring.", | |
1213 | c->stdin_data_size + sz, (size_t) EXEC_STDIN_DATA_MAX); | |
1214 | return 0; | |
08f3be7a LP |
1215 | } |
1216 | ||
e437538f | 1217 | void *p = realloc(c->stdin_data, c->stdin_data_size + sz + 1); |
08f3be7a LP |
1218 | if (!p) |
1219 | return log_oom(); | |
1220 | ||
1221 | *((char*) mempcpy((char*) p + c->stdin_data_size, resolved, sz)) = '\n'; | |
1222 | ||
1223 | c->stdin_data = p; | |
1224 | c->stdin_data_size += sz + 1; | |
1225 | ||
1226 | return 0; | |
52c239d7 LB |
1227 | } |
1228 | ||
08f3be7a LP |
1229 | int config_parse_exec_input_data( |
1230 | const char *unit, | |
1231 | const char *filename, | |
1232 | unsigned line, | |
1233 | const char *section, | |
1234 | unsigned section_line, | |
1235 | const char *lvalue, | |
1236 | int ltype, | |
1237 | const char *rvalue, | |
1238 | void *data, | |
1239 | void *userdata) { | |
1240 | ||
08f3be7a | 1241 | _cleanup_free_ void *p = NULL; |
99534007 | 1242 | ExecContext *c = ASSERT_PTR(data); |
08f3be7a LP |
1243 | size_t sz; |
1244 | void *q; | |
1245 | int r; | |
1246 | ||
08f3be7a LP |
1247 | assert(filename); |
1248 | assert(line); | |
1249 | assert(rvalue); | |
1250 | ||
1251 | if (isempty(rvalue)) { | |
1252 | /* Reset if the empty string is assigned */ | |
1253 | c->stdin_data = mfree(c->stdin_data); | |
1254 | c->stdin_data_size = 0; | |
1255 | return 0; | |
1256 | } | |
1257 | ||
bdd2036e | 1258 | r = unbase64mem(rvalue, &p, &sz); |
323dda78 YW |
1259 | if (r < 0) { |
1260 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
1261 | "Failed to decode base64 data, ignoring: %s", rvalue); | |
1262 | return 0; | |
1263 | } | |
08f3be7a LP |
1264 | |
1265 | assert(sz > 0); | |
1266 | ||
1267 | if (c->stdin_data_size + sz < c->stdin_data_size || /* check for overflow */ | |
1268 | c->stdin_data_size + sz > EXEC_STDIN_DATA_MAX) { | |
323dda78 YW |
1269 | log_syntax(unit, LOG_WARNING, filename, line, 0, |
1270 | "Standard input data too large (%zu), maximum of %zu permitted, ignoring.", | |
1271 | c->stdin_data_size + sz, (size_t) EXEC_STDIN_DATA_MAX); | |
1272 | return 0; | |
08f3be7a LP |
1273 | } |
1274 | ||
1275 | q = realloc(c->stdin_data, c->stdin_data_size + sz); | |
1276 | if (!q) | |
1277 | return log_oom(); | |
1278 | ||
1279 | memcpy((uint8_t*) q + c->stdin_data_size, p, sz); | |
1280 | ||
1281 | c->stdin_data = q; | |
1282 | c->stdin_data_size += sz; | |
1283 | ||
1284 | return 0; | |
1285 | } | |
1286 | ||
2038c3f5 LP |
1287 | int config_parse_exec_output( |
1288 | const char *unit, | |
1289 | const char *filename, | |
1290 | unsigned line, | |
1291 | const char *section, | |
1292 | unsigned section_line, | |
1293 | const char *lvalue, | |
1294 | int ltype, | |
1295 | const char *rvalue, | |
1296 | void *data, | |
1297 | void *userdata) { | |
1298 | ||
1299 | _cleanup_free_ char *resolved = NULL; | |
1300 | const char *n; | |
99534007 | 1301 | ExecContext *c = ASSERT_PTR(data); |
47538b76 | 1302 | const Unit *u = userdata; |
f3dc6af2 | 1303 | bool obsolete = false; |
52c239d7 | 1304 | ExecOutput eo; |
52c239d7 LB |
1305 | int r; |
1306 | ||
52c239d7 LB |
1307 | assert(filename); |
1308 | assert(line); | |
1309 | assert(lvalue); | |
1310 | assert(rvalue); | |
1311 | ||
2038c3f5 LP |
1312 | n = startswith(rvalue, "fd:"); |
1313 | if (n) { | |
06536492 | 1314 | r = unit_fd_printf(u, n, &resolved); |
323dda78 YW |
1315 | if (r < 0) { |
1316 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s: %m", n); | |
1317 | return 0; | |
1318 | } | |
2038c3f5 LP |
1319 | |
1320 | if (isempty(resolved)) | |
1321 | resolved = mfree(resolved); | |
1322 | else if (!fdname_is_valid(resolved)) { | |
323dda78 YW |
1323 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid file descriptor name, ignoring: %s", resolved); |
1324 | return 0; | |
52c239d7 | 1325 | } |
2038c3f5 | 1326 | |
52c239d7 | 1327 | eo = EXEC_OUTPUT_NAMED_FD; |
2038c3f5 | 1328 | |
f3dc6af2 LP |
1329 | } else if (streq(rvalue, "syslog")) { |
1330 | eo = EXEC_OUTPUT_JOURNAL; | |
1331 | obsolete = true; | |
1332 | ||
1333 | } else if (streq(rvalue, "syslog+console")) { | |
1334 | eo = EXEC_OUTPUT_JOURNAL_AND_CONSOLE; | |
1335 | obsolete = true; | |
1336 | ||
2038c3f5 LP |
1337 | } else if ((n = startswith(rvalue, "file:"))) { |
1338 | ||
06536492 | 1339 | r = unit_path_printf(u, n, &resolved); |
323dda78 YW |
1340 | if (r < 0) { |
1341 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", n); | |
1342 | return 0; | |
1343 | } | |
2038c3f5 | 1344 | |
2f4d31c1 YW |
1345 | r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE | PATH_CHECK_FATAL, unit, filename, line, lvalue); |
1346 | if (r < 0) | |
323dda78 | 1347 | return 0; |
2038c3f5 LP |
1348 | |
1349 | eo = EXEC_OUTPUT_FILE; | |
1350 | ||
566b7d23 ZD |
1351 | } else if ((n = startswith(rvalue, "append:"))) { |
1352 | ||
06536492 | 1353 | r = unit_path_printf(u, n, &resolved); |
323dda78 YW |
1354 | if (r < 0) { |
1355 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", n); | |
1356 | return 0; | |
1357 | } | |
566b7d23 ZD |
1358 | |
1359 | r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE | PATH_CHECK_FATAL, unit, filename, line, lvalue); | |
1360 | if (r < 0) | |
323dda78 | 1361 | return 0; |
566b7d23 ZD |
1362 | |
1363 | eo = EXEC_OUTPUT_FILE_APPEND; | |
8d7dab1f LW |
1364 | |
1365 | } else if ((n = startswith(rvalue, "truncate:"))) { | |
1366 | ||
06536492 | 1367 | r = unit_path_printf(u, n, &resolved); |
8d7dab1f LW |
1368 | if (r < 0) { |
1369 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", n); | |
1370 | return 0; | |
1371 | } | |
1372 | ||
1373 | r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE | PATH_CHECK_FATAL, unit, filename, line, lvalue); | |
1374 | if (r < 0) | |
1375 | return 0; | |
1376 | ||
1377 | eo = EXEC_OUTPUT_FILE_TRUNCATE; | |
52c239d7 LB |
1378 | } else { |
1379 | eo = exec_output_from_string(rvalue); | |
2038c3f5 | 1380 | if (eo < 0) { |
b98680b2 | 1381 | log_syntax(unit, LOG_WARNING, filename, line, eo, "Failed to parse output specifier, ignoring: %s", rvalue); |
52c239d7 LB |
1382 | return 0; |
1383 | } | |
1384 | } | |
1385 | ||
f3dc6af2 LP |
1386 | if (obsolete) |
1387 | log_syntax(unit, LOG_NOTICE, filename, line, 0, | |
1388 | "Standard output type %s is obsolete, automatically updating to %s. Please update your unit file, and consider removing the setting altogether.", | |
1389 | rvalue, exec_output_to_string(eo)); | |
1390 | ||
52c239d7 | 1391 | if (streq(lvalue, "StandardOutput")) { |
2038c3f5 LP |
1392 | if (eo == EXEC_OUTPUT_NAMED_FD) |
1393 | free_and_replace(c->stdio_fdname[STDOUT_FILENO], resolved); | |
1394 | else | |
1395 | free_and_replace(c->stdio_file[STDOUT_FILENO], resolved); | |
1396 | ||
52c239d7 | 1397 | c->std_output = eo; |
2038c3f5 | 1398 | |
52c239d7 | 1399 | } else { |
2038c3f5 LP |
1400 | assert(streq(lvalue, "StandardError")); |
1401 | ||
1402 | if (eo == EXEC_OUTPUT_NAMED_FD) | |
1403 | free_and_replace(c->stdio_fdname[STDERR_FILENO], resolved); | |
1404 | else | |
1405 | free_and_replace(c->stdio_file[STDERR_FILENO], resolved); | |
1406 | ||
1407 | c->std_error = eo; | |
52c239d7 | 1408 | } |
2038c3f5 LP |
1409 | |
1410 | return 0; | |
52c239d7 | 1411 | } |
87f0e418 | 1412 | |
e8e581bf ZJS |
1413 | int config_parse_exec_io_class(const char *unit, |
1414 | const char *filename, | |
1415 | unsigned line, | |
1416 | const char *section, | |
71a61510 | 1417 | unsigned section_line, |
e8e581bf ZJS |
1418 | const char *lvalue, |
1419 | int ltype, | |
1420 | const char *rvalue, | |
1421 | void *data, | |
1422 | void *userdata) { | |
94f04347 | 1423 | |
99534007 | 1424 | ExecContext *c = ASSERT_PTR(data); |
94f04347 LP |
1425 | int x; |
1426 | ||
1427 | assert(filename); | |
1428 | assert(lvalue); | |
1429 | assert(rvalue); | |
94f04347 | 1430 | |
617d253a YW |
1431 | if (isempty(rvalue)) { |
1432 | c->ioprio_set = false; | |
0692548c | 1433 | c->ioprio = IOPRIO_DEFAULT_CLASS_AND_PRIO; |
617d253a YW |
1434 | return 0; |
1435 | } | |
1436 | ||
f8b69d1d MS |
1437 | x = ioprio_class_from_string(rvalue); |
1438 | if (x < 0) { | |
b98680b2 | 1439 | log_syntax(unit, LOG_WARNING, filename, line, x, "Failed to parse IO scheduling class, ignoring: %s", rvalue); |
c0b34696 | 1440 | return 0; |
0d87eb42 | 1441 | } |
94f04347 | 1442 | |
ba7772fe | 1443 | c->ioprio = ioprio_normalize(ioprio_prio_value(x, ioprio_prio_data(c->ioprio))); |
94f04347 LP |
1444 | c->ioprio_set = true; |
1445 | ||
1446 | return 0; | |
1447 | } | |
1448 | ||
e8e581bf ZJS |
1449 | int config_parse_exec_io_priority(const char *unit, |
1450 | const char *filename, | |
1451 | unsigned line, | |
1452 | const char *section, | |
71a61510 | 1453 | unsigned section_line, |
e8e581bf ZJS |
1454 | const char *lvalue, |
1455 | int ltype, | |
1456 | const char *rvalue, | |
1457 | void *data, | |
1458 | void *userdata) { | |
94f04347 | 1459 | |
99534007 | 1460 | ExecContext *c = ASSERT_PTR(data); |
e8e581bf | 1461 | int i, r; |
94f04347 LP |
1462 | |
1463 | assert(filename); | |
1464 | assert(lvalue); | |
1465 | assert(rvalue); | |
94f04347 | 1466 | |
617d253a YW |
1467 | if (isempty(rvalue)) { |
1468 | c->ioprio_set = false; | |
0692548c | 1469 | c->ioprio = IOPRIO_DEFAULT_CLASS_AND_PRIO; |
617d253a YW |
1470 | return 0; |
1471 | } | |
1472 | ||
7f452159 LP |
1473 | r = ioprio_parse_priority(rvalue, &i); |
1474 | if (r < 0) { | |
323dda78 | 1475 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse IO priority, ignoring: %s", rvalue); |
c0b34696 | 1476 | return 0; |
071830ff LP |
1477 | } |
1478 | ||
ba7772fe | 1479 | c->ioprio = ioprio_normalize(ioprio_prio_value(ioprio_prio_class(c->ioprio), i)); |
94f04347 LP |
1480 | c->ioprio_set = true; |
1481 | ||
071830ff LP |
1482 | return 0; |
1483 | } | |
1484 | ||
e8e581bf ZJS |
1485 | int config_parse_exec_cpu_sched_policy(const char *unit, |
1486 | const char *filename, | |
1487 | unsigned line, | |
1488 | const char *section, | |
71a61510 | 1489 | unsigned section_line, |
e8e581bf ZJS |
1490 | const char *lvalue, |
1491 | int ltype, | |
1492 | const char *rvalue, | |
1493 | void *data, | |
1494 | void *userdata) { | |
9eba9da4 | 1495 | |
99534007 | 1496 | ExecContext *c = ASSERT_PTR(data); |
94f04347 LP |
1497 | int x; |
1498 | ||
1499 | assert(filename); | |
1500 | assert(lvalue); | |
1501 | assert(rvalue); | |
94f04347 | 1502 | |
b00e1a9e YW |
1503 | if (isempty(rvalue)) { |
1504 | c->cpu_sched_set = false; | |
1505 | c->cpu_sched_policy = SCHED_OTHER; | |
1506 | c->cpu_sched_priority = 0; | |
1507 | return 0; | |
1508 | } | |
1509 | ||
f8b69d1d MS |
1510 | x = sched_policy_from_string(rvalue); |
1511 | if (x < 0) { | |
b98680b2 | 1512 | log_syntax(unit, LOG_WARNING, filename, line, x, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue); |
c0b34696 | 1513 | return 0; |
0d87eb42 | 1514 | } |
94f04347 LP |
1515 | |
1516 | c->cpu_sched_policy = x; | |
bb112710 HHPF |
1517 | /* Moving to or from real-time policy? We need to adjust the priority */ |
1518 | c->cpu_sched_priority = CLAMP(c->cpu_sched_priority, sched_get_priority_min(x), sched_get_priority_max(x)); | |
94f04347 LP |
1519 | c->cpu_sched_set = true; |
1520 | ||
1521 | return 0; | |
1522 | } | |
1523 | ||
5e98086d ZJS |
1524 | int config_parse_exec_mount_apivfs(const char *unit, |
1525 | const char *filename, | |
1526 | unsigned line, | |
1527 | const char *section, | |
1528 | unsigned section_line, | |
1529 | const char *lvalue, | |
1530 | int ltype, | |
1531 | const char *rvalue, | |
1532 | void *data, | |
1533 | void *userdata) { | |
1534 | ||
99534007 | 1535 | ExecContext *c = ASSERT_PTR(data); |
5e98086d ZJS |
1536 | int k; |
1537 | ||
1538 | assert(filename); | |
1539 | assert(lvalue); | |
1540 | assert(rvalue); | |
5e98086d ZJS |
1541 | |
1542 | if (isempty(rvalue)) { | |
1543 | c->mount_apivfs_set = false; | |
1544 | c->mount_apivfs = false; | |
1545 | return 0; | |
1546 | } | |
1547 | ||
1548 | k = parse_boolean(rvalue); | |
1549 | if (k < 0) { | |
1550 | log_syntax(unit, LOG_WARNING, filename, line, k, | |
1551 | "Failed to parse boolean value, ignoring: %s", | |
1552 | rvalue); | |
1553 | return 0; | |
1554 | } | |
1555 | ||
1556 | c->mount_apivfs_set = true; | |
1557 | c->mount_apivfs = k; | |
1558 | return 0; | |
1559 | } | |
1560 | ||
b070c7c0 MS |
1561 | int config_parse_numa_mask(const char *unit, |
1562 | const char *filename, | |
1563 | unsigned line, | |
1564 | const char *section, | |
1565 | unsigned section_line, | |
1566 | const char *lvalue, | |
1567 | int ltype, | |
1568 | const char *rvalue, | |
1569 | void *data, | |
1570 | void *userdata) { | |
1571 | int r; | |
99534007 | 1572 | NUMAPolicy *p = ASSERT_PTR(data); |
b070c7c0 MS |
1573 | |
1574 | assert(filename); | |
1575 | assert(lvalue); | |
1576 | assert(rvalue); | |
b070c7c0 | 1577 | |
332d387f MS |
1578 | if (streq(rvalue, "all")) { |
1579 | r = numa_mask_add_all(&p->nodes); | |
323dda78 YW |
1580 | if (r < 0) |
1581 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
1582 | "Failed to create NUMA mask representing \"all\" NUMA nodes, ignoring: %m"); | |
332d387f MS |
1583 | } else { |
1584 | r = parse_cpu_set_extend(rvalue, &p->nodes, true, unit, filename, line, lvalue); | |
323dda78 YW |
1585 | if (r < 0) |
1586 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse NUMA node mask, ignoring: %s", rvalue); | |
b070c7c0 MS |
1587 | } |
1588 | ||
323dda78 | 1589 | return 0; |
b070c7c0 MS |
1590 | } |
1591 | ||
e8e581bf ZJS |
1592 | int config_parse_exec_cpu_sched_prio(const char *unit, |
1593 | const char *filename, | |
1594 | unsigned line, | |
1595 | const char *section, | |
71a61510 | 1596 | unsigned section_line, |
e8e581bf ZJS |
1597 | const char *lvalue, |
1598 | int ltype, | |
1599 | const char *rvalue, | |
1600 | void *data, | |
1601 | void *userdata) { | |
9eba9da4 | 1602 | |
99534007 | 1603 | ExecContext *c = ASSERT_PTR(data); |
40c05a34 | 1604 | int i, r; |
9eba9da4 LP |
1605 | |
1606 | assert(filename); | |
1607 | assert(lvalue); | |
1608 | assert(rvalue); | |
9eba9da4 | 1609 | |
e8e581bf ZJS |
1610 | r = safe_atoi(rvalue, &i); |
1611 | if (r < 0) { | |
323dda78 | 1612 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue); |
c0b34696 | 1613 | return 0; |
94f04347 | 1614 | } |
9eba9da4 | 1615 | |
40c05a34 LB |
1616 | /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0. Policy might be set later so |
1617 | * we do not check the precise range, but only the generic outer bounds. */ | |
1618 | if (i < 0 || i > 99) { | |
323dda78 | 1619 | log_syntax(unit, LOG_WARNING, filename, line, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue); |
bb112710 HHPF |
1620 | return 0; |
1621 | } | |
1622 | ||
94f04347 LP |
1623 | c->cpu_sched_priority = i; |
1624 | c->cpu_sched_set = true; | |
1625 | ||
1626 | return 0; | |
1627 | } | |
1628 | ||
18d73705 LB |
1629 | int config_parse_root_image_options( |
1630 | const char *unit, | |
1631 | const char *filename, | |
1632 | unsigned line, | |
1633 | const char *section, | |
1634 | unsigned section_line, | |
1635 | const char *lvalue, | |
1636 | int ltype, | |
1637 | const char *rvalue, | |
1638 | void *data, | |
1639 | void *userdata) { | |
1640 | ||
1641 | _cleanup_(mount_options_free_allp) MountOptions *options = NULL; | |
bc8d56d3 | 1642 | _cleanup_strv_free_ char **l = NULL; |
99534007 | 1643 | ExecContext *c = ASSERT_PTR(data); |
18d73705 | 1644 | const Unit *u = userdata; |
18d73705 LB |
1645 | int r; |
1646 | ||
1647 | assert(filename); | |
1648 | assert(lvalue); | |
1649 | assert(rvalue); | |
18d73705 LB |
1650 | |
1651 | if (isempty(rvalue)) { | |
1652 | c->root_image_options = mount_options_free_all(c->root_image_options); | |
1653 | return 0; | |
1654 | } | |
1655 | ||
bc8d56d3 LB |
1656 | r = strv_split_colon_pairs(&l, rvalue); |
1657 | if (r == -ENOMEM) | |
1658 | return log_oom(); | |
1659 | if (r < 0) { | |
323dda78 | 1660 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s, ignoring: %s", lvalue, rvalue); |
bc8d56d3 LB |
1661 | return 0; |
1662 | } | |
18d73705 | 1663 | |
bc8d56d3 | 1664 | STRV_FOREACH_PAIR(first, second, l) { |
18d73705 | 1665 | MountOptions *o = NULL; |
9ece6444 LB |
1666 | _cleanup_free_ char *mount_options_resolved = NULL; |
1667 | const char *mount_options = NULL, *partition = "root"; | |
569a0e42 | 1668 | PartitionDesignator partition_designator; |
18d73705 | 1669 | |
9ece6444 | 1670 | /* Format is either 'root:foo' or 'foo' (root is implied) */ |
bc8d56d3 | 1671 | if (!isempty(*second)) { |
9ece6444 | 1672 | partition = *first; |
bc8d56d3 | 1673 | mount_options = *second; |
18d73705 | 1674 | } else |
bc8d56d3 | 1675 | mount_options = *first; |
18d73705 | 1676 | |
9ece6444 LB |
1677 | partition_designator = partition_designator_from_string(partition); |
1678 | if (partition_designator < 0) { | |
b98680b2 YW |
1679 | log_syntax(unit, LOG_WARNING, filename, line, partition_designator, |
1680 | "Invalid partition name %s, ignoring", partition); | |
18d73705 LB |
1681 | continue; |
1682 | } | |
18d73705 LB |
1683 | r = unit_full_printf(u, mount_options, &mount_options_resolved); |
1684 | if (r < 0) { | |
323dda78 | 1685 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options); |
18d73705 LB |
1686 | continue; |
1687 | } | |
1688 | ||
1689 | o = new(MountOptions, 1); | |
1690 | if (!o) | |
1691 | return log_oom(); | |
1692 | *o = (MountOptions) { | |
9ece6444 | 1693 | .partition_designator = partition_designator, |
18d73705 LB |
1694 | .options = TAKE_PTR(mount_options_resolved), |
1695 | }; | |
9ece6444 | 1696 | LIST_APPEND(mount_options, options, TAKE_PTR(o)); |
18d73705 LB |
1697 | } |
1698 | ||
64903d18 | 1699 | if (options) |
18d73705 | 1700 | LIST_JOIN(mount_options, c->root_image_options, options); |
64903d18 ZJS |
1701 | else |
1702 | /* empty spaces/separators only */ | |
1703 | c->root_image_options = mount_options_free_all(c->root_image_options); | |
18d73705 LB |
1704 | |
1705 | return 0; | |
1706 | } | |
1707 | ||
0389f4fa LB |
1708 | int config_parse_exec_root_hash( |
1709 | const char *unit, | |
1710 | const char *filename, | |
1711 | unsigned line, | |
1712 | const char *section, | |
1713 | unsigned section_line, | |
1714 | const char *lvalue, | |
1715 | int ltype, | |
1716 | const char *rvalue, | |
1717 | void *data, | |
1718 | void *userdata) { | |
1719 | ||
1720 | _cleanup_free_ void *roothash_decoded = NULL; | |
99534007 | 1721 | ExecContext *c = ASSERT_PTR(data); |
0389f4fa LB |
1722 | size_t roothash_decoded_size = 0; |
1723 | int r; | |
1724 | ||
0389f4fa LB |
1725 | assert(filename); |
1726 | assert(line); | |
1727 | assert(rvalue); | |
1728 | ||
1729 | if (isempty(rvalue)) { | |
1730 | /* Reset if the empty string is assigned */ | |
1731 | c->root_hash_path = mfree(c->root_hash_path); | |
1732 | c->root_hash = mfree(c->root_hash); | |
1733 | c->root_hash_size = 0; | |
1734 | return 0; | |
1735 | } | |
1736 | ||
1737 | if (path_is_absolute(rvalue)) { | |
1738 | /* We have the path to a roothash to load and decode, eg: RootHash=/foo/bar.roothash */ | |
1739 | _cleanup_free_ char *p = NULL; | |
1740 | ||
1741 | p = strdup(rvalue); | |
1742 | if (!p) | |
1743 | return -ENOMEM; | |
1744 | ||
1745 | free_and_replace(c->root_hash_path, p); | |
1746 | c->root_hash = mfree(c->root_hash); | |
1747 | c->root_hash_size = 0; | |
1748 | return 0; | |
1749 | } | |
1750 | ||
1751 | /* We have a roothash to decode, eg: RootHash=012345789abcdef */ | |
bdd2036e | 1752 | r = unhexmem(rvalue, &roothash_decoded, &roothash_decoded_size); |
323dda78 YW |
1753 | if (r < 0) { |
1754 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to decode RootHash=, ignoring: %s", rvalue); | |
1755 | return 0; | |
1756 | } | |
1757 | if (roothash_decoded_size < sizeof(sd_id128_t)) { | |
1758 | log_syntax(unit, LOG_WARNING, filename, line, 0, "RootHash= is too short, ignoring: %s", rvalue); | |
1759 | return 0; | |
1760 | } | |
0389f4fa LB |
1761 | |
1762 | free_and_replace(c->root_hash, roothash_decoded); | |
1763 | c->root_hash_size = roothash_decoded_size; | |
1764 | c->root_hash_path = mfree(c->root_hash_path); | |
1765 | ||
1766 | return 0; | |
1767 | } | |
1768 | ||
d4d55b0d LB |
1769 | int config_parse_exec_root_hash_sig( |
1770 | const char *unit, | |
1771 | const char *filename, | |
1772 | unsigned line, | |
1773 | const char *section, | |
1774 | unsigned section_line, | |
1775 | const char *lvalue, | |
1776 | int ltype, | |
1777 | const char *rvalue, | |
1778 | void *data, | |
1779 | void *userdata) { | |
1780 | ||
1781 | _cleanup_free_ void *roothash_sig_decoded = NULL; | |
1782 | char *value; | |
99534007 | 1783 | ExecContext *c = ASSERT_PTR(data); |
d4d55b0d LB |
1784 | size_t roothash_sig_decoded_size = 0; |
1785 | int r; | |
1786 | ||
d4d55b0d LB |
1787 | assert(filename); |
1788 | assert(line); | |
1789 | assert(rvalue); | |
1790 | ||
1791 | if (isempty(rvalue)) { | |
1792 | /* Reset if the empty string is assigned */ | |
1793 | c->root_hash_sig_path = mfree(c->root_hash_sig_path); | |
1794 | c->root_hash_sig = mfree(c->root_hash_sig); | |
1795 | c->root_hash_sig_size = 0; | |
1796 | return 0; | |
1797 | } | |
1798 | ||
1799 | if (path_is_absolute(rvalue)) { | |
1800 | /* We have the path to a roothash signature to load and decode, eg: RootHashSignature=/foo/bar.roothash.p7s */ | |
1801 | _cleanup_free_ char *p = NULL; | |
1802 | ||
1803 | p = strdup(rvalue); | |
1804 | if (!p) | |
323dda78 | 1805 | return log_oom(); |
d4d55b0d LB |
1806 | |
1807 | free_and_replace(c->root_hash_sig_path, p); | |
1808 | c->root_hash_sig = mfree(c->root_hash_sig); | |
1809 | c->root_hash_sig_size = 0; | |
1810 | return 0; | |
1811 | } | |
1812 | ||
323dda78 YW |
1813 | if (!(value = startswith(rvalue, "base64:"))) { |
1814 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
1815 | "Failed to decode RootHashSignature=, not a path but doesn't start with 'base64:', ignoring: %s", rvalue); | |
1816 | return 0; | |
1817 | } | |
d4d55b0d LB |
1818 | |
1819 | /* We have a roothash signature to decode, eg: RootHashSignature=base64:012345789abcdef */ | |
bdd2036e | 1820 | r = unbase64mem(value, &roothash_sig_decoded, &roothash_sig_decoded_size); |
323dda78 YW |
1821 | if (r < 0) { |
1822 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to decode RootHashSignature=, ignoring: %s", rvalue); | |
1823 | return 0; | |
1824 | } | |
d4d55b0d LB |
1825 | |
1826 | free_and_replace(c->root_hash_sig, roothash_sig_decoded); | |
1827 | c->root_hash_sig_size = roothash_sig_decoded_size; | |
1828 | c->root_hash_sig_path = mfree(c->root_hash_sig_path); | |
1829 | ||
1830 | return 0; | |
1831 | } | |
1832 | ||
ca9169f4 YW |
1833 | int config_parse_exec_cpu_affinity( |
1834 | const char *unit, | |
1835 | const char *filename, | |
1836 | unsigned line, | |
1837 | const char *section, | |
1838 | unsigned section_line, | |
1839 | const char *lvalue, | |
1840 | int ltype, | |
1841 | const char *rvalue, | |
1842 | void *data, | |
1843 | void *userdata) { | |
94f04347 | 1844 | |
99534007 | 1845 | ExecContext *c = ASSERT_PTR(data); |
54cfe9a7 FG |
1846 | const Unit *u = userdata; |
1847 | _cleanup_free_ char *k = NULL; | |
e2b2fb7f | 1848 | int r; |
94f04347 LP |
1849 | |
1850 | assert(filename); | |
1851 | assert(lvalue); | |
1852 | assert(rvalue); | |
94f04347 | 1853 | |
e2b2fb7f MS |
1854 | if (streq(rvalue, "numa")) { |
1855 | c->cpu_affinity_from_numa = true; | |
1856 | cpu_set_reset(&c->cpu_set); | |
1857 | ||
1858 | return 0; | |
1859 | } | |
1860 | ||
54cfe9a7 FG |
1861 | r = unit_full_printf(u, rvalue, &k); |
1862 | if (r < 0) { | |
1863 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
1864 | "Failed to resolve unit specifiers in '%s', ignoring: %m", | |
1865 | rvalue); | |
1866 | return 0; | |
1867 | } | |
1868 | ||
1869 | r = parse_cpu_set_extend(k, &c->cpu_set, true, unit, filename, line, lvalue); | |
e2b2fb7f MS |
1870 | if (r >= 0) |
1871 | c->cpu_affinity_from_numa = false; | |
1872 | ||
ca9169f4 | 1873 | return 0; |
94f04347 LP |
1874 | } |
1875 | ||
a103496c | 1876 | int config_parse_capability_set( |
65dce264 LP |
1877 | const char *unit, |
1878 | const char *filename, | |
1879 | unsigned line, | |
1880 | const char *section, | |
1881 | unsigned section_line, | |
1882 | const char *lvalue, | |
1883 | int ltype, | |
1884 | const char *rvalue, | |
1885 | void *data, | |
1886 | void *userdata) { | |
94f04347 | 1887 | |
99534007 | 1888 | uint64_t *capability_set = ASSERT_PTR(data); |
3fd5190b | 1889 | uint64_t sum = 0, initial, def; |
260abb78 | 1890 | bool invert = false; |
dd1f5bd0 | 1891 | int r; |
94f04347 LP |
1892 | |
1893 | assert(filename); | |
1894 | assert(lvalue); | |
1895 | assert(rvalue); | |
94f04347 | 1896 | |
260abb78 LP |
1897 | if (rvalue[0] == '~') { |
1898 | invert = true; | |
1899 | rvalue++; | |
1900 | } | |
1901 | ||
3fd5190b LP |
1902 | if (streq(lvalue, "CapabilityBoundingSet")) { |
1903 | initial = CAP_MASK_ALL; /* initialized to all bits on */ | |
1904 | def = CAP_MASK_UNSET; /* not set */ | |
1905 | } else | |
1906 | def = initial = 0; /* All bits off */ | |
260abb78 | 1907 | |
dd1f5bd0 | 1908 | r = capability_set_from_string(rvalue, &sum); |
dd1f5bd0 | 1909 | if (r < 0) { |
323dda78 | 1910 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue, rvalue); |
dd1f5bd0 | 1911 | return 0; |
94f04347 | 1912 | } |
9eba9da4 | 1913 | |
3fd5190b | 1914 | if (sum == 0 || *capability_set == def) |
c792ec2e IP |
1915 | /* "", "~" or uninitialized data -> replace */ |
1916 | *capability_set = invert ? ~sum : sum; | |
1917 | else { | |
a103496c | 1918 | /* previous data -> merge */ |
c792ec2e IP |
1919 | if (invert) |
1920 | *capability_set &= ~sum; | |
1921 | else | |
1922 | *capability_set |= sum; | |
1923 | } | |
260abb78 | 1924 | |
9eba9da4 LP |
1925 | return 0; |
1926 | } | |
1927 | ||
5f8640fb LP |
1928 | int config_parse_exec_selinux_context( |
1929 | const char *unit, | |
1930 | const char *filename, | |
1931 | unsigned line, | |
1932 | const char *section, | |
1933 | unsigned section_line, | |
1934 | const char *lvalue, | |
1935 | int ltype, | |
1936 | const char *rvalue, | |
1937 | void *data, | |
1938 | void *userdata) { | |
1939 | ||
99534007 | 1940 | ExecContext *c = ASSERT_PTR(data); |
47538b76 | 1941 | const Unit *u = userdata; |
5f8640fb LP |
1942 | bool ignore; |
1943 | char *k; | |
1944 | int r; | |
1945 | ||
1946 | assert(filename); | |
1947 | assert(lvalue); | |
1948 | assert(rvalue); | |
5f8640fb LP |
1949 | |
1950 | if (isempty(rvalue)) { | |
a1e58e8e | 1951 | c->selinux_context = mfree(c->selinux_context); |
5f8640fb LP |
1952 | c->selinux_context_ignore = false; |
1953 | return 0; | |
1954 | } | |
1955 | ||
1956 | if (rvalue[0] == '-') { | |
1957 | ignore = true; | |
1958 | rvalue++; | |
1959 | } else | |
1960 | ignore = false; | |
1961 | ||
18913df9 | 1962 | r = unit_full_printf(u, rvalue, &k); |
5f8640fb | 1963 | if (r < 0) { |
323dda78 | 1964 | log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, r, |
063c4b1a YW |
1965 | "Failed to resolve unit specifiers in '%s'%s: %m", |
1966 | rvalue, ignore ? ", ignoring" : ""); | |
bb28e684 | 1967 | return ignore ? 0 : -ENOEXEC; |
5f8640fb LP |
1968 | } |
1969 | ||
063c4b1a | 1970 | free_and_replace(c->selinux_context, k); |
5f8640fb LP |
1971 | c->selinux_context_ignore = ignore; |
1972 | ||
1973 | return 0; | |
1974 | } | |
1975 | ||
eef65bf3 MS |
1976 | int config_parse_exec_apparmor_profile( |
1977 | const char *unit, | |
1978 | const char *filename, | |
1979 | unsigned line, | |
1980 | const char *section, | |
1981 | unsigned section_line, | |
1982 | const char *lvalue, | |
1983 | int ltype, | |
1984 | const char *rvalue, | |
1985 | void *data, | |
1986 | void *userdata) { | |
1987 | ||
99534007 | 1988 | ExecContext *c = ASSERT_PTR(data); |
47538b76 | 1989 | const Unit *u = userdata; |
eef65bf3 MS |
1990 | bool ignore; |
1991 | char *k; | |
1992 | int r; | |
1993 | ||
1994 | assert(filename); | |
1995 | assert(lvalue); | |
1996 | assert(rvalue); | |
eef65bf3 MS |
1997 | |
1998 | if (isempty(rvalue)) { | |
a1e58e8e | 1999 | c->apparmor_profile = mfree(c->apparmor_profile); |
eef65bf3 MS |
2000 | c->apparmor_profile_ignore = false; |
2001 | return 0; | |
2002 | } | |
2003 | ||
2004 | if (rvalue[0] == '-') { | |
2005 | ignore = true; | |
2006 | rvalue++; | |
2007 | } else | |
2008 | ignore = false; | |
2009 | ||
18913df9 | 2010 | r = unit_full_printf(u, rvalue, &k); |
eef65bf3 | 2011 | if (r < 0) { |
323dda78 | 2012 | log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, r, |
063c4b1a YW |
2013 | "Failed to resolve unit specifiers in '%s'%s: %m", |
2014 | rvalue, ignore ? ", ignoring" : ""); | |
bb28e684 | 2015 | return ignore ? 0 : -ENOEXEC; |
eef65bf3 MS |
2016 | } |
2017 | ||
063c4b1a | 2018 | free_and_replace(c->apparmor_profile, k); |
eef65bf3 MS |
2019 | c->apparmor_profile_ignore = ignore; |
2020 | ||
2021 | return 0; | |
2022 | } | |
2023 | ||
2ca620c4 WC |
2024 | int config_parse_exec_smack_process_label( |
2025 | const char *unit, | |
2026 | const char *filename, | |
2027 | unsigned line, | |
2028 | const char *section, | |
2029 | unsigned section_line, | |
2030 | const char *lvalue, | |
2031 | int ltype, | |
2032 | const char *rvalue, | |
2033 | void *data, | |
2034 | void *userdata) { | |
2035 | ||
99534007 | 2036 | ExecContext *c = ASSERT_PTR(data); |
47538b76 | 2037 | const Unit *u = userdata; |
2ca620c4 WC |
2038 | bool ignore; |
2039 | char *k; | |
2040 | int r; | |
2041 | ||
2042 | assert(filename); | |
2043 | assert(lvalue); | |
2044 | assert(rvalue); | |
2ca620c4 WC |
2045 | |
2046 | if (isempty(rvalue)) { | |
a1e58e8e | 2047 | c->smack_process_label = mfree(c->smack_process_label); |
2ca620c4 WC |
2048 | c->smack_process_label_ignore = false; |
2049 | return 0; | |
2050 | } | |
2051 | ||
2052 | if (rvalue[0] == '-') { | |
2053 | ignore = true; | |
2054 | rvalue++; | |
2055 | } else | |
2056 | ignore = false; | |
2057 | ||
18913df9 | 2058 | r = unit_full_printf(u, rvalue, &k); |
2ca620c4 | 2059 | if (r < 0) { |
323dda78 | 2060 | log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, r, |
063c4b1a YW |
2061 | "Failed to resolve unit specifiers in '%s'%s: %m", |
2062 | rvalue, ignore ? ", ignoring" : ""); | |
bb28e684 | 2063 | return ignore ? 0 : -ENOEXEC; |
2ca620c4 WC |
2064 | } |
2065 | ||
063c4b1a | 2066 | free_and_replace(c->smack_process_label, k); |
2ca620c4 WC |
2067 | c->smack_process_label_ignore = ignore; |
2068 | ||
2069 | return 0; | |
2070 | } | |
2071 | ||
25a04ae5 LP |
2072 | int config_parse_timer( |
2073 | const char *unit, | |
2074 | const char *filename, | |
2075 | unsigned line, | |
2076 | const char *section, | |
2077 | unsigned section_line, | |
2078 | const char *lvalue, | |
2079 | int ltype, | |
2080 | const char *rvalue, | |
2081 | void *data, | |
2082 | void *userdata) { | |
871d7de4 | 2083 | |
25a04ae5 LP |
2084 | _cleanup_(calendar_spec_freep) CalendarSpec *c = NULL; |
2085 | _cleanup_free_ char *k = NULL; | |
47538b76 | 2086 | const Unit *u = userdata; |
99534007 | 2087 | Timer *t = ASSERT_PTR(data); |
2507992f | 2088 | usec_t usec = 0; |
871d7de4 | 2089 | TimerValue *v; |
2507992f | 2090 | int r; |
871d7de4 LP |
2091 | |
2092 | assert(filename); | |
2093 | assert(lvalue); | |
2094 | assert(rvalue); | |
871d7de4 | 2095 | |
74051b9b LP |
2096 | if (isempty(rvalue)) { |
2097 | /* Empty assignment resets list */ | |
2098 | timer_free_values(t); | |
2099 | return 0; | |
2100 | } | |
2101 | ||
2507992f DC |
2102 | r = unit_full_printf(u, rvalue, &k); |
2103 | if (r < 0) { | |
323dda78 | 2104 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
2507992f DC |
2105 | return 0; |
2106 | } | |
2107 | ||
25a04ae5 | 2108 | if (ltype == TIMER_CALENDAR) { |
dc44c96d LP |
2109 | r = calendar_spec_from_string(k, &c); |
2110 | if (r < 0) { | |
323dda78 | 2111 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse calendar specification, ignoring: %s", k); |
36697dc0 LP |
2112 | return 0; |
2113 | } | |
dc44c96d LP |
2114 | } else { |
2115 | r = parse_sec(k, &usec); | |
2116 | if (r < 0) { | |
323dda78 | 2117 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse timer value, ignoring: %s", k); |
36697dc0 LP |
2118 | return 0; |
2119 | } | |
dc44c96d | 2120 | } |
871d7de4 | 2121 | |
25a04ae5 | 2122 | v = new(TimerValue, 1); |
921b5987 | 2123 | if (!v) |
74051b9b | 2124 | return log_oom(); |
871d7de4 | 2125 | |
25a04ae5 LP |
2126 | *v = (TimerValue) { |
2127 | .base = ltype, | |
2128 | .value = usec, | |
2129 | .calendar_spec = TAKE_PTR(c), | |
2130 | }; | |
871d7de4 | 2131 | |
71fda00f | 2132 | LIST_PREPEND(value, t->values, v); |
871d7de4 LP |
2133 | |
2134 | return 0; | |
2135 | } | |
2136 | ||
3ecaa09b LP |
2137 | int config_parse_trigger_unit( |
2138 | const char *unit, | |
2139 | const char *filename, | |
2140 | unsigned line, | |
2141 | const char *section, | |
71a61510 | 2142 | unsigned section_line, |
3ecaa09b LP |
2143 | const char *lvalue, |
2144 | int ltype, | |
2145 | const char *rvalue, | |
2146 | void *data, | |
2147 | void *userdata) { | |
871d7de4 | 2148 | |
74051b9b | 2149 | _cleanup_free_ char *p = NULL; |
99534007 | 2150 | Unit *u = ASSERT_PTR(data); |
3ecaa09b LP |
2151 | UnitType type; |
2152 | int r; | |
398ef8ba LP |
2153 | |
2154 | assert(filename); | |
2155 | assert(lvalue); | |
2156 | assert(rvalue); | |
398ef8ba | 2157 | |
bc32241e | 2158 | if (UNIT_TRIGGER(u)) { |
323dda78 | 2159 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Multiple units to trigger specified, ignoring: %s", rvalue); |
3ecaa09b LP |
2160 | return 0; |
2161 | } | |
871d7de4 | 2162 | |
19f6d710 | 2163 | r = unit_name_printf(u, rvalue, &p); |
12ca818f | 2164 | if (r < 0) { |
323dda78 | 2165 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue); |
12ca818f LP |
2166 | return 0; |
2167 | } | |
74051b9b | 2168 | |
12ca818f | 2169 | type = unit_name_to_type(p); |
3ecaa09b | 2170 | if (type < 0) { |
b98680b2 | 2171 | log_syntax(unit, LOG_WARNING, filename, line, type, "Unit type not valid, ignoring: %s", rvalue); |
c0b34696 | 2172 | return 0; |
871d7de4 | 2173 | } |
49219a1c | 2174 | if (unit_has_name(u, p)) { |
323dda78 | 2175 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Units cannot trigger themselves, ignoring: %s", rvalue); |
3ecaa09b LP |
2176 | return 0; |
2177 | } | |
2178 | ||
5a724170 | 2179 | r = unit_add_two_dependencies_by_name(u, UNIT_BEFORE, UNIT_TRIGGERS, p, true, UNIT_DEPENDENCY_FILE); |
57020a3a | 2180 | if (r < 0) { |
323dda78 | 2181 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to add trigger on %s, ignoring: %m", p); |
c0b34696 | 2182 | return 0; |
871d7de4 LP |
2183 | } |
2184 | ||
2185 | return 0; | |
2186 | } | |
2187 | ||
e8e581bf ZJS |
2188 | int config_parse_path_spec(const char *unit, |
2189 | const char *filename, | |
2190 | unsigned line, | |
2191 | const char *section, | |
71a61510 | 2192 | unsigned section_line, |
e8e581bf ZJS |
2193 | const char *lvalue, |
2194 | int ltype, | |
2195 | const char *rvalue, | |
2196 | void *data, | |
2197 | void *userdata) { | |
01f78473 | 2198 | |
99534007 | 2199 | Path *p = ASSERT_PTR(data); |
01f78473 LP |
2200 | PathSpec *s; |
2201 | PathType b; | |
7fd1b19b | 2202 | _cleanup_free_ char *k = NULL; |
19f6d710 | 2203 | int r; |
01f78473 LP |
2204 | |
2205 | assert(filename); | |
2206 | assert(lvalue); | |
2207 | assert(rvalue); | |
01f78473 | 2208 | |
74051b9b LP |
2209 | if (isempty(rvalue)) { |
2210 | /* Empty assignment clears list */ | |
2211 | path_free_specs(p); | |
2212 | return 0; | |
2213 | } | |
2214 | ||
93e4c84b LP |
2215 | b = path_type_from_string(lvalue); |
2216 | if (b < 0) { | |
b98680b2 | 2217 | log_syntax(unit, LOG_WARNING, filename, line, b, "Failed to parse path type, ignoring: %s", lvalue); |
c0b34696 | 2218 | return 0; |
01f78473 LP |
2219 | } |
2220 | ||
06536492 | 2221 | r = unit_path_printf(UNIT(p), rvalue, &k); |
19f6d710 | 2222 | if (r < 0) { |
323dda78 | 2223 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue); |
12ca818f | 2224 | return 0; |
487060c2 | 2225 | } |
93e4c84b | 2226 | |
2f4d31c1 YW |
2227 | r = path_simplify_and_warn(k, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
2228 | if (r < 0) | |
c0b34696 | 2229 | return 0; |
01f78473 | 2230 | |
93e4c84b | 2231 | s = new0(PathSpec, 1); |
543295ad | 2232 | if (!s) |
93e4c84b | 2233 | return log_oom(); |
01f78473 | 2234 | |
718db961 | 2235 | s->unit = UNIT(p); |
063c4b1a | 2236 | s->path = TAKE_PTR(k); |
01f78473 | 2237 | s->type = b; |
254d1313 | 2238 | s->inotify_fd = -EBADF; |
01f78473 | 2239 | |
71fda00f | 2240 | LIST_PREPEND(spec, p->specs, s); |
01f78473 LP |
2241 | |
2242 | return 0; | |
2243 | } | |
2244 | ||
b02cb41c LP |
2245 | int config_parse_socket_service( |
2246 | const char *unit, | |
2247 | const char *filename, | |
2248 | unsigned line, | |
2249 | const char *section, | |
2250 | unsigned section_line, | |
2251 | const char *lvalue, | |
2252 | int ltype, | |
2253 | const char *rvalue, | |
2254 | void *data, | |
2255 | void *userdata) { | |
d9ff321a | 2256 | |
4afd3348 | 2257 | _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; |
8dd4c05b | 2258 | _cleanup_free_ char *p = NULL; |
99534007 | 2259 | Socket *s = ASSERT_PTR(data); |
4ff77f66 | 2260 | Unit *x; |
8dd4c05b | 2261 | int r; |
d9ff321a LP |
2262 | |
2263 | assert(filename); | |
2264 | assert(lvalue); | |
2265 | assert(rvalue); | |
d9ff321a | 2266 | |
19f6d710 | 2267 | r = unit_name_printf(UNIT(s), rvalue, &p); |
613b411c | 2268 | if (r < 0) { |
323dda78 YW |
2269 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue); |
2270 | return 0; | |
613b411c | 2271 | } |
74051b9b | 2272 | |
613b411c | 2273 | if (!endswith(p, ".service")) { |
323dda78 YW |
2274 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Unit must be of type service, ignoring: %s", rvalue); |
2275 | return 0; | |
d9ff321a LP |
2276 | } |
2277 | ||
613b411c | 2278 | r = manager_load_unit(UNIT(s)->manager, p, NULL, &error, &x); |
4ff77f66 | 2279 | if (r < 0) { |
323dda78 YW |
2280 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to load unit %s, ignoring: %s", rvalue, bus_error_message(&error, r)); |
2281 | return 0; | |
d9ff321a LP |
2282 | } |
2283 | ||
7f7d01ed | 2284 | unit_ref_set(&s->service, UNIT(s), x); |
4ff77f66 | 2285 | |
d9ff321a LP |
2286 | return 0; |
2287 | } | |
2288 | ||
8dd4c05b LP |
2289 | int config_parse_fdname( |
2290 | const char *unit, | |
2291 | const char *filename, | |
2292 | unsigned line, | |
2293 | const char *section, | |
2294 | unsigned section_line, | |
2295 | const char *lvalue, | |
2296 | int ltype, | |
2297 | const char *rvalue, | |
2298 | void *data, | |
2299 | void *userdata) { | |
2300 | ||
2301 | _cleanup_free_ char *p = NULL; | |
99534007 | 2302 | Socket *s = ASSERT_PTR(data); |
8dd4c05b LP |
2303 | int r; |
2304 | ||
2305 | assert(filename); | |
2306 | assert(lvalue); | |
2307 | assert(rvalue); | |
8dd4c05b LP |
2308 | |
2309 | if (isempty(rvalue)) { | |
2310 | s->fdname = mfree(s->fdname); | |
2311 | return 0; | |
2312 | } | |
2313 | ||
06536492 | 2314 | r = unit_fd_printf(UNIT(s), rvalue, &p); |
8dd4c05b | 2315 | if (r < 0) { |
323dda78 | 2316 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
8dd4c05b LP |
2317 | return 0; |
2318 | } | |
2319 | ||
2320 | if (!fdname_is_valid(p)) { | |
323dda78 | 2321 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid file descriptor name, ignoring: %s", p); |
8dd4c05b LP |
2322 | return 0; |
2323 | } | |
2324 | ||
3b319885 | 2325 | return free_and_replace(s->fdname, p); |
8dd4c05b LP |
2326 | } |
2327 | ||
b02cb41c LP |
2328 | int config_parse_service_sockets( |
2329 | const char *unit, | |
2330 | const char *filename, | |
2331 | unsigned line, | |
2332 | const char *section, | |
2333 | unsigned section_line, | |
2334 | const char *lvalue, | |
2335 | int ltype, | |
2336 | const char *rvalue, | |
2337 | void *data, | |
2338 | void *userdata) { | |
f976f3f6 | 2339 | |
99534007 | 2340 | Service *s = ASSERT_PTR(data); |
b02cb41c | 2341 | int r; |
f976f3f6 LP |
2342 | |
2343 | assert(filename); | |
2344 | assert(lvalue); | |
2345 | assert(rvalue); | |
f976f3f6 | 2346 | |
323dda78 | 2347 | for (const char *p = rvalue;;) { |
6a0f3175 | 2348 | _cleanup_free_ char *word = NULL, *k = NULL; |
f976f3f6 | 2349 | |
7b2313f5 | 2350 | r = extract_first_word(&p, &word, NULL, 0); |
7b2313f5 | 2351 | if (r == -ENOMEM) |
74051b9b | 2352 | return log_oom(); |
7b2313f5 | 2353 | if (r < 0) { |
323dda78 YW |
2354 | log_syntax(unit, LOG_WARNING, filename, line, r, "Trailing garbage in sockets, ignoring: %s", rvalue); |
2355 | return 0; | |
7b2313f5 | 2356 | } |
a687f500 ZJS |
2357 | if (r == 0) |
2358 | return 0; | |
f976f3f6 | 2359 | |
7b2313f5 | 2360 | r = unit_name_printf(UNIT(s), word, &k); |
b02cb41c | 2361 | if (r < 0) { |
323dda78 | 2362 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", word); |
b02cb41c LP |
2363 | continue; |
2364 | } | |
57020a3a | 2365 | |
b02cb41c | 2366 | if (!endswith(k, ".socket")) { |
323dda78 | 2367 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Unit must be of type socket, ignoring: %s", k); |
f976f3f6 LP |
2368 | continue; |
2369 | } | |
2370 | ||
5a724170 | 2371 | r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_WANTS, UNIT_AFTER, k, true, UNIT_DEPENDENCY_FILE); |
57020a3a | 2372 | if (r < 0) |
323dda78 | 2373 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to add dependency on %s, ignoring: %m", k); |
f976f3f6 | 2374 | |
35d8c19a | 2375 | r = unit_add_dependency_by_name(UNIT(s), UNIT_TRIGGERED_BY, k, true, UNIT_DEPENDENCY_FILE); |
57020a3a | 2376 | if (r < 0) |
323dda78 | 2377 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to add dependency on %s, ignoring: %m", k); |
f976f3f6 | 2378 | } |
f976f3f6 LP |
2379 | } |
2380 | ||
b02cb41c LP |
2381 | int config_parse_bus_name( |
2382 | const char *unit, | |
2383 | const char *filename, | |
2384 | unsigned line, | |
2385 | const char *section, | |
2386 | unsigned section_line, | |
2387 | const char *lvalue, | |
2388 | int ltype, | |
2389 | const char *rvalue, | |
2390 | void *data, | |
2391 | void *userdata) { | |
2392 | ||
2393 | _cleanup_free_ char *k = NULL; | |
99534007 | 2394 | const Unit *u = ASSERT_PTR(userdata); |
b02cb41c LP |
2395 | int r; |
2396 | ||
2397 | assert(filename); | |
2398 | assert(lvalue); | |
2399 | assert(rvalue); | |
b02cb41c | 2400 | |
06536492 | 2401 | r = unit_full_printf_full(u, rvalue, SD_BUS_MAXIMUM_NAME_LENGTH, &k); |
b02cb41c | 2402 | if (r < 0) { |
323dda78 | 2403 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue); |
b02cb41c LP |
2404 | return 0; |
2405 | } | |
2406 | ||
5453a4b1 | 2407 | if (!sd_bus_service_name_is_valid(k)) { |
323dda78 | 2408 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid bus name, ignoring: %s", k); |
b02cb41c LP |
2409 | return 0; |
2410 | } | |
2411 | ||
2412 | return config_parse_string(unit, filename, line, section, section_line, lvalue, ltype, k, data, userdata); | |
2413 | } | |
2414 | ||
aad41f08 LP |
2415 | int config_parse_service_timeout( |
2416 | const char *unit, | |
2417 | const char *filename, | |
2418 | unsigned line, | |
2419 | const char *section, | |
2420 | unsigned section_line, | |
2421 | const char *lvalue, | |
2422 | int ltype, | |
2423 | const char *rvalue, | |
2424 | void *data, | |
2425 | void *userdata) { | |
98709151 | 2426 | |
99534007 | 2427 | Service *s = ASSERT_PTR(userdata); |
aad41f08 | 2428 | usec_t usec; |
98709151 LN |
2429 | int r; |
2430 | ||
2431 | assert(filename); | |
2432 | assert(lvalue); | |
2433 | assert(rvalue); | |
98709151 | 2434 | |
6c58305a | 2435 | /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */ |
98709151 | 2436 | |
fb27be3f YW |
2437 | /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens |
2438 | * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle | |
2439 | * all other timeouts. */ | |
2440 | r = parse_sec_fix_0(rvalue, &usec); | |
aad41f08 | 2441 | if (r < 0) { |
323dda78 | 2442 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s= parameter, ignoring: %s", lvalue, rvalue); |
aad41f08 LP |
2443 | return 0; |
2444 | } | |
d568a335 | 2445 | |
6c58305a YW |
2446 | s->start_timeout_defined = true; |
2447 | s->timeout_start_usec = usec; | |
36c16a7c | 2448 | |
6c58305a | 2449 | if (streq(lvalue, "TimeoutSec")) |
aad41f08 | 2450 | s->timeout_stop_usec = usec; |
36c16a7c | 2451 | |
d568a335 | 2452 | return 0; |
98709151 LN |
2453 | } |
2454 | ||
a61d6874 | 2455 | int config_parse_timeout_abort( |
dc653bf4 JK |
2456 | const char *unit, |
2457 | const char *filename, | |
2458 | unsigned line, | |
2459 | const char *section, | |
2460 | unsigned section_line, | |
2461 | const char *lvalue, | |
2462 | int ltype, | |
2463 | const char *rvalue, | |
2464 | void *data, | |
2465 | void *userdata) { | |
2466 | ||
99534007 | 2467 | usec_t *ret = ASSERT_PTR(data); |
dc653bf4 JK |
2468 | int r; |
2469 | ||
2470 | assert(filename); | |
2471 | assert(lvalue); | |
2472 | assert(rvalue); | |
a61d6874 ZJS |
2473 | |
2474 | /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */ | |
dc653bf4 | 2475 | |
dc653bf4 | 2476 | if (isempty(rvalue)) { |
a61d6874 ZJS |
2477 | *ret = 0; |
2478 | return 0; /* "not set" */ | |
dc653bf4 JK |
2479 | } |
2480 | ||
a61d6874 ZJS |
2481 | r = parse_sec(rvalue, ret); |
2482 | if (r < 0) | |
323dda78 | 2483 | return log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s= setting, ignoring: %s", lvalue, rvalue); |
a61d6874 ZJS |
2484 | |
2485 | return 1; /* "set" */ | |
2486 | } | |
2487 | ||
2488 | int config_parse_service_timeout_abort( | |
2489 | const char *unit, | |
2490 | const char *filename, | |
2491 | unsigned line, | |
2492 | const char *section, | |
2493 | unsigned section_line, | |
2494 | const char *lvalue, | |
2495 | int ltype, | |
2496 | const char *rvalue, | |
2497 | void *data, | |
2498 | void *userdata) { | |
2499 | ||
99534007 | 2500 | Service *s = ASSERT_PTR(userdata); |
a61d6874 | 2501 | int r; |
dc653bf4 | 2502 | |
a61d6874 ZJS |
2503 | r = config_parse_timeout_abort(unit, filename, line, section, section_line, lvalue, ltype, rvalue, |
2504 | &s->timeout_abort_usec, s); | |
2505 | if (r >= 0) | |
2506 | s->timeout_abort_set = r; | |
dc653bf4 JK |
2507 | return 0; |
2508 | } | |
2509 | ||
ae480f0b | 2510 | int config_parse_user_group_compat( |
66dccd8d LP |
2511 | const char *unit, |
2512 | const char *filename, | |
2513 | unsigned line, | |
2514 | const char *section, | |
2515 | unsigned section_line, | |
2516 | const char *lvalue, | |
2517 | int ltype, | |
2518 | const char *rvalue, | |
2519 | void *data, | |
2520 | void *userdata) { | |
2521 | ||
063c4b1a YW |
2522 | _cleanup_free_ char *k = NULL; |
2523 | char **user = data; | |
99534007 | 2524 | const Unit *u = ASSERT_PTR(userdata); |
66dccd8d LP |
2525 | int r; |
2526 | ||
2527 | assert(filename); | |
2528 | assert(lvalue); | |
2529 | assert(rvalue); | |
66dccd8d | 2530 | |
063c4b1a YW |
2531 | if (isempty(rvalue)) { |
2532 | *user = mfree(*user); | |
2533 | return 0; | |
2534 | } | |
66dccd8d | 2535 | |
063c4b1a YW |
2536 | r = unit_full_printf(u, rvalue, &k); |
2537 | if (r < 0) { | |
2538 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s: %m", rvalue); | |
2539 | return -ENOEXEC; | |
66dccd8d LP |
2540 | } |
2541 | ||
7a8867ab | 2542 | if (!valid_user_group_name(k, VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX|VALID_USER_WARN)) { |
063c4b1a YW |
2543 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid user/group name or numeric ID: %s", k); |
2544 | return -ENOEXEC; | |
2545 | } | |
66dccd8d | 2546 | |
bed0b7df LP |
2547 | if (strstr(lvalue, "User") && streq(k, NOBODY_USER_NAME)) |
2548 | log_struct(LOG_NOTICE, | |
2549 | "MESSAGE=%s:%u: Special user %s configured, this is not safe!", filename, line, k, | |
2550 | "UNIT=%s", unit, | |
2551 | "MESSAGE_ID=" SD_MESSAGE_NOBODY_USER_UNSUITABLE_STR, | |
2552 | "OFFENDING_USER=%s", k, | |
2553 | "CONFIG_FILE=%s", filename, | |
2554 | "CONFIG_LINE=%u", line); | |
2555 | ||
063c4b1a | 2556 | return free_and_replace(*user, k); |
66dccd8d LP |
2557 | } |
2558 | ||
ae480f0b | 2559 | int config_parse_user_group_strv_compat( |
66dccd8d LP |
2560 | const char *unit, |
2561 | const char *filename, | |
2562 | unsigned line, | |
2563 | const char *section, | |
2564 | unsigned section_line, | |
2565 | const char *lvalue, | |
2566 | int ltype, | |
2567 | const char *rvalue, | |
2568 | void *data, | |
2569 | void *userdata) { | |
2570 | ||
2571 | char ***users = data; | |
99534007 | 2572 | const Unit *u = ASSERT_PTR(userdata); |
66dccd8d LP |
2573 | int r; |
2574 | ||
2575 | assert(filename); | |
2576 | assert(lvalue); | |
2577 | assert(rvalue); | |
66dccd8d LP |
2578 | |
2579 | if (isempty(rvalue)) { | |
9f2d41a6 | 2580 | *users = strv_free(*users); |
66dccd8d LP |
2581 | return 0; |
2582 | } | |
2583 | ||
323dda78 | 2584 | for (const char *p = rvalue;;) { |
66dccd8d LP |
2585 | _cleanup_free_ char *word = NULL, *k = NULL; |
2586 | ||
9a82ab95 | 2587 | r = extract_first_word(&p, &word, NULL, 0); |
66dccd8d LP |
2588 | if (r == -ENOMEM) |
2589 | return log_oom(); | |
2590 | if (r < 0) { | |
bb28e684 ZJS |
2591 | log_syntax(unit, LOG_ERR, filename, line, r, "Invalid syntax: %s", rvalue); |
2592 | return -ENOEXEC; | |
66dccd8d | 2593 | } |
a687f500 ZJS |
2594 | if (r == 0) |
2595 | return 0; | |
66dccd8d LP |
2596 | |
2597 | r = unit_full_printf(u, word, &k); | |
2598 | if (r < 0) { | |
bb28e684 ZJS |
2599 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s: %m", word); |
2600 | return -ENOEXEC; | |
66dccd8d LP |
2601 | } |
2602 | ||
7a8867ab | 2603 | if (!valid_user_group_name(k, VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX|VALID_USER_WARN)) { |
bb28e684 ZJS |
2604 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid user/group name or numeric ID: %s", k); |
2605 | return -ENOEXEC; | |
66dccd8d LP |
2606 | } |
2607 | ||
2608 | r = strv_push(users, k); | |
2609 | if (r < 0) | |
2610 | return log_oom(); | |
2611 | ||
2612 | k = NULL; | |
2613 | } | |
66dccd8d LP |
2614 | } |
2615 | ||
5f5d8eab LP |
2616 | int config_parse_working_directory( |
2617 | const char *unit, | |
2618 | const char *filename, | |
2619 | unsigned line, | |
2620 | const char *section, | |
2621 | unsigned section_line, | |
2622 | const char *lvalue, | |
2623 | int ltype, | |
2624 | const char *rvalue, | |
2625 | void *data, | |
2626 | void *userdata) { | |
2627 | ||
99534007 DT |
2628 | ExecContext *c = ASSERT_PTR(data); |
2629 | const Unit *u = ASSERT_PTR(userdata); | |
5f5d8eab LP |
2630 | bool missing_ok; |
2631 | int r; | |
2632 | ||
2633 | assert(filename); | |
2634 | assert(lvalue); | |
2635 | assert(rvalue); | |
5f5d8eab | 2636 | |
862fcffd YW |
2637 | if (isempty(rvalue)) { |
2638 | c->working_directory_home = false; | |
2639 | c->working_directory = mfree(c->working_directory); | |
2640 | return 0; | |
2641 | } | |
2642 | ||
5f5d8eab LP |
2643 | if (rvalue[0] == '-') { |
2644 | missing_ok = true; | |
2645 | rvalue++; | |
2646 | } else | |
2647 | missing_ok = false; | |
2648 | ||
2649 | if (streq(rvalue, "~")) { | |
2650 | c->working_directory_home = true; | |
2651 | c->working_directory = mfree(c->working_directory); | |
2652 | } else { | |
2653 | _cleanup_free_ char *k = NULL; | |
2654 | ||
06536492 | 2655 | r = unit_path_printf(u, rvalue, &k); |
5f5d8eab | 2656 | if (r < 0) { |
323dda78 | 2657 | log_syntax(unit, missing_ok ? LOG_WARNING : LOG_ERR, filename, line, r, |
bb28e684 ZJS |
2658 | "Failed to resolve unit specifiers in working directory path '%s'%s: %m", |
2659 | rvalue, missing_ok ? ", ignoring" : ""); | |
2660 | return missing_ok ? 0 : -ENOEXEC; | |
5f5d8eab LP |
2661 | } |
2662 | ||
2f4d31c1 YW |
2663 | r = path_simplify_and_warn(k, PATH_CHECK_ABSOLUTE | (missing_ok ? 0 : PATH_CHECK_FATAL), unit, filename, line, lvalue); |
2664 | if (r < 0) | |
bb28e684 | 2665 | return missing_ok ? 0 : -ENOEXEC; |
5f5d8eab | 2666 | |
5f5d8eab | 2667 | c->working_directory_home = false; |
bb28e684 | 2668 | free_and_replace(c->working_directory, k); |
5f5d8eab LP |
2669 | } |
2670 | ||
2671 | c->working_directory_missing_ok = missing_ok; | |
2672 | return 0; | |
2673 | } | |
2674 | ||
e8e581bf ZJS |
2675 | int config_parse_unit_env_file(const char *unit, |
2676 | const char *filename, | |
2677 | unsigned line, | |
2678 | const char *section, | |
71a61510 | 2679 | unsigned section_line, |
e8e581bf ZJS |
2680 | const char *lvalue, |
2681 | int ltype, | |
2682 | const char *rvalue, | |
2683 | void *data, | |
2684 | void *userdata) { | |
ddb26e18 | 2685 | |
99534007 | 2686 | char ***env = ASSERT_PTR(data); |
47538b76 | 2687 | const Unit *u = userdata; |
19f6d710 | 2688 | _cleanup_free_ char *n = NULL; |
853b8397 | 2689 | int r; |
ddb26e18 LP |
2690 | |
2691 | assert(filename); | |
2692 | assert(lvalue); | |
2693 | assert(rvalue); | |
ddb26e18 | 2694 | |
74051b9b LP |
2695 | if (isempty(rvalue)) { |
2696 | /* Empty assignment frees the list */ | |
6796073e | 2697 | *env = strv_free(*env); |
74051b9b LP |
2698 | return 0; |
2699 | } | |
2700 | ||
e195a5c1 | 2701 | r = unit_path_printf(u, rvalue, &n); |
12ca818f | 2702 | if (r < 0) { |
323dda78 | 2703 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
12ca818f LP |
2704 | return 0; |
2705 | } | |
8fef7659 | 2706 | |
2f4d31c1 YW |
2707 | r = path_simplify_and_warn(n[0] == '-' ? n + 1 : n, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
2708 | if (r < 0) | |
afe4bfe2 | 2709 | return 0; |
afe4bfe2 | 2710 | |
2f4d31c1 | 2711 | r = strv_push(env, n); |
853b8397 LP |
2712 | if (r < 0) |
2713 | return log_oom(); | |
2714 | ||
2f4d31c1 YW |
2715 | n = NULL; |
2716 | ||
853b8397 LP |
2717 | return 0; |
2718 | } | |
2719 | ||
f7f3f5c3 LP |
2720 | int config_parse_environ( |
2721 | const char *unit, | |
2722 | const char *filename, | |
2723 | unsigned line, | |
2724 | const char *section, | |
2725 | unsigned section_line, | |
2726 | const char *lvalue, | |
2727 | int ltype, | |
2728 | const char *rvalue, | |
2729 | void *data, | |
2730 | void *userdata) { | |
853b8397 | 2731 | |
47538b76 | 2732 | const Unit *u = userdata; |
99534007 | 2733 | char ***env = ASSERT_PTR(data); |
19f6d710 | 2734 | int r; |
853b8397 LP |
2735 | |
2736 | assert(filename); | |
2737 | assert(lvalue); | |
2738 | assert(rvalue); | |
853b8397 LP |
2739 | |
2740 | if (isempty(rvalue)) { | |
2741 | /* Empty assignment resets the list */ | |
6796073e | 2742 | *env = strv_free(*env); |
853b8397 LP |
2743 | return 0; |
2744 | } | |
2745 | ||
4870133b LP |
2746 | /* If 'u' is set, we operate on the regular unit specifier table. Otherwise we use a manager-specific |
2747 | * specifier table (in which case ltype must contain the runtime scope). */ | |
2748 | const Specifier *table = u ? NULL : (const Specifier[]) { | |
0b40688d RP |
2749 | COMMON_SYSTEM_SPECIFIERS, |
2750 | COMMON_TMP_SPECIFIERS, | |
4870133b | 2751 | COMMON_CREDS_SPECIFIERS(ltype), |
0b40688d RP |
2752 | { 'h', specifier_user_home, NULL }, |
2753 | { 's', specifier_user_shell, NULL }, | |
2754 | }; | |
2755 | ||
323dda78 | 2756 | for (const char *p = rvalue;; ) { |
13734c75 | 2757 | _cleanup_free_ char *word = NULL, *resolved = NULL; |
035fe294 | 2758 | |
4ec85141 | 2759 | r = extract_first_word(&p, &word, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE); |
035fe294 ZJS |
2760 | if (r == -ENOMEM) |
2761 | return log_oom(); | |
12ca818f | 2762 | if (r < 0) { |
035fe294 ZJS |
2763 | log_syntax(unit, LOG_WARNING, filename, line, r, |
2764 | "Invalid syntax, ignoring: %s", rvalue); | |
12ca818f LP |
2765 | return 0; |
2766 | } | |
a687f500 ZJS |
2767 | if (r == 0) |
2768 | return 0; | |
97d0e5f8 | 2769 | |
4870133b | 2770 | if (table) |
0b40688d | 2771 | r = specifier_printf(word, sc_arg_max(), table, NULL, NULL, &resolved); |
4870133b LP |
2772 | else |
2773 | r = unit_env_printf(u, word, &resolved); | |
46a9ee5d LP |
2774 | if (r < 0) { |
2775 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
2776 | "Failed to resolve specifiers in %s, ignoring: %m", word); | |
2777 | continue; | |
2778 | } | |
853b8397 | 2779 | |
13734c75 | 2780 | if (!env_assignment_is_valid(resolved)) { |
323dda78 | 2781 | log_syntax(unit, LOG_WARNING, filename, line, 0, |
13734c75 | 2782 | "Invalid environment assignment, ignoring: %s", resolved); |
853b8397 LP |
2783 | continue; |
2784 | } | |
2785 | ||
13734c75 | 2786 | r = strv_env_replace_consume(env, TAKE_PTR(resolved)); |
54ac3494 | 2787 | if (r < 0) |
13734c75 | 2788 | return log_error_errno(r, "Failed to update environment: %m"); |
853b8397 | 2789 | } |
ddb26e18 LP |
2790 | } |
2791 | ||
00819cc1 LP |
2792 | int config_parse_pass_environ( |
2793 | const char *unit, | |
2794 | const char *filename, | |
2795 | unsigned line, | |
2796 | const char *section, | |
2797 | unsigned section_line, | |
2798 | const char *lvalue, | |
2799 | int ltype, | |
2800 | const char *rvalue, | |
2801 | void *data, | |
2802 | void *userdata) { | |
b4c14404 | 2803 | |
b4c14404 | 2804 | _cleanup_strv_free_ char **n = NULL; |
47538b76 | 2805 | const Unit *u = userdata; |
99534007 | 2806 | char*** passenv = ASSERT_PTR(data); |
319a4f4b | 2807 | size_t nlen = 0; |
b4c14404 FB |
2808 | int r; |
2809 | ||
2810 | assert(filename); | |
2811 | assert(lvalue); | |
2812 | assert(rvalue); | |
b4c14404 FB |
2813 | |
2814 | if (isempty(rvalue)) { | |
2815 | /* Empty assignment resets the list */ | |
2816 | *passenv = strv_free(*passenv); | |
2817 | return 0; | |
2818 | } | |
2819 | ||
323dda78 | 2820 | for (const char *p = rvalue;;) { |
41de9cc2 | 2821 | _cleanup_free_ char *word = NULL, *k = NULL; |
b4c14404 | 2822 | |
4ec85141 | 2823 | r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); |
b4c14404 FB |
2824 | if (r == -ENOMEM) |
2825 | return log_oom(); | |
2826 | if (r < 0) { | |
323dda78 | 2827 | log_syntax(unit, LOG_WARNING, filename, line, r, |
063c4b1a | 2828 | "Trailing garbage in %s, ignoring: %s", lvalue, rvalue); |
b4c14404 FB |
2829 | break; |
2830 | } | |
a687f500 ZJS |
2831 | if (r == 0) |
2832 | break; | |
b4c14404 | 2833 | |
41de9cc2 | 2834 | if (u) { |
06536492 | 2835 | r = unit_env_printf(u, word, &k); |
41de9cc2 | 2836 | if (r < 0) { |
323dda78 | 2837 | log_syntax(unit, LOG_WARNING, filename, line, r, |
063c4b1a | 2838 | "Failed to resolve specifiers in %s, ignoring: %m", word); |
41de9cc2 LP |
2839 | continue; |
2840 | } | |
ae2a15bc LP |
2841 | } else |
2842 | k = TAKE_PTR(word); | |
41de9cc2 LP |
2843 | |
2844 | if (!env_name_is_valid(k)) { | |
323dda78 | 2845 | log_syntax(unit, LOG_WARNING, filename, line, 0, |
41de9cc2 | 2846 | "Invalid environment name for %s, ignoring: %s", lvalue, k); |
b4c14404 FB |
2847 | continue; |
2848 | } | |
2849 | ||
319a4f4b | 2850 | if (!GREEDY_REALLOC(n, nlen + 2)) |
b4c14404 | 2851 | return log_oom(); |
41de9cc2 | 2852 | |
1cc6c93a | 2853 | n[nlen++] = TAKE_PTR(k); |
b4c14404 | 2854 | n[nlen] = NULL; |
b4c14404 FB |
2855 | } |
2856 | ||
2857 | if (n) { | |
2858 | r = strv_extend_strv(passenv, n, true); | |
2859 | if (r < 0) | |
16eb0c4a | 2860 | return log_oom(); |
b4c14404 FB |
2861 | } |
2862 | ||
2863 | return 0; | |
2864 | } | |
2865 | ||
00819cc1 LP |
2866 | int config_parse_unset_environ( |
2867 | const char *unit, | |
2868 | const char *filename, | |
2869 | unsigned line, | |
2870 | const char *section, | |
2871 | unsigned section_line, | |
2872 | const char *lvalue, | |
2873 | int ltype, | |
2874 | const char *rvalue, | |
2875 | void *data, | |
2876 | void *userdata) { | |
2877 | ||
2878 | _cleanup_strv_free_ char **n = NULL; | |
99534007 | 2879 | char*** unsetenv = ASSERT_PTR(data); |
47538b76 | 2880 | const Unit *u = userdata; |
319a4f4b | 2881 | size_t nlen = 0; |
00819cc1 LP |
2882 | int r; |
2883 | ||
2884 | assert(filename); | |
2885 | assert(lvalue); | |
2886 | assert(rvalue); | |
00819cc1 LP |
2887 | |
2888 | if (isempty(rvalue)) { | |
2889 | /* Empty assignment resets the list */ | |
2890 | *unsetenv = strv_free(*unsetenv); | |
2891 | return 0; | |
2892 | } | |
2893 | ||
323dda78 | 2894 | for (const char *p = rvalue;;) { |
00819cc1 LP |
2895 | _cleanup_free_ char *word = NULL, *k = NULL; |
2896 | ||
4ec85141 | 2897 | r = extract_first_word(&p, &word, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE); |
00819cc1 LP |
2898 | if (r == -ENOMEM) |
2899 | return log_oom(); | |
2900 | if (r < 0) { | |
323dda78 | 2901 | log_syntax(unit, LOG_WARNING, filename, line, r, |
063c4b1a | 2902 | "Trailing garbage in %s, ignoring: %s", lvalue, rvalue); |
00819cc1 LP |
2903 | break; |
2904 | } | |
a687f500 ZJS |
2905 | if (r == 0) |
2906 | break; | |
00819cc1 LP |
2907 | |
2908 | if (u) { | |
06536492 | 2909 | r = unit_env_printf(u, word, &k); |
00819cc1 | 2910 | if (r < 0) { |
323dda78 | 2911 | log_syntax(unit, LOG_WARNING, filename, line, r, |
063c4b1a | 2912 | "Failed to resolve unit specifiers in %s, ignoring: %m", word); |
00819cc1 LP |
2913 | continue; |
2914 | } | |
ae2a15bc LP |
2915 | } else |
2916 | k = TAKE_PTR(word); | |
00819cc1 LP |
2917 | |
2918 | if (!env_assignment_is_valid(k) && !env_name_is_valid(k)) { | |
323dda78 | 2919 | log_syntax(unit, LOG_WARNING, filename, line, 0, |
00819cc1 LP |
2920 | "Invalid environment name or assignment %s, ignoring: %s", lvalue, k); |
2921 | continue; | |
2922 | } | |
2923 | ||
319a4f4b | 2924 | if (!GREEDY_REALLOC(n, nlen + 2)) |
00819cc1 LP |
2925 | return log_oom(); |
2926 | ||
1cc6c93a | 2927 | n[nlen++] = TAKE_PTR(k); |
00819cc1 | 2928 | n[nlen] = NULL; |
00819cc1 LP |
2929 | } |
2930 | ||
2931 | if (n) { | |
2932 | r = strv_extend_strv(unsetenv, n, true); | |
2933 | if (r < 0) | |
16eb0c4a | 2934 | return log_oom(); |
00819cc1 LP |
2935 | } |
2936 | ||
2937 | return 0; | |
2938 | } | |
2939 | ||
d3070fbd LP |
2940 | int config_parse_log_extra_fields( |
2941 | const char *unit, | |
2942 | const char *filename, | |
2943 | unsigned line, | |
2944 | const char *section, | |
2945 | unsigned section_line, | |
2946 | const char *lvalue, | |
2947 | int ltype, | |
2948 | const char *rvalue, | |
2949 | void *data, | |
2950 | void *userdata) { | |
2951 | ||
99534007 | 2952 | ExecContext *c = ASSERT_PTR(data); |
47538b76 | 2953 | const Unit *u = userdata; |
d3070fbd LP |
2954 | int r; |
2955 | ||
2956 | assert(filename); | |
2957 | assert(lvalue); | |
2958 | assert(rvalue); | |
d3070fbd LP |
2959 | |
2960 | if (isempty(rvalue)) { | |
2961 | exec_context_free_log_extra_fields(c); | |
2962 | return 0; | |
2963 | } | |
2964 | ||
323dda78 | 2965 | for (const char *p = rvalue;;) { |
d3070fbd LP |
2966 | _cleanup_free_ char *word = NULL, *k = NULL; |
2967 | struct iovec *t; | |
2968 | const char *eq; | |
2969 | ||
4ec85141 | 2970 | r = extract_first_word(&p, &word, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE); |
d3070fbd LP |
2971 | if (r == -ENOMEM) |
2972 | return log_oom(); | |
2973 | if (r < 0) { | |
2974 | log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue); | |
2975 | return 0; | |
2976 | } | |
a687f500 ZJS |
2977 | if (r == 0) |
2978 | return 0; | |
d3070fbd LP |
2979 | |
2980 | r = unit_full_printf(u, word, &k); | |
2981 | if (r < 0) { | |
323dda78 | 2982 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", word); |
d3070fbd LP |
2983 | continue; |
2984 | } | |
2985 | ||
2986 | eq = strchr(k, '='); | |
2987 | if (!eq) { | |
323dda78 | 2988 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Log field lacks '=' character, ignoring: %s", k); |
d3070fbd LP |
2989 | continue; |
2990 | } | |
2991 | ||
2992 | if (!journal_field_valid(k, eq-k, false)) { | |
323dda78 | 2993 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Log field name is invalid, ignoring: %s", k); |
d3070fbd LP |
2994 | continue; |
2995 | } | |
2996 | ||
aa484f35 | 2997 | t = reallocarray(c->log_extra_fields, c->n_log_extra_fields+1, sizeof(struct iovec)); |
d3070fbd LP |
2998 | if (!t) |
2999 | return log_oom(); | |
3000 | ||
3001 | c->log_extra_fields = t; | |
3002 | c->log_extra_fields[c->n_log_extra_fields++] = IOVEC_MAKE_STRING(k); | |
3003 | ||
3004 | k = NULL; | |
3005 | } | |
d3070fbd LP |
3006 | } |
3007 | ||
91dd5f7c LP |
3008 | int config_parse_log_namespace( |
3009 | const char *unit, | |
3010 | const char *filename, | |
3011 | unsigned line, | |
3012 | const char *section, | |
3013 | unsigned section_line, | |
3014 | const char *lvalue, | |
3015 | int ltype, | |
3016 | const char *rvalue, | |
3017 | void *data, | |
3018 | void *userdata) { | |
3019 | ||
3020 | _cleanup_free_ char *k = NULL; | |
99534007 | 3021 | ExecContext *c = ASSERT_PTR(data); |
91dd5f7c LP |
3022 | const Unit *u = userdata; |
3023 | int r; | |
3024 | ||
3025 | assert(filename); | |
3026 | assert(lvalue); | |
3027 | assert(rvalue); | |
91dd5f7c LP |
3028 | |
3029 | if (isempty(rvalue)) { | |
3030 | c->log_namespace = mfree(c->log_namespace); | |
3031 | return 0; | |
3032 | } | |
3033 | ||
06536492 | 3034 | r = unit_full_printf_full(u, rvalue, NAME_MAX, &k); |
91dd5f7c | 3035 | if (r < 0) { |
323dda78 | 3036 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue); |
91dd5f7c LP |
3037 | return 0; |
3038 | } | |
3039 | ||
3040 | if (!log_namespace_name_valid(k)) { | |
323dda78 | 3041 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Specified log namespace name is not valid, ignoring: %s", k); |
91dd5f7c LP |
3042 | return 0; |
3043 | } | |
3044 | ||
3045 | free_and_replace(c->log_namespace, k); | |
3046 | return 0; | |
3047 | } | |
3048 | ||
59fccdc5 LP |
3049 | int config_parse_unit_condition_path( |
3050 | const char *unit, | |
3051 | const char *filename, | |
3052 | unsigned line, | |
3053 | const char *section, | |
3054 | unsigned section_line, | |
3055 | const char *lvalue, | |
3056 | int ltype, | |
3057 | const char *rvalue, | |
3058 | void *data, | |
3059 | void *userdata) { | |
52661efd | 3060 | |
2fbe635a | 3061 | _cleanup_free_ char *p = NULL; |
99534007 | 3062 | Condition **list = ASSERT_PTR(data), *c; |
59fccdc5 LP |
3063 | ConditionType t = ltype; |
3064 | bool trigger, negate; | |
47538b76 | 3065 | const Unit *u = userdata; |
19f6d710 | 3066 | int r; |
52661efd LP |
3067 | |
3068 | assert(filename); | |
3069 | assert(lvalue); | |
3070 | assert(rvalue); | |
52661efd | 3071 | |
74051b9b LP |
3072 | if (isempty(rvalue)) { |
3073 | /* Empty assignment resets the list */ | |
447021aa | 3074 | *list = condition_free_list(*list); |
74051b9b LP |
3075 | return 0; |
3076 | } | |
3077 | ||
ab7f148f LP |
3078 | trigger = rvalue[0] == '|'; |
3079 | if (trigger) | |
267632f0 LP |
3080 | rvalue++; |
3081 | ||
ab7f148f LP |
3082 | negate = rvalue[0] == '!'; |
3083 | if (negate) | |
52661efd LP |
3084 | rvalue++; |
3085 | ||
06536492 | 3086 | r = unit_path_printf(u, rvalue, &p); |
59fccdc5 | 3087 | if (r < 0) { |
323dda78 | 3088 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue); |
59fccdc5 | 3089 | return 0; |
19f6d710 | 3090 | } |
095b2d7a | 3091 | |
2f4d31c1 YW |
3092 | r = path_simplify_and_warn(p, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
3093 | if (r < 0) | |
52661efd | 3094 | return 0; |
52661efd | 3095 | |
59fccdc5 | 3096 | c = condition_new(t, p, trigger, negate); |
ab7f148f | 3097 | if (!c) |
74051b9b | 3098 | return log_oom(); |
52661efd | 3099 | |
59fccdc5 | 3100 | LIST_PREPEND(conditions, *list, c); |
52661efd LP |
3101 | return 0; |
3102 | } | |
3103 | ||
59fccdc5 LP |
3104 | int config_parse_unit_condition_string( |
3105 | const char *unit, | |
3106 | const char *filename, | |
3107 | unsigned line, | |
3108 | const char *section, | |
3109 | unsigned section_line, | |
3110 | const char *lvalue, | |
3111 | int ltype, | |
3112 | const char *rvalue, | |
3113 | void *data, | |
3114 | void *userdata) { | |
039655a4 | 3115 | |
2fbe635a | 3116 | _cleanup_free_ char *s = NULL; |
99534007 | 3117 | Condition **list = ASSERT_PTR(data), *c; |
59fccdc5 LP |
3118 | ConditionType t = ltype; |
3119 | bool trigger, negate; | |
47538b76 | 3120 | const Unit *u = userdata; |
19f6d710 | 3121 | int r; |
039655a4 LP |
3122 | |
3123 | assert(filename); | |
3124 | assert(lvalue); | |
3125 | assert(rvalue); | |
039655a4 | 3126 | |
74051b9b LP |
3127 | if (isempty(rvalue)) { |
3128 | /* Empty assignment resets the list */ | |
447021aa | 3129 | *list = condition_free_list(*list); |
74051b9b LP |
3130 | return 0; |
3131 | } | |
3132 | ||
9266f31e | 3133 | trigger = *rvalue == '|'; |
c0d6e764 | 3134 | if (trigger) |
9266f31e | 3135 | rvalue += 1 + strspn(rvalue + 1, WHITESPACE); |
267632f0 | 3136 | |
9266f31e | 3137 | negate = *rvalue == '!'; |
c0d6e764 | 3138 | if (negate) |
9266f31e | 3139 | rvalue += 1 + strspn(rvalue + 1, WHITESPACE); |
039655a4 | 3140 | |
19f6d710 | 3141 | r = unit_full_printf(u, rvalue, &s); |
59fccdc5 | 3142 | if (r < 0) { |
323dda78 | 3143 | log_syntax(unit, LOG_WARNING, filename, line, r, |
cae90de3 | 3144 | "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
59fccdc5 | 3145 | return 0; |
19f6d710 | 3146 | } |
095b2d7a | 3147 | |
59fccdc5 | 3148 | c = condition_new(t, s, trigger, negate); |
c0d6e764 LP |
3149 | if (!c) |
3150 | return log_oom(); | |
039655a4 | 3151 | |
59fccdc5 | 3152 | LIST_PREPEND(conditions, *list, c); |
039655a4 LP |
3153 | return 0; |
3154 | } | |
3155 | ||
9e615fa3 | 3156 | int config_parse_unit_mounts_for( |
a57f7e2c LP |
3157 | const char *unit, |
3158 | const char *filename, | |
3159 | unsigned line, | |
3160 | const char *section, | |
71a61510 | 3161 | unsigned section_line, |
a57f7e2c LP |
3162 | const char *lvalue, |
3163 | int ltype, | |
3164 | const char *rvalue, | |
3165 | void *data, | |
3166 | void *userdata) { | |
7c8fa05c LP |
3167 | |
3168 | Unit *u = userdata; | |
035fe294 | 3169 | int r; |
7c8fa05c LP |
3170 | |
3171 | assert(filename); | |
3172 | assert(lvalue); | |
3173 | assert(rvalue); | |
3174 | assert(data); | |
9e615fa3 | 3175 | assert(STR_IN_SET(lvalue, "RequiresMountsFor", "WantsMountsFor")); |
7c8fa05c | 3176 | |
323dda78 | 3177 | for (const char *p = rvalue;;) { |
744bb5b1 | 3178 | _cleanup_free_ char *word = NULL, *resolved = NULL; |
a57f7e2c | 3179 | |
4ec85141 | 3180 | r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); |
035fe294 | 3181 | if (r == -ENOMEM) |
a57f7e2c | 3182 | return log_oom(); |
035fe294 ZJS |
3183 | if (r < 0) { |
3184 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3185 | "Invalid syntax, ignoring: %s", rvalue); | |
3186 | return 0; | |
3187 | } | |
a687f500 ZJS |
3188 | if (r == 0) |
3189 | return 0; | |
7c8fa05c | 3190 | |
06536492 | 3191 | r = unit_path_printf(u, word, &resolved); |
744bb5b1 | 3192 | if (r < 0) { |
323dda78 | 3193 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", word); |
744bb5b1 LP |
3194 | continue; |
3195 | } | |
3196 | ||
2f4d31c1 YW |
3197 | r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
3198 | if (r < 0) | |
3199 | continue; | |
3200 | ||
9e615fa3 | 3201 | r = unit_add_mounts_for(u, resolved, UNIT_DEPENDENCY_FILE, unit_mount_dependency_type_from_string(lvalue)); |
a57f7e2c | 3202 | if (r < 0) { |
9e615fa3 | 3203 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to add requested mount '%s', ignoring: %m", resolved); |
a57f7e2c LP |
3204 | continue; |
3205 | } | |
3206 | } | |
7c8fa05c | 3207 | } |
9e372868 | 3208 | |
8c6493e5 YW |
3209 | int config_parse_documentation( |
3210 | const char *unit, | |
3211 | const char *filename, | |
3212 | unsigned line, | |
3213 | const char *section, | |
3214 | unsigned section_line, | |
3215 | const char *lvalue, | |
3216 | int ltype, | |
3217 | const char *rvalue, | |
3218 | void *data, | |
3219 | void *userdata) { | |
49dbfa7b | 3220 | |
99534007 | 3221 | Unit *u = ASSERT_PTR(userdata); |
49dbfa7b LP |
3222 | int r; |
3223 | char **a, **b; | |
3224 | ||
3225 | assert(filename); | |
3226 | assert(lvalue); | |
3227 | assert(rvalue); | |
49dbfa7b | 3228 | |
74051b9b LP |
3229 | if (isempty(rvalue)) { |
3230 | /* Empty assignment resets the list */ | |
6796073e | 3231 | u->documentation = strv_free(u->documentation); |
74051b9b LP |
3232 | return 0; |
3233 | } | |
3234 | ||
71a61510 | 3235 | r = config_parse_unit_strv_printf(unit, filename, line, section, section_line, lvalue, ltype, |
e8e581bf | 3236 | rvalue, data, userdata); |
49dbfa7b LP |
3237 | if (r < 0) |
3238 | return r; | |
3239 | ||
3240 | for (a = b = u->documentation; a && *a; a++) { | |
3241 | ||
a2e03378 | 3242 | if (documentation_url_is_valid(*a)) |
49dbfa7b LP |
3243 | *(b++) = *a; |
3244 | else { | |
323dda78 | 3245 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid URL, ignoring: %s", *a); |
49dbfa7b LP |
3246 | free(*a); |
3247 | } | |
3248 | } | |
f6d2d421 ZJS |
3249 | if (b) |
3250 | *b = NULL; | |
49dbfa7b | 3251 | |
8c6493e5 | 3252 | return 0; |
49dbfa7b LP |
3253 | } |
3254 | ||
349cc4a5 | 3255 | #if HAVE_SECCOMP |
17df7223 LP |
3256 | int config_parse_syscall_filter( |
3257 | const char *unit, | |
3258 | const char *filename, | |
3259 | unsigned line, | |
3260 | const char *section, | |
3261 | unsigned section_line, | |
3262 | const char *lvalue, | |
3263 | int ltype, | |
3264 | const char *rvalue, | |
3265 | void *data, | |
3266 | void *userdata) { | |
3267 | ||
8351ceae | 3268 | ExecContext *c = data; |
99534007 | 3269 | _unused_ const Unit *u = ASSERT_PTR(userdata); |
b5fb3789 | 3270 | bool invert = false; |
17df7223 | 3271 | int r; |
8351ceae LP |
3272 | |
3273 | assert(filename); | |
3274 | assert(lvalue); | |
3275 | assert(rvalue); | |
8351ceae | 3276 | |
74051b9b LP |
3277 | if (isempty(rvalue)) { |
3278 | /* Empty assignment resets the list */ | |
8cfa775f | 3279 | c->syscall_filter = hashmap_free(c->syscall_filter); |
6b000af4 | 3280 | c->syscall_allow_list = false; |
74051b9b LP |
3281 | return 0; |
3282 | } | |
3283 | ||
8351ceae LP |
3284 | if (rvalue[0] == '~') { |
3285 | invert = true; | |
3286 | rvalue++; | |
3287 | } | |
3288 | ||
17df7223 | 3289 | if (!c->syscall_filter) { |
8cfa775f | 3290 | c->syscall_filter = hashmap_new(NULL); |
17df7223 LP |
3291 | if (!c->syscall_filter) |
3292 | return log_oom(); | |
3293 | ||
c0467cf3 | 3294 | if (invert) |
17df7223 | 3295 | /* Allow everything but the ones listed */ |
6b000af4 | 3296 | c->syscall_allow_list = false; |
c0467cf3 | 3297 | else { |
17df7223 | 3298 | /* Allow nothing but the ones listed */ |
6b000af4 | 3299 | c->syscall_allow_list = true; |
8351ceae | 3300 | |
387f6955 | 3301 | /* Accept default syscalls if we are on an allow_list */ |
2f6b9110 LP |
3302 | r = seccomp_parse_syscall_filter( |
3303 | "@default", -1, c->syscall_filter, | |
6b000af4 | 3304 | SECCOMP_PARSE_PERMISSIVE|SECCOMP_PARSE_ALLOW_LIST, |
58f6ab44 ZJS |
3305 | unit, |
3306 | NULL, 0); | |
201c1cc2 TM |
3307 | if (r < 0) |
3308 | return r; | |
c0467cf3 | 3309 | } |
8351ceae LP |
3310 | } |
3311 | ||
323dda78 | 3312 | for (const char *p = rvalue;;) { |
8cfa775f YW |
3313 | _cleanup_free_ char *word = NULL, *name = NULL; |
3314 | int num; | |
8351ceae | 3315 | |
8130926d | 3316 | r = extract_first_word(&p, &word, NULL, 0); |
8130926d | 3317 | if (r == -ENOMEM) |
74051b9b | 3318 | return log_oom(); |
8130926d | 3319 | if (r < 0) { |
084a46d7 YW |
3320 | log_syntax(unit, LOG_WARNING, filename, line, r, |
3321 | "Invalid syntax, ignoring: %s", rvalue); | |
063c4b1a | 3322 | return 0; |
8130926d | 3323 | } |
a687f500 ZJS |
3324 | if (r == 0) |
3325 | return 0; | |
8351ceae | 3326 | |
8cfa775f YW |
3327 | r = parse_syscall_and_errno(word, &name, &num); |
3328 | if (r < 0) { | |
084a46d7 YW |
3329 | log_syntax(unit, LOG_WARNING, filename, line, r, |
3330 | "Failed to parse syscall:errno, ignoring: %s", word); | |
3331 | continue; | |
3332 | } | |
3333 | if (!invert && num >= 0) { | |
3334 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
3335 | "Allow-listed system calls cannot take error number, ignoring: %s", word); | |
8cfa775f YW |
3336 | continue; |
3337 | } | |
3338 | ||
58f6ab44 | 3339 | r = seccomp_parse_syscall_filter( |
acd142af LP |
3340 | name, num, c->syscall_filter, |
3341 | SECCOMP_PARSE_LOG|SECCOMP_PARSE_PERMISSIVE| | |
3342 | (invert ? SECCOMP_PARSE_INVERT : 0)| | |
6b000af4 | 3343 | (c->syscall_allow_list ? SECCOMP_PARSE_ALLOW_LIST : 0), |
acd142af | 3344 | unit, filename, line); |
201c1cc2 TM |
3345 | if (r < 0) |
3346 | return r; | |
c0467cf3 | 3347 | } |
17df7223 LP |
3348 | } |
3349 | ||
9df2cdd8 TM |
3350 | int config_parse_syscall_log( |
3351 | const char *unit, | |
3352 | const char *filename, | |
3353 | unsigned line, | |
3354 | const char *section, | |
3355 | unsigned section_line, | |
3356 | const char *lvalue, | |
3357 | int ltype, | |
3358 | const char *rvalue, | |
3359 | void *data, | |
3360 | void *userdata) { | |
3361 | ||
3362 | ExecContext *c = data; | |
99534007 | 3363 | _unused_ const Unit *u = ASSERT_PTR(userdata); |
9df2cdd8 TM |
3364 | bool invert = false; |
3365 | const char *p; | |
3366 | int r; | |
3367 | ||
3368 | assert(filename); | |
3369 | assert(lvalue); | |
3370 | assert(rvalue); | |
9df2cdd8 TM |
3371 | |
3372 | if (isempty(rvalue)) { | |
3373 | /* Empty assignment resets the list */ | |
3374 | c->syscall_log = hashmap_free(c->syscall_log); | |
3375 | c->syscall_log_allow_list = false; | |
3376 | return 0; | |
3377 | } | |
3378 | ||
3379 | if (rvalue[0] == '~') { | |
3380 | invert = true; | |
3381 | rvalue++; | |
3382 | } | |
3383 | ||
3384 | if (!c->syscall_log) { | |
3385 | c->syscall_log = hashmap_new(NULL); | |
3386 | if (!c->syscall_log) | |
3387 | return log_oom(); | |
3388 | ||
3389 | if (invert) | |
3390 | /* Log everything but the ones listed */ | |
3391 | c->syscall_log_allow_list = false; | |
3392 | else | |
3393 | /* Log nothing but the ones listed */ | |
3394 | c->syscall_log_allow_list = true; | |
3395 | } | |
3396 | ||
3397 | p = rvalue; | |
3398 | for (;;) { | |
696a13ba | 3399 | _cleanup_free_ char *word = NULL; |
9df2cdd8 TM |
3400 | |
3401 | r = extract_first_word(&p, &word, NULL, 0); | |
9df2cdd8 TM |
3402 | if (r == -ENOMEM) |
3403 | return log_oom(); | |
3404 | if (r < 0) { | |
3405 | log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue); | |
3406 | return 0; | |
3407 | } | |
a687f500 ZJS |
3408 | if (r == 0) |
3409 | return 0; | |
9df2cdd8 | 3410 | |
9df2cdd8 | 3411 | r = seccomp_parse_syscall_filter( |
696a13ba | 3412 | word, -1, c->syscall_log, |
9df2cdd8 TM |
3413 | SECCOMP_PARSE_LOG|SECCOMP_PARSE_PERMISSIVE| |
3414 | (invert ? SECCOMP_PARSE_INVERT : 0)| | |
3415 | (c->syscall_log_allow_list ? SECCOMP_PARSE_ALLOW_LIST : 0), | |
3416 | unit, filename, line); | |
3417 | if (r < 0) | |
3418 | return r; | |
3419 | } | |
3420 | } | |
3421 | ||
57183d11 LP |
3422 | int config_parse_syscall_archs( |
3423 | const char *unit, | |
3424 | const char *filename, | |
3425 | unsigned line, | |
3426 | const char *section, | |
3427 | unsigned section_line, | |
3428 | const char *lvalue, | |
3429 | int ltype, | |
3430 | const char *rvalue, | |
3431 | void *data, | |
3432 | void *userdata) { | |
3433 | ||
d3b1c508 | 3434 | Set **archs = data; |
57183d11 LP |
3435 | int r; |
3436 | ||
3437 | if (isempty(rvalue)) { | |
525d3cc7 | 3438 | *archs = set_free(*archs); |
57183d11 LP |
3439 | return 0; |
3440 | } | |
3441 | ||
323dda78 | 3442 | for (const char *p = rvalue;;) { |
035fe294 | 3443 | _cleanup_free_ char *word = NULL; |
57183d11 LP |
3444 | uint32_t a; |
3445 | ||
4ec85141 | 3446 | r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); |
035fe294 | 3447 | if (r == -ENOMEM) |
57183d11 | 3448 | return log_oom(); |
035fe294 ZJS |
3449 | if (r < 0) { |
3450 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3451 | "Invalid syntax, ignoring: %s", rvalue); | |
3452 | return 0; | |
3453 | } | |
a687f500 ZJS |
3454 | if (r == 0) |
3455 | return 0; | |
57183d11 | 3456 | |
035fe294 | 3457 | r = seccomp_arch_from_string(word, &a); |
57183d11 | 3458 | if (r < 0) { |
323dda78 | 3459 | log_syntax(unit, LOG_WARNING, filename, line, r, |
035fe294 | 3460 | "Failed to parse system call architecture \"%s\", ignoring: %m", word); |
57183d11 LP |
3461 | continue; |
3462 | } | |
3463 | ||
de7fef4b | 3464 | r = set_ensure_put(archs, NULL, UINT32_TO_PTR(a + 1)); |
57183d11 LP |
3465 | if (r < 0) |
3466 | return log_oom(); | |
3467 | } | |
57183d11 LP |
3468 | } |
3469 | ||
17df7223 LP |
3470 | int config_parse_syscall_errno( |
3471 | const char *unit, | |
3472 | const char *filename, | |
3473 | unsigned line, | |
3474 | const char *section, | |
3475 | unsigned section_line, | |
3476 | const char *lvalue, | |
3477 | int ltype, | |
3478 | const char *rvalue, | |
3479 | void *data, | |
3480 | void *userdata) { | |
3481 | ||
3482 | ExecContext *c = data; | |
3483 | int e; | |
3484 | ||
3485 | assert(filename); | |
3486 | assert(lvalue); | |
3487 | assert(rvalue); | |
3488 | ||
005bfaf1 | 3489 | if (isempty(rvalue) || streq(rvalue, "kill")) { |
17df7223 | 3490 | /* Empty assignment resets to KILL */ |
005bfaf1 | 3491 | c->syscall_errno = SECCOMP_ERROR_NUMBER_KILL; |
17df7223 | 3492 | return 0; |
8351ceae LP |
3493 | } |
3494 | ||
3df90f24 | 3495 | e = parse_errno(rvalue); |
b98680b2 YW |
3496 | if (e < 0) { |
3497 | log_syntax(unit, LOG_WARNING, filename, line, e, "Failed to parse error number, ignoring: %s", rvalue); | |
3498 | return 0; | |
3499 | } | |
3500 | if (e == 0) { | |
3501 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid error number, ignoring: %s", rvalue); | |
17df7223 LP |
3502 | return 0; |
3503 | } | |
8351ceae | 3504 | |
17df7223 | 3505 | c->syscall_errno = e; |
8351ceae LP |
3506 | return 0; |
3507 | } | |
4298d0b5 LP |
3508 | |
3509 | int config_parse_address_families( | |
3510 | const char *unit, | |
3511 | const char *filename, | |
3512 | unsigned line, | |
3513 | const char *section, | |
3514 | unsigned section_line, | |
3515 | const char *lvalue, | |
3516 | int ltype, | |
3517 | const char *rvalue, | |
3518 | void *data, | |
3519 | void *userdata) { | |
3520 | ||
3521 | ExecContext *c = data; | |
4298d0b5 | 3522 | bool invert = false; |
4298d0b5 LP |
3523 | int r; |
3524 | ||
3525 | assert(filename); | |
3526 | assert(lvalue); | |
3527 | assert(rvalue); | |
4298d0b5 LP |
3528 | |
3529 | if (isempty(rvalue)) { | |
3530 | /* Empty assignment resets the list */ | |
525d3cc7 | 3531 | c->address_families = set_free(c->address_families); |
6b000af4 | 3532 | c->address_families_allow_list = false; |
4298d0b5 LP |
3533 | return 0; |
3534 | } | |
3535 | ||
4e6c50a5 YW |
3536 | if (streq(rvalue, "none")) { |
3537 | /* Forbid all address families. */ | |
3538 | c->address_families = set_free(c->address_families); | |
3539 | c->address_families_allow_list = true; | |
3540 | return 0; | |
3541 | } | |
3542 | ||
4298d0b5 LP |
3543 | if (rvalue[0] == '~') { |
3544 | invert = true; | |
3545 | rvalue++; | |
3546 | } | |
3547 | ||
3548 | if (!c->address_families) { | |
d5099efc | 3549 | c->address_families = set_new(NULL); |
4298d0b5 LP |
3550 | if (!c->address_families) |
3551 | return log_oom(); | |
3552 | ||
6b000af4 | 3553 | c->address_families_allow_list = !invert; |
4298d0b5 LP |
3554 | } |
3555 | ||
323dda78 | 3556 | for (const char *p = rvalue;;) { |
035fe294 | 3557 | _cleanup_free_ char *word = NULL; |
4298d0b5 LP |
3558 | int af; |
3559 | ||
4ec85141 | 3560 | r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); |
035fe294 | 3561 | if (r == -ENOMEM) |
4298d0b5 | 3562 | return log_oom(); |
035fe294 ZJS |
3563 | if (r < 0) { |
3564 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3565 | "Invalid syntax, ignoring: %s", rvalue); | |
3566 | return 0; | |
3567 | } | |
a687f500 ZJS |
3568 | if (r == 0) |
3569 | return 0; | |
4298d0b5 | 3570 | |
035fe294 | 3571 | af = af_from_name(word); |
acf4d158 | 3572 | if (af < 0) { |
323dda78 | 3573 | log_syntax(unit, LOG_WARNING, filename, line, af, |
063c4b1a | 3574 | "Failed to parse address family, ignoring: %s", word); |
4298d0b5 LP |
3575 | continue; |
3576 | } | |
3577 | ||
3578 | /* If we previously wanted to forbid an address family and now | |
035fe294 | 3579 | * we want to allow it, then just remove it from the list. |
4298d0b5 | 3580 | */ |
6b000af4 | 3581 | if (!invert == c->address_families_allow_list) { |
4298d0b5 | 3582 | r = set_put(c->address_families, INT_TO_PTR(af)); |
4298d0b5 LP |
3583 | if (r < 0) |
3584 | return log_oom(); | |
3585 | } else | |
3586 | set_remove(c->address_families, INT_TO_PTR(af)); | |
3587 | } | |
4298d0b5 | 3588 | } |
add00535 LP |
3589 | |
3590 | int config_parse_restrict_namespaces( | |
3591 | const char *unit, | |
3592 | const char *filename, | |
3593 | unsigned line, | |
3594 | const char *section, | |
3595 | unsigned section_line, | |
3596 | const char *lvalue, | |
3597 | int ltype, | |
3598 | const char *rvalue, | |
3599 | void *data, | |
3600 | void *userdata) { | |
3601 | ||
3602 | ExecContext *c = data; | |
aa9d574d | 3603 | unsigned long flags; |
add00535 LP |
3604 | bool invert = false; |
3605 | int r; | |
3606 | ||
3607 | if (isempty(rvalue)) { | |
3608 | /* Reset to the default. */ | |
aa9d574d YW |
3609 | c->restrict_namespaces = NAMESPACE_FLAGS_INITIAL; |
3610 | return 0; | |
3611 | } | |
3612 | ||
3613 | /* Boolean parameter ignores the previous settings */ | |
3614 | r = parse_boolean(rvalue); | |
3615 | if (r > 0) { | |
3616 | c->restrict_namespaces = 0; | |
3617 | return 0; | |
3618 | } else if (r == 0) { | |
add00535 LP |
3619 | c->restrict_namespaces = NAMESPACE_FLAGS_ALL; |
3620 | return 0; | |
3621 | } | |
3622 | ||
3623 | if (rvalue[0] == '~') { | |
3624 | invert = true; | |
3625 | rvalue++; | |
3626 | } | |
3627 | ||
aa9d574d YW |
3628 | /* Not a boolean argument, in this case it's a list of namespace types. */ |
3629 | r = namespace_flags_from_string(rvalue, &flags); | |
3630 | if (r < 0) { | |
323dda78 | 3631 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse namespace type string, ignoring: %s", rvalue); |
aa9d574d | 3632 | return 0; |
add00535 LP |
3633 | } |
3634 | ||
aa9d574d YW |
3635 | if (c->restrict_namespaces == NAMESPACE_FLAGS_INITIAL) |
3636 | /* Initial assignment. Just set the value. */ | |
3637 | c->restrict_namespaces = invert ? (~flags) & NAMESPACE_FLAGS_ALL : flags; | |
3638 | else | |
3639 | /* Merge the value with the previous one. */ | |
3640 | SET_FLAG(c->restrict_namespaces, flags, !invert); | |
add00535 LP |
3641 | |
3642 | return 0; | |
3643 | } | |
c0467cf3 | 3644 | #endif |
8351ceae | 3645 | |
e59ccd03 ILG |
3646 | int config_parse_restrict_filesystems( |
3647 | const char *unit, | |
3648 | const char *filename, | |
3649 | unsigned line, | |
3650 | const char *section, | |
3651 | unsigned section_line, | |
3652 | const char *lvalue, | |
3653 | int ltype, | |
3654 | const char *rvalue, | |
3655 | void *data, | |
3656 | void *userdata) { | |
99534007 | 3657 | ExecContext *c = ASSERT_PTR(data); |
e59ccd03 ILG |
3658 | bool invert = false; |
3659 | int r; | |
3660 | ||
3661 | assert(filename); | |
3662 | assert(lvalue); | |
3663 | assert(rvalue); | |
e59ccd03 ILG |
3664 | |
3665 | if (isempty(rvalue)) { | |
3666 | /* Empty assignment resets the list */ | |
1a572fd0 | 3667 | c->restrict_filesystems = set_free_free(c->restrict_filesystems); |
e59ccd03 ILG |
3668 | c->restrict_filesystems_allow_list = false; |
3669 | return 0; | |
3670 | } | |
3671 | ||
3672 | if (rvalue[0] == '~') { | |
3673 | invert = true; | |
3674 | rvalue++; | |
3675 | } | |
3676 | ||
3677 | if (!c->restrict_filesystems) { | |
3678 | if (invert) | |
3679 | /* Allow everything but the ones listed */ | |
3680 | c->restrict_filesystems_allow_list = false; | |
3681 | else | |
3682 | /* Allow nothing but the ones listed */ | |
3683 | c->restrict_filesystems_allow_list = true; | |
3684 | } | |
3685 | ||
3686 | for (const char *p = rvalue;;) { | |
3687 | _cleanup_free_ char *word = NULL; | |
3688 | ||
3689 | r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); | |
3690 | if (r == 0) | |
3691 | break; | |
3692 | if (r == -ENOMEM) | |
3693 | return log_oom(); | |
3694 | if (r < 0) { | |
3695 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3696 | "Trailing garbage in %s, ignoring: %s", lvalue, rvalue); | |
3697 | break; | |
3698 | } | |
3699 | ||
3700 | r = lsm_bpf_parse_filesystem( | |
3701 | word, | |
3702 | &c->restrict_filesystems, | |
3703 | FILESYSTEM_PARSE_LOG| | |
3704 | (invert ? FILESYSTEM_PARSE_INVERT : 0)| | |
3705 | (c->restrict_filesystems_allow_list ? FILESYSTEM_PARSE_ALLOW_LIST : 0), | |
3706 | unit, filename, line); | |
3707 | ||
3708 | if (r < 0) | |
3709 | return r; | |
3710 | } | |
3711 | ||
3712 | return 0; | |
3713 | } | |
3714 | ||
a016b922 LP |
3715 | int config_parse_unit_slice( |
3716 | const char *unit, | |
3717 | const char *filename, | |
3718 | unsigned line, | |
3719 | const char *section, | |
71a61510 | 3720 | unsigned section_line, |
a016b922 LP |
3721 | const char *lvalue, |
3722 | int ltype, | |
3723 | const char *rvalue, | |
3724 | void *data, | |
3725 | void *userdata) { | |
3726 | ||
063c4b1a | 3727 | _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; |
a016b922 | 3728 | _cleanup_free_ char *k = NULL; |
abc9fa1c | 3729 | Unit *u = userdata, *slice; |
a016b922 LP |
3730 | int r; |
3731 | ||
3732 | assert(filename); | |
3733 | assert(lvalue); | |
3734 | assert(rvalue); | |
3735 | assert(u); | |
3736 | ||
19f6d710 | 3737 | r = unit_name_printf(u, rvalue, &k); |
d79200e2 | 3738 | if (r < 0) { |
323dda78 | 3739 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue); |
d79200e2 | 3740 | return 0; |
19f6d710 | 3741 | } |
a016b922 | 3742 | |
063c4b1a | 3743 | r = manager_load_unit(u->manager, k, NULL, &error, &slice); |
a016b922 | 3744 | if (r < 0) { |
323dda78 | 3745 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to load slice unit %s, ignoring: %s", k, bus_error_message(&error, r)); |
a016b922 LP |
3746 | return 0; |
3747 | } | |
3748 | ||
899acf5c | 3749 | r = unit_set_slice(u, slice); |
d79200e2 | 3750 | if (r < 0) { |
323dda78 | 3751 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to assign slice %s to unit %s, ignoring: %m", slice->id, u->id); |
a016b922 LP |
3752 | return 0; |
3753 | } | |
3754 | ||
a016b922 LP |
3755 | return 0; |
3756 | } | |
3757 | ||
b2f8b02e LP |
3758 | int config_parse_cpu_quota( |
3759 | const char *unit, | |
3760 | const char *filename, | |
3761 | unsigned line, | |
3762 | const char *section, | |
3763 | unsigned section_line, | |
3764 | const char *lvalue, | |
3765 | int ltype, | |
3766 | const char *rvalue, | |
3767 | void *data, | |
3768 | void *userdata) { | |
3769 | ||
3770 | CGroupContext *c = data; | |
9184ca48 | 3771 | int r; |
b2f8b02e LP |
3772 | |
3773 | assert(filename); | |
3774 | assert(lvalue); | |
3775 | assert(rvalue); | |
3776 | ||
3777 | if (isempty(rvalue)) { | |
3a43da28 | 3778 | c->cpu_quota_per_sec_usec = USEC_INFINITY; |
b2f8b02e LP |
3779 | return 0; |
3780 | } | |
3781 | ||
fe845b5e | 3782 | r = parse_permyriad_unbounded(rvalue); |
9184ca48 | 3783 | if (r <= 0) { |
323dda78 | 3784 | log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid CPU quota '%s', ignoring.", rvalue); |
9a054909 | 3785 | return 0; |
b2f8b02e LP |
3786 | } |
3787 | ||
fe845b5e | 3788 | c->cpu_quota_per_sec_usec = ((usec_t) r * USEC_PER_SEC) / 10000U; |
b2f8b02e LP |
3789 | return 0; |
3790 | } | |
3791 | ||
31d3a520 | 3792 | int config_parse_allowed_cpuset( |
047f5d63 PH |
3793 | const char *unit, |
3794 | const char *filename, | |
3795 | unsigned line, | |
3796 | const char *section, | |
3797 | unsigned section_line, | |
3798 | const char *lvalue, | |
3799 | int ltype, | |
3800 | const char *rvalue, | |
3801 | void *data, | |
3802 | void *userdata) { | |
3803 | ||
31d3a520 | 3804 | CPUSet *c = data; |
67001c25 AL |
3805 | const Unit *u = userdata; |
3806 | _cleanup_free_ char *k = NULL; | |
3807 | int r; | |
3808 | ||
3809 | assert(filename); | |
3810 | assert(lvalue); | |
3811 | assert(rvalue); | |
3812 | ||
3813 | r = unit_full_printf(u, rvalue, &k); | |
3814 | if (r < 0) { | |
3815 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3816 | "Failed to resolve unit specifiers in '%s', ignoring: %m", | |
3817 | rvalue); | |
3818 | return 0; | |
3819 | } | |
047f5d63 | 3820 | |
67001c25 | 3821 | (void) parse_cpu_set_extend(k, c, true, unit, filename, line, lvalue); |
047f5d63 PH |
3822 | return 0; |
3823 | } | |
3824 | ||
4ad49000 LP |
3825 | int config_parse_memory_limit( |
3826 | const char *unit, | |
3827 | const char *filename, | |
3828 | unsigned line, | |
3829 | const char *section, | |
71a61510 | 3830 | unsigned section_line, |
4ad49000 LP |
3831 | const char *lvalue, |
3832 | int ltype, | |
3833 | const char *rvalue, | |
3834 | void *data, | |
3835 | void *userdata) { | |
3836 | ||
3837 | CGroupContext *c = data; | |
da4d897e | 3838 | uint64_t bytes = CGROUP_LIMIT_MAX; |
4ad49000 LP |
3839 | int r; |
3840 | ||
67e2baff MK |
3841 | if (isempty(rvalue) && STR_IN_SET(lvalue, "DefaultMemoryLow", |
3842 | "DefaultMemoryMin", | |
3843 | "MemoryLow", | |
53fda560 | 3844 | "StartupMemoryLow", |
67e2baff | 3845 | "MemoryMin")) |
db2b8d2e | 3846 | bytes = CGROUP_LIMIT_MIN; |
67e2baff | 3847 | else if (!isempty(rvalue) && !streq(rvalue, "infinity")) { |
875ae566 | 3848 | |
fe845b5e | 3849 | r = parse_permyriad(rvalue); |
875ae566 LP |
3850 | if (r < 0) { |
3851 | r = parse_size(rvalue, 1024, &bytes); | |
3852 | if (r < 0) { | |
323dda78 | 3853 | log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid memory limit '%s', ignoring: %m", rvalue); |
875ae566 LP |
3854 | return 0; |
3855 | } | |
3856 | } else | |
fe845b5e | 3857 | bytes = physical_memory_scale(r, 10000U); |
875ae566 | 3858 | |
906bdbf5 | 3859 | if (bytes >= UINT64_MAX || |
53fda560 LB |
3860 | (bytes <= 0 && !STR_IN_SET(lvalue, |
3861 | "MemorySwapMax", | |
3862 | "StartupMemorySwapMax", | |
3863 | "MemoryZSwapMax", | |
3864 | "StartupMemoryZSwapMax", | |
3865 | "MemoryLow", | |
3866 | "StartupMemoryLow", | |
3867 | "MemoryMin", | |
3868 | "DefaultMemoryLow", | |
3869 | "DefaultstartupMemoryLow", | |
3870 | "DefaultMemoryMin"))) { | |
323dda78 | 3871 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Memory limit '%s' out of range, ignoring.", rvalue); |
da4d897e TH |
3872 | return 0; |
3873 | } | |
4ad49000 LP |
3874 | } |
3875 | ||
c52db42b | 3876 | if (streq(lvalue, "DefaultMemoryLow")) { |
db2b8d2e | 3877 | c->default_memory_low = bytes; |
c52db42b | 3878 | c->default_memory_low_set = true; |
53fda560 LB |
3879 | } else if (streq(lvalue, "DefaultStartupMemoryLow")) { |
3880 | c->default_startup_memory_low = bytes; | |
3881 | c->default_startup_memory_low_set = true; | |
7ad5439e | 3882 | } else if (streq(lvalue, "DefaultMemoryMin")) { |
db2b8d2e | 3883 | c->default_memory_min = bytes; |
7ad5439e | 3884 | c->default_memory_min_set = true; |
7ad5439e | 3885 | } else if (streq(lvalue, "MemoryMin")) { |
48422635 | 3886 | c->memory_min = bytes; |
311a0e2e | 3887 | c->memory_min_set = true; |
7ad5439e | 3888 | } else if (streq(lvalue, "MemoryLow")) { |
da4d897e | 3889 | c->memory_low = bytes; |
311a0e2e | 3890 | c->memory_low_set = true; |
53fda560 LB |
3891 | } else if (streq(lvalue, "StartupMemoryLow")) { |
3892 | c->startup_memory_low = bytes; | |
3893 | c->startup_memory_low_set = true; | |
c52db42b | 3894 | } else if (streq(lvalue, "MemoryHigh")) |
da4d897e | 3895 | c->memory_high = bytes; |
53fda560 LB |
3896 | else if (streq(lvalue, "StartupMemoryHigh")) { |
3897 | c->startup_memory_high = bytes; | |
3898 | c->startup_memory_high_set = true; | |
3899 | } else if (streq(lvalue, "MemoryMax")) | |
da4d897e | 3900 | c->memory_max = bytes; |
53fda560 LB |
3901 | else if (streq(lvalue, "StartupMemoryMax")) { |
3902 | c->startup_memory_max = bytes; | |
3903 | c->startup_memory_max_set = true; | |
3904 | } else if (streq(lvalue, "MemorySwapMax")) | |
96e131ea | 3905 | c->memory_swap_max = bytes; |
53fda560 LB |
3906 | else if (streq(lvalue, "StartupMemorySwapMax")) { |
3907 | c->startup_memory_swap_max = bytes; | |
3908 | c->startup_memory_swap_max_set = true; | |
3909 | } else if (streq(lvalue, "MemoryZSwapMax")) | |
d7fe0a67 | 3910 | c->memory_zswap_max = bytes; |
53fda560 LB |
3911 | else if (streq(lvalue, "StartupMemoryZSwapMax")) { |
3912 | c->startup_memory_zswap_max = bytes; | |
3913 | c->startup_memory_zswap_max_set = true; | |
3914 | } else if (streq(lvalue, "MemoryLimit")) { | |
c1e701e2 LP |
3915 | log_syntax(unit, LOG_WARNING, filename, line, 0, |
3916 | "Unit uses MemoryLimit=; please use MemoryMax= instead. Support for MemoryLimit= will be removed soon."); | |
da4d897e | 3917 | c->memory_limit = bytes; |
c1e701e2 | 3918 | } else |
96e131ea | 3919 | return -EINVAL; |
4ad49000 | 3920 | |
4ad49000 LP |
3921 | return 0; |
3922 | } | |
3923 | ||
03a7b521 LP |
3924 | int config_parse_tasks_max( |
3925 | const char *unit, | |
3926 | const char *filename, | |
3927 | unsigned line, | |
3928 | const char *section, | |
3929 | unsigned section_line, | |
3930 | const char *lvalue, | |
3931 | int ltype, | |
3932 | const char *rvalue, | |
3933 | void *data, | |
3934 | void *userdata) { | |
3935 | ||
47538b76 | 3936 | const Unit *u = userdata; |
94f0b13b | 3937 | CGroupTasksMax *tasks_max = data; |
3a0f06c4 | 3938 | uint64_t v; |
03a7b521 LP |
3939 | int r; |
3940 | ||
f5058264 | 3941 | if (isempty(rvalue)) { |
94f0b13b | 3942 | *tasks_max = u ? u->manager->defaults.tasks_max : CGROUP_TASKS_MAX_UNSET; |
f5058264 TH |
3943 | return 0; |
3944 | } | |
3945 | ||
3946 | if (streq(rvalue, "infinity")) { | |
94f0b13b | 3947 | *tasks_max = CGROUP_TASKS_MAX_UNSET; |
03a7b521 LP |
3948 | return 0; |
3949 | } | |
3950 | ||
fe845b5e | 3951 | r = parse_permyriad(rvalue); |
3a0f06c4 | 3952 | if (r >= 0) |
94f0b13b | 3953 | *tasks_max = (CGroupTasksMax) { r, 10000U }; /* r‱ */ |
3a0f06c4 | 3954 | else { |
f5058264 | 3955 | r = safe_atou64(rvalue, &v); |
83f8e808 | 3956 | if (r < 0) { |
323dda78 | 3957 | log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid maximum tasks value '%s', ignoring: %m", rvalue); |
83f8e808 LP |
3958 | return 0; |
3959 | } | |
83f8e808 | 3960 | |
3a0f06c4 | 3961 | if (v <= 0 || v >= UINT64_MAX) { |
323dda78 | 3962 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue); |
3a0f06c4 ZJS |
3963 | return 0; |
3964 | } | |
3965 | ||
94f0b13b | 3966 | *tasks_max = (CGroupTasksMax) { v }; |
03a7b521 LP |
3967 | } |
3968 | ||
3969 | return 0; | |
3970 | } | |
3971 | ||
02638280 LP |
3972 | int config_parse_delegate( |
3973 | const char *unit, | |
3974 | const char *filename, | |
3975 | unsigned line, | |
3976 | const char *section, | |
3977 | unsigned section_line, | |
3978 | const char *lvalue, | |
3979 | int ltype, | |
3980 | const char *rvalue, | |
3981 | void *data, | |
3982 | void *userdata) { | |
3983 | ||
3984 | CGroupContext *c = data; | |
ecae73d7 | 3985 | UnitType t; |
02638280 LP |
3986 | int r; |
3987 | ||
ecae73d7 ZJS |
3988 | t = unit_name_to_type(unit); |
3989 | assert(t != _UNIT_TYPE_INVALID); | |
3990 | ||
3991 | if (!unit_vtable[t]->can_delegate) { | |
323dda78 | 3992 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Delegate= setting not supported for this unit type, ignoring."); |
ecae73d7 ZJS |
3993 | return 0; |
3994 | } | |
3995 | ||
449172f9 ZJS |
3996 | /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or |
3997 | * turn it off for all. Or it takes a list of controller names, in which case we add the specified | |
3998 | * controllers to the mask to delegate. Delegate= enables delegation without any controllers. */ | |
02638280 | 3999 | |
1bdfc7b9 | 4000 | if (isempty(rvalue)) { |
449172f9 | 4001 | /* An empty string resets controllers and sets Delegate=yes. */ |
d48013f8 | 4002 | c->delegate = true; |
1bdfc7b9 YW |
4003 | c->delegate_controllers = 0; |
4004 | return 0; | |
4005 | } | |
4006 | ||
02638280 LP |
4007 | r = parse_boolean(rvalue); |
4008 | if (r < 0) { | |
02638280 LP |
4009 | CGroupMask mask = 0; |
4010 | ||
323dda78 | 4011 | for (const char *p = rvalue;;) { |
02638280 LP |
4012 | _cleanup_free_ char *word = NULL; |
4013 | CGroupController cc; | |
4014 | ||
4ec85141 | 4015 | r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); |
02638280 LP |
4016 | if (r == -ENOMEM) |
4017 | return log_oom(); | |
4018 | if (r < 0) { | |
323dda78 | 4019 | log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue); |
ff1b8455 | 4020 | return 0; |
02638280 | 4021 | } |
a687f500 ZJS |
4022 | if (r == 0) |
4023 | break; | |
02638280 LP |
4024 | |
4025 | cc = cgroup_controller_from_string(word); | |
4026 | if (cc < 0) { | |
323dda78 | 4027 | log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid controller name '%s', ignoring", word); |
02638280 LP |
4028 | continue; |
4029 | } | |
4030 | ||
4031 | mask |= CGROUP_CONTROLLER_TO_MASK(cc); | |
4032 | } | |
4033 | ||
4034 | c->delegate = true; | |
4035 | c->delegate_controllers |= mask; | |
4036 | ||
4037 | } else if (r > 0) { | |
4038 | c->delegate = true; | |
677e6c14 | 4039 | c->delegate_controllers = CGROUP_MASK_DELEGATE; |
02638280 LP |
4040 | } else { |
4041 | c->delegate = false; | |
4042 | c->delegate_controllers = 0; | |
4043 | } | |
4044 | ||
4045 | return 0; | |
4046 | } | |
4047 | ||
a8b993dc LP |
4048 | int config_parse_delegate_subgroup( |
4049 | const char *unit, | |
4050 | const char *filename, | |
4051 | unsigned line, | |
4052 | const char *section, | |
4053 | unsigned section_line, | |
4054 | const char *lvalue, | |
4055 | int ltype, | |
4056 | const char *rvalue, | |
4057 | void *data, | |
4058 | void *userdata) { | |
4059 | ||
4060 | CGroupContext *c = ASSERT_PTR(data); | |
4061 | UnitType t; | |
4062 | ||
4063 | t = unit_name_to_type(unit); | |
4064 | assert(t >= 0); | |
4065 | ||
4066 | if (!unit_vtable[t]->can_delegate) { | |
4067 | log_syntax(unit, LOG_WARNING, filename, line, 0, "DelegateSubgroup= setting not supported for this unit type, ignoring."); | |
4068 | return 0; | |
4069 | } | |
4070 | ||
4071 | if (isempty(rvalue)) { | |
4072 | c->delegate_subgroup = mfree(c->delegate_subgroup); | |
4073 | return 0; | |
4074 | } | |
4075 | ||
4076 | if (cg_needs_escape(rvalue)) { /* Insist that specified names don't need escaping */ | |
4077 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid control group name, ignoring: %s", rvalue); | |
4078 | return 0; | |
4079 | } | |
4080 | ||
4081 | return free_and_strdup_warn(&c->delegate_subgroup, rvalue); | |
4082 | } | |
4083 | ||
4d824a4e AZ |
4084 | int config_parse_managed_oom_mode( |
4085 | const char *unit, | |
4086 | const char *filename, | |
4087 | unsigned line, | |
4088 | const char *section, | |
4089 | unsigned section_line, | |
4090 | const char *lvalue, | |
4091 | int ltype, | |
4092 | const char *rvalue, | |
4093 | void *data, | |
4094 | void *userdata) { | |
ed5033fd | 4095 | |
4d824a4e AZ |
4096 | ManagedOOMMode *mode = data, m; |
4097 | UnitType t; | |
4098 | ||
4099 | t = unit_name_to_type(unit); | |
4100 | assert(t != _UNIT_TYPE_INVALID); | |
4101 | ||
4102 | if (!unit_vtable[t]->can_set_managed_oom) | |
4103 | return log_syntax(unit, LOG_WARNING, filename, line, 0, "%s= is not supported for this unit type, ignoring.", lvalue); | |
4104 | ||
4105 | if (isempty(rvalue)) { | |
4106 | *mode = MANAGED_OOM_AUTO; | |
f561e8c6 | 4107 | return 0; |
4d824a4e AZ |
4108 | } |
4109 | ||
4110 | m = managed_oom_mode_from_string(rvalue); | |
4111 | if (m < 0) { | |
b98680b2 | 4112 | log_syntax(unit, LOG_WARNING, filename, line, m, "Invalid syntax, ignoring: %s", rvalue); |
4d824a4e AZ |
4113 | return 0; |
4114 | } | |
ed5033fd | 4115 | |
4d824a4e AZ |
4116 | *mode = m; |
4117 | return 0; | |
4118 | } | |
4119 | ||
4120 | int config_parse_managed_oom_mem_pressure_limit( | |
4121 | const char *unit, | |
4122 | const char *filename, | |
4123 | unsigned line, | |
4124 | const char *section, | |
4125 | unsigned section_line, | |
4126 | const char *lvalue, | |
4127 | int ltype, | |
4128 | const char *rvalue, | |
4129 | void *data, | |
4130 | void *userdata) { | |
ed5033fd | 4131 | |
0a9f9344 | 4132 | uint32_t *limit = data; |
4d824a4e AZ |
4133 | UnitType t; |
4134 | int r; | |
4135 | ||
4136 | t = unit_name_to_type(unit); | |
4137 | assert(t != _UNIT_TYPE_INVALID); | |
4138 | ||
4139 | if (!unit_vtable[t]->can_set_managed_oom) | |
4140 | return log_syntax(unit, LOG_WARNING, filename, line, 0, "%s= is not supported for this unit type, ignoring.", lvalue); | |
4141 | ||
4142 | if (isempty(rvalue)) { | |
f561e8c6 AZ |
4143 | *limit = 0; |
4144 | return 0; | |
4d824a4e AZ |
4145 | } |
4146 | ||
0a9f9344 | 4147 | r = parse_permyriad(rvalue); |
4d824a4e | 4148 | if (r < 0) { |
0a9f9344 | 4149 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse memory pressure limit value, ignoring: %s", rvalue); |
4d824a4e AZ |
4150 | return 0; |
4151 | } | |
4152 | ||
d9d3f05d LP |
4153 | /* Normalize to 2^32-1 == 100% */ |
4154 | *limit = UINT32_SCALE_FROM_PERMYRIAD(r); | |
4d824a4e AZ |
4155 | return 0; |
4156 | } | |
4157 | ||
4ad49000 LP |
4158 | int config_parse_device_allow( |
4159 | const char *unit, | |
4160 | const char *filename, | |
4161 | unsigned line, | |
4162 | const char *section, | |
71a61510 | 4163 | unsigned section_line, |
4ad49000 LP |
4164 | const char *lvalue, |
4165 | int ltype, | |
4166 | const char *rvalue, | |
4167 | void *data, | |
4168 | void *userdata) { | |
4169 | ||
c9f620bf | 4170 | _cleanup_free_ char *path = NULL, *resolved = NULL; |
a1044811 | 4171 | CGroupDevicePermissions permissions; |
4ad49000 | 4172 | CGroupContext *c = data; |
c9f620bf | 4173 | const char *p = rvalue; |
1116e14c | 4174 | int r; |
4ad49000 LP |
4175 | |
4176 | if (isempty(rvalue)) { | |
4177 | while (c->device_allow) | |
4178 | cgroup_context_free_device_allow(c, c->device_allow); | |
4179 | ||
4180 | return 0; | |
4181 | } | |
4182 | ||
4ec85141 | 4183 | r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE); |
c9f620bf YW |
4184 | if (r == -ENOMEM) |
4185 | return log_oom(); | |
a687f500 | 4186 | if (r <= 0) { |
1116e14c | 4187 | log_syntax(unit, LOG_WARNING, filename, line, r, |
c9f620bf | 4188 | "Failed to extract device path and rights from '%s', ignoring.", rvalue); |
20d52ab6 | 4189 | return 0; |
1116e14c NBS |
4190 | } |
4191 | ||
06536492 | 4192 | r = unit_path_printf(userdata, path, &resolved); |
c9f620bf YW |
4193 | if (r < 0) { |
4194 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
4195 | "Failed to resolve unit specifiers in '%s', ignoring: %m", path); | |
4ad49000 LP |
4196 | return 0; |
4197 | } | |
4198 | ||
49fe5c09 | 4199 | if (!STARTSWITH_SET(resolved, "block-", "char-")) { |
2f4d31c1 | 4200 | |
57e84e75 LP |
4201 | r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue); |
4202 | if (r < 0) | |
4203 | return 0; | |
4204 | ||
4205 | if (!valid_device_node_path(resolved)) { | |
323dda78 | 4206 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid device node path '%s', ignoring.", resolved); |
57e84e75 LP |
4207 | return 0; |
4208 | } | |
c9f620bf | 4209 | } |
4ad49000 | 4210 | |
a1044811 LP |
4211 | permissions = isempty(p) ? 0 : cgroup_device_permissions_from_string(p); |
4212 | if (permissions < 0) { | |
4213 | log_syntax(unit, LOG_WARNING, filename, line, permissions, "Invalid device rights '%s', ignoring.", p); | |
4ad49000 LP |
4214 | return 0; |
4215 | } | |
4216 | ||
a1044811 | 4217 | return cgroup_context_add_device_allow(c, resolved, permissions); |
4ad49000 LP |
4218 | } |
4219 | ||
13c31542 TH |
4220 | int config_parse_io_device_weight( |
4221 | const char *unit, | |
4222 | const char *filename, | |
4223 | unsigned line, | |
4224 | const char *section, | |
4225 | unsigned section_line, | |
4226 | const char *lvalue, | |
4227 | int ltype, | |
4228 | const char *rvalue, | |
4229 | void *data, | |
4230 | void *userdata) { | |
4231 | ||
c9f620bf | 4232 | _cleanup_free_ char *path = NULL, *resolved = NULL; |
13c31542 TH |
4233 | CGroupIODeviceWeight *w; |
4234 | CGroupContext *c = data; | |
99534007 | 4235 | const char *p = ASSERT_PTR(rvalue); |
13c31542 | 4236 | uint64_t u; |
13c31542 TH |
4237 | int r; |
4238 | ||
4239 | assert(filename); | |
4240 | assert(lvalue); | |
13c31542 TH |
4241 | |
4242 | if (isempty(rvalue)) { | |
4243 | while (c->io_device_weights) | |
4244 | cgroup_context_free_io_device_weight(c, c->io_device_weights); | |
4245 | ||
4246 | return 0; | |
4247 | } | |
4248 | ||
4ec85141 | 4249 | r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE); |
c9f620bf YW |
4250 | if (r == -ENOMEM) |
4251 | return log_oom(); | |
6a35d52d | 4252 | if (r < 0) { |
c9f620bf | 4253 | log_syntax(unit, LOG_WARNING, filename, line, r, |
c9f620bf | 4254 | "Failed to extract device path and weight from '%s', ignoring.", rvalue); |
13c31542 TH |
4255 | return 0; |
4256 | } | |
6a35d52d YW |
4257 | if (r == 0 || isempty(p)) { |
4258 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
4259 | "Invalid device path or weight specified in '%s', ignoring.", rvalue); | |
4260 | return 0; | |
4261 | } | |
13c31542 | 4262 | |
06536492 | 4263 | r = unit_path_printf(userdata, path, &resolved); |
c9f620bf YW |
4264 | if (r < 0) { |
4265 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
4266 | "Failed to resolve unit specifiers in '%s', ignoring: %m", path); | |
4267 | return 0; | |
4268 | } | |
13c31542 | 4269 | |
2f4d31c1 YW |
4270 | r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue); |
4271 | if (r < 0) | |
4272 | return 0; | |
4273 | ||
c9f620bf | 4274 | r = cg_weight_parse(p, &u); |
13c31542 | 4275 | if (r < 0) { |
323dda78 | 4276 | log_syntax(unit, LOG_WARNING, filename, line, r, "IO weight '%s' invalid, ignoring: %m", p); |
13c31542 TH |
4277 | return 0; |
4278 | } | |
4279 | ||
4280 | assert(u != CGROUP_WEIGHT_INVALID); | |
4281 | ||
4282 | w = new0(CGroupIODeviceWeight, 1); | |
4283 | if (!w) | |
4284 | return log_oom(); | |
4285 | ||
c9f620bf | 4286 | w->path = TAKE_PTR(resolved); |
13c31542 TH |
4287 | w->weight = u; |
4288 | ||
4289 | LIST_PREPEND(device_weights, c->io_device_weights, w); | |
4290 | return 0; | |
4291 | } | |
4292 | ||
6ae4283c TH |
4293 | int config_parse_io_device_latency( |
4294 | const char *unit, | |
4295 | const char *filename, | |
4296 | unsigned line, | |
4297 | const char *section, | |
4298 | unsigned section_line, | |
4299 | const char *lvalue, | |
4300 | int ltype, | |
4301 | const char *rvalue, | |
4302 | void *data, | |
4303 | void *userdata) { | |
4304 | ||
4305 | _cleanup_free_ char *path = NULL, *resolved = NULL; | |
4306 | CGroupIODeviceLatency *l; | |
4307 | CGroupContext *c = data; | |
99534007 | 4308 | const char *p = ASSERT_PTR(rvalue); |
6ae4283c TH |
4309 | usec_t usec; |
4310 | int r; | |
4311 | ||
4312 | assert(filename); | |
4313 | assert(lvalue); | |
6ae4283c TH |
4314 | |
4315 | if (isempty(rvalue)) { | |
4316 | while (c->io_device_latencies) | |
4317 | cgroup_context_free_io_device_latency(c, c->io_device_latencies); | |
4318 | ||
4319 | return 0; | |
4320 | } | |
4321 | ||
4ec85141 | 4322 | r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE); |
6ae4283c TH |
4323 | if (r == -ENOMEM) |
4324 | return log_oom(); | |
6a35d52d | 4325 | if (r < 0) { |
6ae4283c | 4326 | log_syntax(unit, LOG_WARNING, filename, line, r, |
6ae4283c TH |
4327 | "Failed to extract device path and latency from '%s', ignoring.", rvalue); |
4328 | return 0; | |
4329 | } | |
6a35d52d YW |
4330 | if (r == 0 || isempty(p)) { |
4331 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
4332 | "Invalid device path or latency specified in '%s', ignoring.", rvalue); | |
4333 | return 0; | |
4334 | } | |
6ae4283c | 4335 | |
06536492 | 4336 | r = unit_path_printf(userdata, path, &resolved); |
6ae4283c TH |
4337 | if (r < 0) { |
4338 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
4339 | "Failed to resolve unit specifiers in '%s', ignoring: %m", path); | |
4340 | return 0; | |
4341 | } | |
4342 | ||
4343 | r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue); | |
4344 | if (r < 0) | |
4345 | return 0; | |
4346 | ||
323dda78 YW |
4347 | r = parse_sec(p, &usec); |
4348 | if (r < 0) { | |
4349 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse timer value, ignoring: %s", p); | |
6ae4283c TH |
4350 | return 0; |
4351 | } | |
4352 | ||
4353 | l = new0(CGroupIODeviceLatency, 1); | |
4354 | if (!l) | |
4355 | return log_oom(); | |
4356 | ||
4357 | l->path = TAKE_PTR(resolved); | |
4358 | l->target_usec = usec; | |
4359 | ||
4360 | LIST_PREPEND(device_latencies, c->io_device_latencies, l); | |
4361 | return 0; | |
4362 | } | |
4363 | ||
13c31542 TH |
4364 | int config_parse_io_limit( |
4365 | const char *unit, | |
4366 | const char *filename, | |
4367 | unsigned line, | |
4368 | const char *section, | |
4369 | unsigned section_line, | |
4370 | const char *lvalue, | |
4371 | int ltype, | |
4372 | const char *rvalue, | |
4373 | void *data, | |
4374 | void *userdata) { | |
4375 | ||
c9f620bf | 4376 | _cleanup_free_ char *path = NULL, *resolved = NULL; |
03677889 | 4377 | CGroupIODeviceLimit *l = NULL; |
13c31542 | 4378 | CGroupContext *c = data; |
9be57249 | 4379 | CGroupIOLimitType type; |
99534007 | 4380 | const char *p = ASSERT_PTR(rvalue); |
13c31542 | 4381 | uint64_t num; |
13c31542 TH |
4382 | int r; |
4383 | ||
4384 | assert(filename); | |
4385 | assert(lvalue); | |
13c31542 | 4386 | |
9be57249 TH |
4387 | type = cgroup_io_limit_type_from_string(lvalue); |
4388 | assert(type >= 0); | |
13c31542 TH |
4389 | |
4390 | if (isempty(rvalue)) { | |
03677889 YW |
4391 | LIST_FOREACH(device_limits, t, c->io_device_limits) |
4392 | t->limits[type] = cgroup_io_limit_defaults[type]; | |
13c31542 TH |
4393 | return 0; |
4394 | } | |
4395 | ||
4ec85141 | 4396 | r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE); |
c9f620bf YW |
4397 | if (r == -ENOMEM) |
4398 | return log_oom(); | |
6a35d52d | 4399 | if (r < 0) { |
c9f620bf | 4400 | log_syntax(unit, LOG_WARNING, filename, line, r, |
c9f620bf | 4401 | "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue); |
13c31542 TH |
4402 | return 0; |
4403 | } | |
6a35d52d YW |
4404 | if (r == 0 || isempty(p)) { |
4405 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
4406 | "Invalid device node or bandwidth specified in '%s', ignoring.", rvalue); | |
4407 | return 0; | |
4408 | } | |
13c31542 | 4409 | |
06536492 | 4410 | r = unit_path_printf(userdata, path, &resolved); |
c9f620bf YW |
4411 | if (r < 0) { |
4412 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
4413 | "Failed to resolve unit specifiers in '%s', ignoring: %m", path); | |
4414 | return 0; | |
4415 | } | |
13c31542 | 4416 | |
2f4d31c1 YW |
4417 | r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue); |
4418 | if (r < 0) | |
4419 | return 0; | |
4420 | ||
9d5e9b4a | 4421 | if (streq("infinity", p)) |
13c31542 | 4422 | num = CGROUP_LIMIT_MAX; |
9d5e9b4a | 4423 | else { |
c9f620bf | 4424 | r = parse_size(p, 1000, &num); |
13c31542 | 4425 | if (r < 0 || num <= 0) { |
323dda78 | 4426 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid IO limit '%s', ignoring.", p); |
13c31542 TH |
4427 | return 0; |
4428 | } | |
4429 | } | |
4430 | ||
03677889 | 4431 | LIST_FOREACH(device_limits, t, c->io_device_limits) |
c9f620bf | 4432 | if (path_equal(resolved, t->path)) { |
13c31542 TH |
4433 | l = t; |
4434 | break; | |
4435 | } | |
13c31542 TH |
4436 | |
4437 | if (!l) { | |
4438 | l = new0(CGroupIODeviceLimit, 1); | |
4439 | if (!l) | |
4440 | return log_oom(); | |
4441 | ||
c9f620bf | 4442 | l->path = TAKE_PTR(resolved); |
24aaf6c6 ZJS |
4443 | for (CGroupIOLimitType i = 0; i < _CGROUP_IO_LIMIT_TYPE_MAX; i++) |
4444 | l->limits[i] = cgroup_io_limit_defaults[i]; | |
13c31542 TH |
4445 | |
4446 | LIST_PREPEND(device_limits, c->io_device_limits, l); | |
4447 | } | |
4448 | ||
9be57249 | 4449 | l->limits[type] = num; |
13c31542 TH |
4450 | |
4451 | return 0; | |
4452 | } | |
4453 | ||
8e7076ca LP |
4454 | int config_parse_blockio_device_weight( |
4455 | const char *unit, | |
4456 | const char *filename, | |
4457 | unsigned line, | |
4458 | const char *section, | |
71a61510 | 4459 | unsigned section_line, |
8e7076ca LP |
4460 | const char *lvalue, |
4461 | int ltype, | |
4462 | const char *rvalue, | |
4463 | void *data, | |
4464 | void *userdata) { | |
4465 | ||
c9f620bf | 4466 | _cleanup_free_ char *path = NULL, *resolved = NULL; |
8e7076ca | 4467 | CGroupBlockIODeviceWeight *w; |
4ad49000 | 4468 | CGroupContext *c = data; |
99534007 | 4469 | const char *p = ASSERT_PTR(rvalue); |
d53d9474 | 4470 | uint64_t u; |
4ad49000 LP |
4471 | int r; |
4472 | ||
4473 | assert(filename); | |
4474 | assert(lvalue); | |
4ad49000 | 4475 | |
c1e701e2 LP |
4476 | log_syntax(unit, LOG_WARNING, filename, line, 0, |
4477 | "Unit uses %s=; please use IO*= settings instead. Support for %s= will be removed soon.", | |
4478 | lvalue, lvalue); | |
4479 | ||
4ad49000 | 4480 | if (isempty(rvalue)) { |
4ad49000 LP |
4481 | while (c->blockio_device_weights) |
4482 | cgroup_context_free_blockio_device_weight(c, c->blockio_device_weights); | |
4483 | ||
4484 | return 0; | |
4485 | } | |
4486 | ||
4ec85141 | 4487 | r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE); |
c9f620bf YW |
4488 | if (r == -ENOMEM) |
4489 | return log_oom(); | |
6a35d52d | 4490 | if (r < 0) { |
c9f620bf | 4491 | log_syntax(unit, LOG_WARNING, filename, line, r, |
c9f620bf | 4492 | "Failed to extract device node and weight from '%s', ignoring.", rvalue); |
8e7076ca LP |
4493 | return 0; |
4494 | } | |
6a35d52d YW |
4495 | if (r == 0 || isempty(p)) { |
4496 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
4497 | "Invalid device node or weight specified in '%s', ignoring.", rvalue); | |
4498 | return 0; | |
4499 | } | |
4ad49000 | 4500 | |
06536492 | 4501 | r = unit_path_printf(userdata, path, &resolved); |
c9f620bf YW |
4502 | if (r < 0) { |
4503 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
4504 | "Failed to resolve unit specifiers in '%s', ignoring: %m", path); | |
4505 | return 0; | |
4506 | } | |
4ad49000 | 4507 | |
2f4d31c1 YW |
4508 | r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue); |
4509 | if (r < 0) | |
4510 | return 0; | |
4511 | ||
c9f620bf | 4512 | r = cg_blkio_weight_parse(p, &u); |
d53d9474 | 4513 | if (r < 0) { |
323dda78 | 4514 | log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid block IO weight '%s', ignoring: %m", p); |
4ad49000 LP |
4515 | return 0; |
4516 | } | |
4517 | ||
d53d9474 LP |
4518 | assert(u != CGROUP_BLKIO_WEIGHT_INVALID); |
4519 | ||
8e7076ca LP |
4520 | w = new0(CGroupBlockIODeviceWeight, 1); |
4521 | if (!w) | |
4522 | return log_oom(); | |
4ad49000 | 4523 | |
c9f620bf | 4524 | w->path = TAKE_PTR(resolved); |
d53d9474 | 4525 | w->weight = u; |
4ad49000 | 4526 | |
71fda00f | 4527 | LIST_PREPEND(device_weights, c->blockio_device_weights, w); |
4ad49000 LP |
4528 | return 0; |
4529 | } | |
4530 | ||
4531 | int config_parse_blockio_bandwidth( | |
4532 | const char *unit, | |
4533 | const char *filename, | |
4534 | unsigned line, | |
4535 | const char *section, | |
71a61510 | 4536 | unsigned section_line, |
4ad49000 LP |
4537 | const char *lvalue, |
4538 | int ltype, | |
4539 | const char *rvalue, | |
4540 | void *data, | |
4541 | void *userdata) { | |
4542 | ||
c9f620bf | 4543 | _cleanup_free_ char *path = NULL, *resolved = NULL; |
03677889 | 4544 | CGroupBlockIODeviceBandwidth *b = NULL; |
4ad49000 | 4545 | CGroupContext *c = data; |
99534007 | 4546 | const char *p = ASSERT_PTR(rvalue); |
59f448cf | 4547 | uint64_t bytes; |
47c0980d | 4548 | bool read; |
4ad49000 LP |
4549 | int r; |
4550 | ||
4551 | assert(filename); | |
4552 | assert(lvalue); | |
4ad49000 | 4553 | |
c1e701e2 LP |
4554 | log_syntax(unit, LOG_WARNING, filename, line, 0, |
4555 | "Unit uses %s=; please use IO*= settings instead. Support for %s= will be removed soon.", | |
4556 | lvalue, lvalue); | |
4557 | ||
47c0980d G |
4558 | read = streq("BlockIOReadBandwidth", lvalue); |
4559 | ||
4ad49000 | 4560 | if (isempty(rvalue)) { |
03677889 YW |
4561 | LIST_FOREACH(device_bandwidths, t, c->blockio_device_bandwidths) { |
4562 | t->rbps = CGROUP_LIMIT_MAX; | |
4563 | t->wbps = CGROUP_LIMIT_MAX; | |
979d0311 | 4564 | } |
4ad49000 LP |
4565 | return 0; |
4566 | } | |
4567 | ||
4ec85141 | 4568 | r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE); |
c9f620bf YW |
4569 | if (r == -ENOMEM) |
4570 | return log_oom(); | |
6a35d52d | 4571 | if (r < 0) { |
c9f620bf | 4572 | log_syntax(unit, LOG_WARNING, filename, line, r, |
c9f620bf | 4573 | "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue); |
4ad49000 LP |
4574 | return 0; |
4575 | } | |
6a35d52d YW |
4576 | if (r == 0 || isempty(p)) { |
4577 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
4578 | "Invalid device node or bandwidth specified in '%s', ignoring.", rvalue); | |
4579 | return 0; | |
4580 | } | |
4ad49000 | 4581 | |
06536492 | 4582 | r = unit_path_printf(userdata, path, &resolved); |
c9f620bf YW |
4583 | if (r < 0) { |
4584 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
4585 | "Failed to resolve unit specifiers in '%s', ignoring: %m", path); | |
4586 | return 0; | |
4587 | } | |
4ad49000 | 4588 | |
2f4d31c1 YW |
4589 | r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue); |
4590 | if (r < 0) | |
4591 | return 0; | |
4592 | ||
c9f620bf | 4593 | r = parse_size(p, 1000, &bytes); |
4ad49000 | 4594 | if (r < 0 || bytes <= 0) { |
323dda78 | 4595 | log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid Block IO Bandwidth '%s', ignoring.", p); |
4ad49000 LP |
4596 | return 0; |
4597 | } | |
4598 | ||
03677889 | 4599 | LIST_FOREACH(device_bandwidths, t, c->blockio_device_bandwidths) |
c9f620bf | 4600 | if (path_equal(resolved, t->path)) { |
979d0311 TH |
4601 | b = t; |
4602 | break; | |
4603 | } | |
4ad49000 | 4604 | |
03677889 | 4605 | if (!b) { |
979d0311 TH |
4606 | b = new0(CGroupBlockIODeviceBandwidth, 1); |
4607 | if (!b) | |
4608 | return log_oom(); | |
4609 | ||
c9f620bf | 4610 | b->path = TAKE_PTR(resolved); |
979d0311 TH |
4611 | b->rbps = CGROUP_LIMIT_MAX; |
4612 | b->wbps = CGROUP_LIMIT_MAX; | |
4613 | ||
4614 | LIST_PREPEND(device_bandwidths, c->blockio_device_bandwidths, b); | |
4615 | } | |
4ad49000 | 4616 | |
979d0311 TH |
4617 | if (read) |
4618 | b->rbps = bytes; | |
4619 | else | |
4620 | b->wbps = bytes; | |
4ad49000 LP |
4621 | |
4622 | return 0; | |
4623 | } | |
4624 | ||
d420282b LP |
4625 | int config_parse_job_mode_isolate( |
4626 | const char *unit, | |
4627 | const char *filename, | |
4628 | unsigned line, | |
4629 | const char *section, | |
4630 | unsigned section_line, | |
4631 | const char *lvalue, | |
4632 | int ltype, | |
4633 | const char *rvalue, | |
4634 | void *data, | |
4635 | void *userdata) { | |
4636 | ||
4637 | JobMode *m = data; | |
4638 | int r; | |
4639 | ||
4640 | assert(filename); | |
4641 | assert(lvalue); | |
4642 | assert(rvalue); | |
4643 | ||
4644 | r = parse_boolean(rvalue); | |
4645 | if (r < 0) { | |
323dda78 | 4646 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse boolean, ignoring: %s", rvalue); |
d420282b LP |
4647 | return 0; |
4648 | } | |
4649 | ||
8ab39347 YW |
4650 | log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue); |
4651 | ||
d420282b LP |
4652 | *m = r ? JOB_ISOLATE : JOB_REPLACE; |
4653 | return 0; | |
4654 | } | |
4655 | ||
3536f49e | 4656 | int config_parse_exec_directories( |
e66cf1a3 LP |
4657 | const char *unit, |
4658 | const char *filename, | |
4659 | unsigned line, | |
4660 | const char *section, | |
4661 | unsigned section_line, | |
4662 | const char *lvalue, | |
4663 | int ltype, | |
4664 | const char *rvalue, | |
4665 | void *data, | |
4666 | void *userdata) { | |
4667 | ||
99534007 | 4668 | ExecDirectory *ed = ASSERT_PTR(data); |
47538b76 | 4669 | const Unit *u = userdata; |
e66cf1a3 LP |
4670 | int r; |
4671 | ||
4672 | assert(filename); | |
4673 | assert(lvalue); | |
4674 | assert(rvalue); | |
e66cf1a3 LP |
4675 | |
4676 | if (isempty(rvalue)) { | |
4677 | /* Empty assignment resets the list */ | |
211a3d87 | 4678 | exec_directory_done(ed); |
e66cf1a3 LP |
4679 | return 0; |
4680 | } | |
4681 | ||
323dda78 | 4682 | for (const char *p = rvalue;;) { |
211a3d87 | 4683 | _cleanup_free_ char *tuple = NULL; |
e66cf1a3 | 4684 | |
211a3d87 | 4685 | r = extract_first_word(&p, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE); |
035fe294 | 4686 | if (r == -ENOMEM) |
e66cf1a3 | 4687 | return log_oom(); |
035fe294 ZJS |
4688 | if (r < 0) { |
4689 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
211a3d87 | 4690 | "Invalid syntax %s=%s, ignoring: %m", lvalue, rvalue); |
035fe294 ZJS |
4691 | return 0; |
4692 | } | |
091e9efe LP |
4693 | if (r == 0) |
4694 | return 0; | |
e66cf1a3 | 4695 | |
211a3d87 LB |
4696 | _cleanup_free_ char *src = NULL, *dest = NULL; |
4697 | const char *q = tuple; | |
4698 | r = extract_many_words(&q, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &src, &dest, NULL); | |
4699 | if (r == -ENOMEM) | |
4700 | return log_oom(); | |
4701 | if (r <= 0) { | |
5afdb462 | 4702 | log_syntax(unit, LOG_WARNING, filename, line, r, |
211a3d87 LB |
4703 | "Invalid syntax in %s=, ignoring: %s", lvalue, tuple); |
4704 | return 0; | |
4705 | } | |
4706 | ||
4707 | _cleanup_free_ char *sresolved = NULL; | |
4708 | r = unit_path_printf(u, src, &sresolved); | |
9b5864d9 | 4709 | if (r < 0) { |
330f8990 | 4710 | log_syntax(unit, LOG_WARNING, filename, line, r, |
211a3d87 | 4711 | "Failed to resolve unit specifiers in \"%s\", ignoring: %m", src); |
9b5864d9 MG |
4712 | continue; |
4713 | } | |
4714 | ||
211a3d87 | 4715 | r = path_simplify_and_warn(sresolved, PATH_CHECK_RELATIVE, unit, filename, line, lvalue); |
2f4d31c1 | 4716 | if (r < 0) |
e8865688 | 4717 | continue; |
e8865688 | 4718 | |
211a3d87 | 4719 | if (path_startswith(sresolved, "private")) { |
330f8990 | 4720 | log_syntax(unit, LOG_WARNING, filename, line, 0, |
211a3d87 | 4721 | "%s= path can't be 'private', ignoring assignment: %s", lvalue, tuple); |
e66cf1a3 LP |
4722 | continue; |
4723 | } | |
4724 | ||
211a3d87 LB |
4725 | /* For State and Runtime directories we support an optional destination parameter, which |
4726 | * will be used to create a symlink to the source. */ | |
564e5c98 | 4727 | _cleanup_free_ char *dresolved = NULL; |
211a3d87 | 4728 | if (!isempty(dest)) { |
211a3d87 LB |
4729 | if (streq(lvalue, "ConfigurationDirectory")) { |
4730 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
4731 | "Destination parameter is not supported for ConfigurationDirectory, ignoring: %s", tuple); | |
4732 | continue; | |
4733 | } | |
4734 | ||
4735 | r = unit_path_printf(u, dest, &dresolved); | |
4736 | if (r < 0) { | |
4737 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
4738 | "Failed to resolve unit specifiers in \"%s\", ignoring: %m", dest); | |
4739 | continue; | |
4740 | } | |
4741 | ||
4742 | r = path_simplify_and_warn(dresolved, PATH_CHECK_RELATIVE, unit, filename, line, lvalue); | |
4743 | if (r < 0) | |
4744 | continue; | |
211a3d87 LB |
4745 | } |
4746 | ||
564e5c98 | 4747 | r = exec_directory_add(ed, sresolved, dresolved); |
e66cf1a3 LP |
4748 | if (r < 0) |
4749 | return log_oom(); | |
e66cf1a3 | 4750 | } |
e66cf1a3 LP |
4751 | } |
4752 | ||
bb0c0d6f LP |
4753 | int config_parse_set_credential( |
4754 | const char *unit, | |
4755 | const char *filename, | |
4756 | unsigned line, | |
4757 | const char *section, | |
4758 | unsigned section_line, | |
4759 | const char *lvalue, | |
4760 | int ltype, | |
4761 | const char *rvalue, | |
4762 | void *data, | |
4763 | void *userdata) { | |
4764 | ||
43144be4 LP |
4765 | _cleanup_free_ char *word = NULL, *k = NULL; |
4766 | _cleanup_free_ void *d = NULL; | |
99534007 | 4767 | ExecContext *context = ASSERT_PTR(data); |
bb0c0d6f LP |
4768 | ExecSetCredential *old; |
4769 | Unit *u = userdata; | |
43144be4 | 4770 | bool encrypted = ltype; |
99534007 | 4771 | const char *p = ASSERT_PTR(rvalue); |
43144be4 LP |
4772 | size_t size; |
4773 | int r; | |
bb0c0d6f LP |
4774 | |
4775 | assert(filename); | |
4776 | assert(lvalue); | |
bb0c0d6f LP |
4777 | |
4778 | if (isempty(rvalue)) { | |
4779 | /* Empty assignment resets the list */ | |
4780 | context->set_credentials = hashmap_free(context->set_credentials); | |
4781 | return 0; | |
4782 | } | |
4783 | ||
bb0c0d6f LP |
4784 | r = extract_first_word(&p, &word, ":", EXTRACT_DONT_COALESCE_SEPARATORS); |
4785 | if (r == -ENOMEM) | |
4786 | return log_oom(); | |
6a35d52d YW |
4787 | if (r < 0) { |
4788 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to extract credential name, ignoring: %s", rvalue); | |
4789 | return 0; | |
4790 | } | |
4791 | if (r == 0 || isempty(p)) { | |
4792 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid syntax, ignoring: %s", rvalue); | |
bb0c0d6f LP |
4793 | return 0; |
4794 | } | |
4795 | ||
06536492 | 4796 | r = unit_cred_printf(u, word, &k); |
bb0c0d6f LP |
4797 | if (r < 0) { |
4798 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word); | |
4799 | return 0; | |
4800 | } | |
4801 | if (!credential_name_valid(k)) { | |
4802 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Credential name \"%s\" not valid, ignoring.", k); | |
4803 | return 0; | |
4804 | } | |
4805 | ||
43144be4 LP |
4806 | if (encrypted) { |
4807 | r = unbase64mem_full(p, SIZE_MAX, true, &d, &size); | |
4808 | if (r < 0) { | |
4809 | log_syntax(unit, LOG_WARNING, filename, line, r, "Encrypted credential data not valid Base64 data, ignoring."); | |
4810 | return 0; | |
4811 | } | |
4812 | } else { | |
1421705d | 4813 | char *unescaped; |
e437538f | 4814 | ssize_t l; |
43144be4 LP |
4815 | |
4816 | /* We support escape codes here, so that users can insert trailing \n if they like */ | |
4817 | l = cunescape(p, UNESCAPE_ACCEPT_NUL, &unescaped); | |
4818 | if (l < 0) { | |
4819 | log_syntax(unit, LOG_WARNING, filename, line, l, "Can't unescape \"%s\", ignoring: %m", p); | |
4820 | return 0; | |
4821 | } | |
4822 | ||
4823 | d = unescaped; | |
4824 | size = l; | |
bb0c0d6f LP |
4825 | } |
4826 | ||
4827 | old = hashmap_get(context->set_credentials, k); | |
4828 | if (old) { | |
43144be4 LP |
4829 | free_and_replace(old->data, d); |
4830 | old->size = size; | |
4831 | old->encrypted = encrypted; | |
bb0c0d6f LP |
4832 | } else { |
4833 | _cleanup_(exec_set_credential_freep) ExecSetCredential *sc = NULL; | |
4834 | ||
43144be4 | 4835 | sc = new(ExecSetCredential, 1); |
bb0c0d6f LP |
4836 | if (!sc) |
4837 | return log_oom(); | |
4838 | ||
43144be4 LP |
4839 | *sc = (ExecSetCredential) { |
4840 | .id = TAKE_PTR(k), | |
4841 | .data = TAKE_PTR(d), | |
4842 | .size = size, | |
4843 | .encrypted = encrypted, | |
4844 | }; | |
bb0c0d6f | 4845 | |
f85f5f0d SS |
4846 | r = hashmap_ensure_put(&context->set_credentials, &exec_set_credential_hash_ops, sc->id, sc); |
4847 | if (r == -ENOMEM) | |
4848 | return log_oom(); | |
2400743e | 4849 | if (r < 0) { |
43144be4 | 4850 | log_syntax(unit, LOG_WARNING, filename, line, r, |
2400743e YW |
4851 | "Duplicated credential value '%s', ignoring assignment: %s", sc->id, rvalue); |
4852 | return 0; | |
4853 | } | |
bb0c0d6f | 4854 | |
bb0c0d6f LP |
4855 | TAKE_PTR(sc); |
4856 | } | |
4857 | ||
4858 | return 0; | |
4859 | } | |
4860 | ||
bbfb25f4 DDM |
4861 | int hashmap_put_credential(Hashmap **h, const char *id, const char *path, bool encrypted) { |
4862 | ExecLoadCredential *old; | |
4863 | int r; | |
4864 | ||
4865 | assert(h); | |
4866 | assert(id); | |
4867 | assert(path); | |
4868 | ||
4869 | old = hashmap_get(*h, id); | |
4870 | if (old) { | |
4871 | r = free_and_strdup(&old->path, path); | |
4872 | if (r < 0) | |
4873 | return r; | |
4874 | ||
4875 | old->encrypted = encrypted; | |
4876 | } else { | |
4877 | _cleanup_(exec_load_credential_freep) ExecLoadCredential *lc = NULL; | |
4878 | ||
4879 | lc = new(ExecLoadCredential, 1); | |
4880 | if (!lc) | |
4881 | return log_oom(); | |
4882 | ||
4883 | *lc = (ExecLoadCredential) { | |
4884 | .id = strdup(id), | |
4885 | .path = strdup(path), | |
4886 | .encrypted = encrypted, | |
4887 | }; | |
4888 | if (!lc->id || !lc->path) | |
4889 | return -ENOMEM; | |
4890 | ||
4891 | r = hashmap_ensure_put(h, &exec_load_credential_hash_ops, lc->id, lc); | |
4892 | if (r < 0) | |
4893 | return r; | |
4894 | ||
4895 | TAKE_PTR(lc); | |
4896 | } | |
4897 | ||
4898 | return 0; | |
4899 | } | |
4900 | ||
bb0c0d6f LP |
4901 | int config_parse_load_credential( |
4902 | const char *unit, | |
4903 | const char *filename, | |
4904 | unsigned line, | |
4905 | const char *section, | |
4906 | unsigned section_line, | |
4907 | const char *lvalue, | |
4908 | int ltype, | |
4909 | const char *rvalue, | |
4910 | void *data, | |
4911 | void *userdata) { | |
4912 | ||
4913 | _cleanup_free_ char *word = NULL, *k = NULL, *q = NULL; | |
99534007 | 4914 | ExecContext *context = ASSERT_PTR(data); |
43144be4 | 4915 | bool encrypted = ltype; |
bb0c0d6f LP |
4916 | Unit *u = userdata; |
4917 | const char *p; | |
4918 | int r; | |
4919 | ||
4920 | assert(filename); | |
4921 | assert(lvalue); | |
4922 | assert(rvalue); | |
bb0c0d6f LP |
4923 | |
4924 | if (isempty(rvalue)) { | |
4925 | /* Empty assignment resets the list */ | |
43144be4 | 4926 | context->load_credentials = hashmap_free(context->load_credentials); |
bb0c0d6f LP |
4927 | return 0; |
4928 | } | |
4929 | ||
4930 | p = rvalue; | |
4931 | r = extract_first_word(&p, &word, ":", EXTRACT_DONT_COALESCE_SEPARATORS); | |
4932 | if (r == -ENOMEM) | |
4933 | return log_oom(); | |
4934 | if (r <= 0) { | |
4935 | log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue); | |
4936 | return 0; | |
4937 | } | |
4938 | ||
06536492 | 4939 | r = unit_cred_printf(u, word, &k); |
bb0c0d6f LP |
4940 | if (r < 0) { |
4941 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word); | |
4942 | return 0; | |
4943 | } | |
4944 | if (!credential_name_valid(k)) { | |
4945 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Credential name \"%s\" not valid, ignoring.", k); | |
4946 | return 0; | |
4947 | } | |
8a29862e LP |
4948 | |
4949 | if (isempty(p)) { | |
08a7e545 | 4950 | /* If only one field is specified take it as shortcut for inheriting a credential named |
8a29862e LP |
4951 | * the same way from our parent */ |
4952 | q = strdup(k); | |
4953 | if (!q) | |
4954 | return log_oom(); | |
4955 | } else { | |
06536492 | 4956 | r = unit_path_printf(u, p, &q); |
8a29862e LP |
4957 | if (r < 0) { |
4958 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", p); | |
4959 | return 0; | |
4960 | } | |
4961 | if (path_is_absolute(q) ? !path_is_normalized(q) : !credential_name_valid(q)) { | |
43144be4 | 4962 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Credential source \"%s\" not valid, ignoring.", q); |
8a29862e LP |
4963 | return 0; |
4964 | } | |
bb0c0d6f LP |
4965 | } |
4966 | ||
bbfb25f4 DDM |
4967 | r = hashmap_put_credential(&context->load_credentials, k, q, encrypted); |
4968 | if (r < 0) | |
4969 | return log_error_errno(r, "Failed to store load credential '%s': %m", rvalue); | |
43144be4 | 4970 | |
bbfb25f4 DDM |
4971 | return 0; |
4972 | } | |
43144be4 | 4973 | |
bbfb25f4 DDM |
4974 | int config_parse_import_credential( |
4975 | const char *unit, | |
4976 | const char *filename, | |
4977 | unsigned line, | |
4978 | const char *section, | |
4979 | unsigned section_line, | |
4980 | const char *lvalue, | |
4981 | int ltype, | |
4982 | const char *rvalue, | |
4983 | void *data, | |
4984 | void *userdata) { | |
43144be4 | 4985 | |
bbfb25f4 DDM |
4986 | _cleanup_free_ char *s = NULL; |
4987 | Set** import_credentials = ASSERT_PTR(data); | |
4988 | Unit *u = userdata; | |
4989 | int r; | |
43144be4 | 4990 | |
bbfb25f4 DDM |
4991 | assert(filename); |
4992 | assert(lvalue); | |
4993 | assert(rvalue); | |
4994 | ||
4995 | if (isempty(rvalue)) { | |
4996 | /* Empty assignment resets the list */ | |
1a572fd0 | 4997 | *import_credentials = set_free_free(*import_credentials); |
bbfb25f4 DDM |
4998 | return 0; |
4999 | } | |
5000 | ||
5001 | r = unit_cred_printf(u, rvalue, &s); | |
5002 | if (r < 0) { | |
5003 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s); | |
5004 | return 0; | |
5005 | } | |
947c4d39 LP |
5006 | if (!credential_glob_valid(s)) { |
5007 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Credential name or glob \"%s\" not valid, ignoring.", s); | |
bbfb25f4 | 5008 | return 0; |
43144be4 | 5009 | } |
bb0c0d6f | 5010 | |
bbfb25f4 DDM |
5011 | r = set_put_strdup(import_credentials, s); |
5012 | if (r < 0) | |
5013 | return log_error_errno(r, "Failed to store credential name '%s': %m", rvalue); | |
5014 | ||
bb0c0d6f LP |
5015 | return 0; |
5016 | } | |
5017 | ||
3af00fb8 LP |
5018 | int config_parse_set_status( |
5019 | const char *unit, | |
5020 | const char *filename, | |
5021 | unsigned line, | |
5022 | const char *section, | |
5023 | unsigned section_line, | |
5024 | const char *lvalue, | |
5025 | int ltype, | |
5026 | const char *rvalue, | |
5027 | void *data, | |
5028 | void *userdata) { | |
5029 | ||
99534007 | 5030 | ExitStatusSet *status_set = ASSERT_PTR(data); |
7896ad8f | 5031 | int r; |
3af00fb8 LP |
5032 | |
5033 | assert(filename); | |
5034 | assert(lvalue); | |
5035 | assert(rvalue); | |
3af00fb8 | 5036 | |
3e2d435b | 5037 | /* Empty assignment resets the list */ |
3af00fb8 | 5038 | if (isempty(rvalue)) { |
3e2d435b | 5039 | exit_status_set_free(status_set); |
3af00fb8 LP |
5040 | return 0; |
5041 | } | |
5042 | ||
7896ad8f ZJS |
5043 | for (const char *p = rvalue;;) { |
5044 | _cleanup_free_ char *word = NULL; | |
23d5dd16 | 5045 | Bitmap *bitmap; |
3af00fb8 | 5046 | |
7896ad8f | 5047 | r = extract_first_word(&p, &word, NULL, 0); |
323dda78 YW |
5048 | if (r == -ENOMEM) |
5049 | return log_oom(); | |
5050 | if (r < 0) { | |
5051 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
5052 | "Failed to parse %s=%s, ignoring: %m", lvalue, rvalue); | |
5053 | return 0; | |
5054 | } | |
7896ad8f ZJS |
5055 | if (r == 0) |
5056 | return 0; | |
3af00fb8 | 5057 | |
2e2ed880 ZJS |
5058 | /* We need to call exit_status_from_string() first, because we want |
5059 | * to parse numbers as exit statuses, not signals. */ | |
3af00fb8 | 5060 | |
7896ad8f | 5061 | r = exit_status_from_string(word); |
2e2ed880 ZJS |
5062 | if (r >= 0) { |
5063 | assert(r >= 0 && r < 256); | |
5064 | bitmap = &status_set->status; | |
3af00fb8 | 5065 | } else { |
7896ad8f ZJS |
5066 | r = signal_from_string(word); |
5067 | if (r < 0) { | |
b98680b2 | 5068 | log_syntax(unit, LOG_WARNING, filename, line, r, |
2e2ed880 | 5069 | "Failed to parse value, ignoring: %s", word); |
1e2fd62d | 5070 | continue; |
3af00fb8 | 5071 | } |
2e2ed880 | 5072 | bitmap = &status_set->signal; |
3af00fb8 | 5073 | } |
1e2fd62d | 5074 | |
2e2ed880 | 5075 | r = bitmap_set(bitmap, r); |
063c4b1a | 5076 | if (r < 0) |
323dda78 YW |
5077 | log_syntax(unit, LOG_WARNING, filename, line, r, |
5078 | "Failed to set signal or status %s, ignoring: %m", word); | |
3af00fb8 | 5079 | } |
3af00fb8 LP |
5080 | } |
5081 | ||
94828d2d LP |
5082 | int config_parse_namespace_path_strv( |
5083 | const char *unit, | |
5084 | const char *filename, | |
5085 | unsigned line, | |
5086 | const char *section, | |
5087 | unsigned section_line, | |
5088 | const char *lvalue, | |
5089 | int ltype, | |
5090 | const char *rvalue, | |
5091 | void *data, | |
5092 | void *userdata) { | |
5093 | ||
47538b76 | 5094 | const Unit *u = userdata; |
99534007 | 5095 | char*** sv = ASSERT_PTR(data); |
94828d2d LP |
5096 | int r; |
5097 | ||
5098 | assert(filename); | |
5099 | assert(lvalue); | |
5100 | assert(rvalue); | |
94828d2d LP |
5101 | |
5102 | if (isempty(rvalue)) { | |
5103 | /* Empty assignment resets the list */ | |
6796073e | 5104 | *sv = strv_free(*sv); |
94828d2d LP |
5105 | return 0; |
5106 | } | |
5107 | ||
323dda78 | 5108 | for (const char *p = rvalue;;) { |
7b07e993 | 5109 | _cleanup_free_ char *word = NULL, *resolved = NULL, *joined = NULL; |
20b7a007 LP |
5110 | const char *w; |
5111 | bool ignore_enoent = false, shall_prefix = false; | |
94828d2d | 5112 | |
4ec85141 | 5113 | r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); |
0293a7a8 EV |
5114 | if (r == -ENOMEM) |
5115 | return log_oom(); | |
727f76d7 | 5116 | if (r < 0) { |
323dda78 | 5117 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to extract first word, ignoring: %s", rvalue); |
727f76d7 EV |
5118 | return 0; |
5119 | } | |
a687f500 ZJS |
5120 | if (r == 0) |
5121 | break; | |
94828d2d | 5122 | |
20b7a007 LP |
5123 | w = word; |
5124 | if (startswith(w, "-")) { | |
5125 | ignore_enoent = true; | |
5126 | w++; | |
5127 | } | |
5128 | if (startswith(w, "+")) { | |
5129 | shall_prefix = true; | |
5130 | w++; | |
5131 | } | |
7b07e993 | 5132 | |
06536492 | 5133 | r = unit_path_printf(u, w, &resolved); |
7b07e993 | 5134 | if (r < 0) { |
323dda78 | 5135 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s: %m", w); |
94828d2d LP |
5136 | continue; |
5137 | } | |
5138 | ||
2f4d31c1 YW |
5139 | r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
5140 | if (r < 0) | |
7b07e993 | 5141 | continue; |
94828d2d | 5142 | |
20b7a007 LP |
5143 | joined = strjoin(ignore_enoent ? "-" : "", |
5144 | shall_prefix ? "+" : "", | |
5145 | resolved); | |
7b07e993 LP |
5146 | |
5147 | r = strv_push(sv, joined); | |
94828d2d LP |
5148 | if (r < 0) |
5149 | return log_oom(); | |
5150 | ||
7b07e993 | 5151 | joined = NULL; |
94828d2d LP |
5152 | } |
5153 | ||
5154 | return 0; | |
5155 | } | |
5156 | ||
2abd4e38 YW |
5157 | int config_parse_temporary_filesystems( |
5158 | const char *unit, | |
5159 | const char *filename, | |
5160 | unsigned line, | |
5161 | const char *section, | |
5162 | unsigned section_line, | |
5163 | const char *lvalue, | |
5164 | int ltype, | |
5165 | const char *rvalue, | |
5166 | void *data, | |
5167 | void *userdata) { | |
5168 | ||
47538b76 | 5169 | const Unit *u = userdata; |
99534007 | 5170 | ExecContext *c = ASSERT_PTR(data); |
2abd4e38 YW |
5171 | int r; |
5172 | ||
5173 | assert(filename); | |
5174 | assert(lvalue); | |
5175 | assert(rvalue); | |
2abd4e38 YW |
5176 | |
5177 | if (isempty(rvalue)) { | |
5178 | /* Empty assignment resets the list */ | |
5179 | temporary_filesystem_free_many(c->temporary_filesystems, c->n_temporary_filesystems); | |
5180 | c->temporary_filesystems = NULL; | |
5181 | c->n_temporary_filesystems = 0; | |
5182 | return 0; | |
5183 | } | |
5184 | ||
323dda78 | 5185 | for (const char *p = rvalue;;) { |
2abd4e38 YW |
5186 | _cleanup_free_ char *word = NULL, *path = NULL, *resolved = NULL; |
5187 | const char *w; | |
5188 | ||
4ec85141 | 5189 | r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); |
2abd4e38 YW |
5190 | if (r == -ENOMEM) |
5191 | return log_oom(); | |
5192 | if (r < 0) { | |
323dda78 | 5193 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to extract first word, ignoring: %s", rvalue); |
2abd4e38 YW |
5194 | return 0; |
5195 | } | |
a687f500 ZJS |
5196 | if (r == 0) |
5197 | return 0; | |
2abd4e38 YW |
5198 | |
5199 | w = word; | |
5200 | r = extract_first_word(&w, &path, ":", EXTRACT_DONT_COALESCE_SEPARATORS); | |
063c4b1a YW |
5201 | if (r == -ENOMEM) |
5202 | return log_oom(); | |
5203 | if (r < 0) { | |
323dda78 | 5204 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to extract first word, ignoring: %s", word); |
063c4b1a YW |
5205 | continue; |
5206 | } | |
5207 | if (r == 0) { | |
323dda78 | 5208 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid syntax, ignoring: %s", word); |
063c4b1a YW |
5209 | continue; |
5210 | } | |
2abd4e38 | 5211 | |
06536492 | 5212 | r = unit_path_printf(u, path, &resolved); |
2abd4e38 | 5213 | if (r < 0) { |
323dda78 | 5214 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", path); |
2abd4e38 YW |
5215 | continue; |
5216 | } | |
5217 | ||
2f4d31c1 YW |
5218 | r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
5219 | if (r < 0) | |
2abd4e38 | 5220 | continue; |
2abd4e38 | 5221 | |
a26fec24 | 5222 | r = temporary_filesystem_add(&c->temporary_filesystems, &c->n_temporary_filesystems, resolved, w); |
6302d1ea | 5223 | if (r < 0) |
2abd4e38 | 5224 | return log_oom(); |
2abd4e38 | 5225 | } |
2abd4e38 YW |
5226 | } |
5227 | ||
d2d6c096 LP |
5228 | int config_parse_bind_paths( |
5229 | const char *unit, | |
5230 | const char *filename, | |
5231 | unsigned line, | |
5232 | const char *section, | |
5233 | unsigned section_line, | |
5234 | const char *lvalue, | |
5235 | int ltype, | |
5236 | const char *rvalue, | |
5237 | void *data, | |
5238 | void *userdata) { | |
5239 | ||
99534007 | 5240 | ExecContext *c = ASSERT_PTR(data); |
47538b76 | 5241 | const Unit *u = userdata; |
d2d6c096 LP |
5242 | int r; |
5243 | ||
5244 | assert(filename); | |
5245 | assert(lvalue); | |
5246 | assert(rvalue); | |
d2d6c096 LP |
5247 | |
5248 | if (isempty(rvalue)) { | |
5249 | /* Empty assignment resets the list */ | |
5250 | bind_mount_free_many(c->bind_mounts, c->n_bind_mounts); | |
5251 | c->bind_mounts = NULL; | |
5252 | c->n_bind_mounts = 0; | |
5253 | return 0; | |
5254 | } | |
5255 | ||
323dda78 | 5256 | for (const char *p = rvalue;;) { |
d2d6c096 | 5257 | _cleanup_free_ char *source = NULL, *destination = NULL; |
42d43f21 | 5258 | _cleanup_free_ char *sresolved = NULL, *dresolved = NULL; |
d2d6c096 LP |
5259 | char *s = NULL, *d = NULL; |
5260 | bool rbind = true, ignore_enoent = false; | |
5261 | ||
4ec85141 | 5262 | r = extract_first_word(&p, &source, ":" WHITESPACE, EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS); |
d2d6c096 LP |
5263 | if (r == -ENOMEM) |
5264 | return log_oom(); | |
5265 | if (r < 0) { | |
323dda78 | 5266 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s, ignoring: %s", lvalue, rvalue); |
d2d6c096 LP |
5267 | return 0; |
5268 | } | |
a687f500 ZJS |
5269 | if (r == 0) |
5270 | break; | |
d2d6c096 | 5271 | |
e195a5c1 | 5272 | r = unit_path_printf(u, source, &sresolved); |
42d43f21 | 5273 | if (r < 0) { |
323dda78 | 5274 | log_syntax(unit, LOG_WARNING, filename, line, r, |
556a7bbe | 5275 | "Failed to resolve unit specifiers in \"%s\", ignoring: %m", source); |
2f4d31c1 | 5276 | continue; |
42d43f21 DC |
5277 | } |
5278 | ||
5279 | s = sresolved; | |
d2d6c096 LP |
5280 | if (s[0] == '-') { |
5281 | ignore_enoent = true; | |
5282 | s++; | |
5283 | } | |
5284 | ||
2f4d31c1 YW |
5285 | r = path_simplify_and_warn(s, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
5286 | if (r < 0) | |
5287 | continue; | |
d2d6c096 LP |
5288 | |
5289 | /* Optionally, the destination is specified. */ | |
5290 | if (p && p[-1] == ':') { | |
4ec85141 | 5291 | r = extract_first_word(&p, &destination, ":" WHITESPACE, EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS); |
d2d6c096 LP |
5292 | if (r == -ENOMEM) |
5293 | return log_oom(); | |
5294 | if (r < 0) { | |
323dda78 | 5295 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s, ignoring: %s", lvalue, rvalue); |
d2d6c096 LP |
5296 | return 0; |
5297 | } | |
5298 | if (r == 0) { | |
323dda78 | 5299 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Missing argument after ':', ignoring: %s", s); |
2f4d31c1 | 5300 | continue; |
d2d6c096 LP |
5301 | } |
5302 | ||
06536492 | 5303 | r = unit_path_printf(u, destination, &dresolved); |
42d43f21 | 5304 | if (r < 0) { |
323dda78 | 5305 | log_syntax(unit, LOG_WARNING, filename, line, r, |
556a7bbe | 5306 | "Failed to resolve specifiers in \"%s\", ignoring: %m", destination); |
2f4d31c1 | 5307 | continue; |
42d43f21 DC |
5308 | } |
5309 | ||
2f4d31c1 YW |
5310 | r = path_simplify_and_warn(dresolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
5311 | if (r < 0) | |
5312 | continue; | |
d2d6c096 | 5313 | |
2f4d31c1 | 5314 | d = dresolved; |
d2d6c096 LP |
5315 | |
5316 | /* Optionally, there's also a short option string specified */ | |
5317 | if (p && p[-1] == ':') { | |
5318 | _cleanup_free_ char *options = NULL; | |
5319 | ||
4ec85141 | 5320 | r = extract_first_word(&p, &options, NULL, EXTRACT_UNQUOTE); |
d2d6c096 LP |
5321 | if (r == -ENOMEM) |
5322 | return log_oom(); | |
5323 | if (r < 0) { | |
6a35d52d | 5324 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s=, ignoring: %s", lvalue, rvalue); |
d2d6c096 LP |
5325 | return 0; |
5326 | } | |
5327 | ||
5328 | if (isempty(options) || streq(options, "rbind")) | |
5329 | rbind = true; | |
5330 | else if (streq(options, "norbind")) | |
5331 | rbind = false; | |
5332 | else { | |
323dda78 | 5333 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid option string, ignoring setting: %s", options); |
2f4d31c1 | 5334 | continue; |
d2d6c096 LP |
5335 | } |
5336 | } | |
5337 | } else | |
5338 | d = s; | |
5339 | ||
5340 | r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts, | |
5341 | &(BindMount) { | |
5342 | .source = s, | |
5343 | .destination = d, | |
5344 | .read_only = !!strstr(lvalue, "ReadOnly"), | |
5345 | .recursive = rbind, | |
5346 | .ignore_enoent = ignore_enoent, | |
5347 | }); | |
5348 | if (r < 0) | |
5349 | return log_oom(); | |
5350 | } | |
5351 | ||
5352 | return 0; | |
5353 | } | |
5354 | ||
b3d13314 LB |
5355 | int config_parse_mount_images( |
5356 | const char *unit, | |
5357 | const char *filename, | |
5358 | unsigned line, | |
5359 | const char *section, | |
5360 | unsigned section_line, | |
5361 | const char *lvalue, | |
5362 | int ltype, | |
5363 | const char *rvalue, | |
5364 | void *data, | |
5365 | void *userdata) { | |
5366 | ||
99534007 | 5367 | ExecContext *c = ASSERT_PTR(data); |
b3d13314 | 5368 | const Unit *u = userdata; |
b3d13314 LB |
5369 | int r; |
5370 | ||
5371 | assert(filename); | |
5372 | assert(lvalue); | |
5373 | assert(rvalue); | |
b3d13314 LB |
5374 | |
5375 | if (isempty(rvalue)) { | |
5376 | /* Empty assignment resets the list */ | |
5377 | c->mount_images = mount_image_free_many(c->mount_images, &c->n_mount_images); | |
5378 | return 0; | |
5379 | } | |
5380 | ||
323dda78 | 5381 | for (const char *p = rvalue;;) { |
427353f6 LB |
5382 | _cleanup_(mount_options_free_allp) MountOptions *options = NULL; |
5383 | _cleanup_free_ char *first = NULL, *second = NULL, *tuple = NULL; | |
b3d13314 | 5384 | _cleanup_free_ char *sresolved = NULL, *dresolved = NULL; |
427353f6 | 5385 | const char *q = NULL; |
b3d13314 LB |
5386 | char *s = NULL; |
5387 | bool permissive = false; | |
5388 | ||
427353f6 | 5389 | r = extract_first_word(&p, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE); |
323dda78 YW |
5390 | if (r == -ENOMEM) |
5391 | return log_oom(); | |
5392 | if (r < 0) { | |
5393 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
5394 | "Invalid syntax %s=%s, ignoring: %m", lvalue, rvalue); | |
5395 | return 0; | |
5396 | } | |
427353f6 | 5397 | if (r == 0) |
323dda78 | 5398 | return 0; |
427353f6 LB |
5399 | |
5400 | q = tuple; | |
5401 | r = extract_many_words(&q, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &first, &second, NULL); | |
323dda78 YW |
5402 | if (r == -ENOMEM) |
5403 | return log_oom(); | |
5404 | if (r < 0) { | |
5405 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
5406 | "Invalid syntax in %s=, ignoring: %s", lvalue, tuple); | |
5407 | return 0; | |
5408 | } | |
427353f6 LB |
5409 | if (r == 0) |
5410 | continue; | |
5411 | ||
6c3f7ca0 | 5412 | s = first; |
b3d13314 LB |
5413 | if (s[0] == '-') { |
5414 | permissive = true; | |
5415 | s++; | |
5416 | } | |
5417 | ||
06536492 | 5418 | r = unit_path_printf(u, s, &sresolved); |
6c3f7ca0 LB |
5419 | if (r < 0) { |
5420 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
5421 | "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s); | |
5422 | continue; | |
5423 | } | |
5424 | ||
5425 | r = path_simplify_and_warn(sresolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); | |
b3d13314 LB |
5426 | if (r < 0) |
5427 | continue; | |
5428 | ||
427353f6 | 5429 | if (isempty(second)) { |
323dda78 | 5430 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Missing destination in %s, ignoring: %s", lvalue, rvalue); |
b3d13314 LB |
5431 | continue; |
5432 | } | |
5433 | ||
06536492 | 5434 | r = unit_path_printf(u, second, &dresolved); |
b3d13314 | 5435 | if (r < 0) { |
323dda78 | 5436 | log_syntax(unit, LOG_WARNING, filename, line, r, |
427353f6 | 5437 | "Failed to resolve specifiers in \"%s\", ignoring: %m", second); |
b3d13314 LB |
5438 | continue; |
5439 | } | |
5440 | ||
5441 | r = path_simplify_and_warn(dresolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); | |
5442 | if (r < 0) | |
5443 | continue; | |
5444 | ||
427353f6 LB |
5445 | for (;;) { |
5446 | _cleanup_free_ char *partition = NULL, *mount_options = NULL, *mount_options_resolved = NULL; | |
5447 | MountOptions *o = NULL; | |
569a0e42 | 5448 | PartitionDesignator partition_designator; |
427353f6 LB |
5449 | |
5450 | r = extract_many_words(&q, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &partition, &mount_options, NULL); | |
323dda78 YW |
5451 | if (r == -ENOMEM) |
5452 | return log_oom(); | |
5453 | if (r < 0) { | |
5454 | log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", q); | |
5455 | return 0; | |
5456 | } | |
427353f6 LB |
5457 | if (r == 0) |
5458 | break; | |
5459 | /* Single set of options, applying to the root partition/single filesystem */ | |
5460 | if (r == 1) { | |
5461 | r = unit_full_printf(u, partition, &mount_options_resolved); | |
5462 | if (r < 0) { | |
323dda78 | 5463 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", first); |
427353f6 LB |
5464 | continue; |
5465 | } | |
5466 | ||
5467 | o = new(MountOptions, 1); | |
5468 | if (!o) | |
5469 | return log_oom(); | |
5470 | *o = (MountOptions) { | |
5471 | .partition_designator = PARTITION_ROOT, | |
5472 | .options = TAKE_PTR(mount_options_resolved), | |
5473 | }; | |
5474 | LIST_APPEND(mount_options, options, o); | |
5475 | ||
5476 | break; | |
5477 | } | |
5478 | ||
5479 | partition_designator = partition_designator_from_string(partition); | |
5480 | if (partition_designator < 0) { | |
b98680b2 YW |
5481 | log_syntax(unit, LOG_WARNING, filename, line, partition_designator, |
5482 | "Invalid partition name %s, ignoring", partition); | |
427353f6 LB |
5483 | continue; |
5484 | } | |
5485 | r = unit_full_printf(u, mount_options, &mount_options_resolved); | |
5486 | if (r < 0) { | |
323dda78 | 5487 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options); |
427353f6 LB |
5488 | continue; |
5489 | } | |
5490 | ||
5491 | o = new(MountOptions, 1); | |
5492 | if (!o) | |
5493 | return log_oom(); | |
5494 | *o = (MountOptions) { | |
5495 | .partition_designator = partition_designator, | |
5496 | .options = TAKE_PTR(mount_options_resolved), | |
5497 | }; | |
5498 | LIST_APPEND(mount_options, options, o); | |
5499 | } | |
5500 | ||
b3d13314 LB |
5501 | r = mount_image_add(&c->mount_images, &c->n_mount_images, |
5502 | &(MountImage) { | |
6c3f7ca0 | 5503 | .source = sresolved, |
b3d13314 | 5504 | .destination = dresolved, |
427353f6 | 5505 | .mount_options = options, |
b3d13314 | 5506 | .ignore_enoent = permissive, |
93f59701 LB |
5507 | .type = MOUNT_IMAGE_DISCRETE, |
5508 | }); | |
5509 | if (r < 0) | |
5510 | return log_oom(); | |
5511 | } | |
5512 | } | |
5513 | ||
5514 | int config_parse_extension_images( | |
5515 | const char *unit, | |
5516 | const char *filename, | |
5517 | unsigned line, | |
5518 | const char *section, | |
5519 | unsigned section_line, | |
5520 | const char *lvalue, | |
5521 | int ltype, | |
5522 | const char *rvalue, | |
5523 | void *data, | |
5524 | void *userdata) { | |
5525 | ||
99534007 | 5526 | ExecContext *c = ASSERT_PTR(data); |
93f59701 LB |
5527 | const Unit *u = userdata; |
5528 | int r; | |
5529 | ||
5530 | assert(filename); | |
5531 | assert(lvalue); | |
5532 | assert(rvalue); | |
93f59701 LB |
5533 | |
5534 | if (isempty(rvalue)) { | |
5535 | /* Empty assignment resets the list */ | |
5536 | c->extension_images = mount_image_free_many(c->extension_images, &c->n_extension_images); | |
5537 | return 0; | |
5538 | } | |
5539 | ||
5540 | for (const char *p = rvalue;;) { | |
5541 | _cleanup_free_ char *source = NULL, *tuple = NULL, *sresolved = NULL; | |
5542 | _cleanup_(mount_options_free_allp) MountOptions *options = NULL; | |
5543 | bool permissive = false; | |
5544 | const char *q = NULL; | |
5545 | char *s = NULL; | |
5546 | ||
5547 | r = extract_first_word(&p, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE); | |
5548 | if (r == -ENOMEM) | |
5549 | return log_oom(); | |
5550 | if (r < 0) { | |
5551 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
5552 | "Invalid syntax %s=%s, ignoring: %m", lvalue, rvalue); | |
5553 | return 0; | |
5554 | } | |
5555 | if (r == 0) | |
5556 | return 0; | |
5557 | ||
5558 | q = tuple; | |
5559 | r = extract_first_word(&q, &source, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS); | |
5560 | if (r == -ENOMEM) | |
5561 | return log_oom(); | |
5562 | if (r < 0) { | |
5563 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
5564 | "Invalid syntax in %s=, ignoring: %s", lvalue, tuple); | |
5565 | return 0; | |
5566 | } | |
5567 | if (r == 0) | |
5568 | continue; | |
5569 | ||
5570 | s = source; | |
5571 | if (s[0] == '-') { | |
5572 | permissive = true; | |
5573 | s++; | |
5574 | } | |
5575 | ||
06536492 | 5576 | r = unit_path_printf(u, s, &sresolved); |
93f59701 LB |
5577 | if (r < 0) { |
5578 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
5579 | "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s); | |
5580 | continue; | |
5581 | } | |
5582 | ||
5583 | r = path_simplify_and_warn(sresolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); | |
5584 | if (r < 0) | |
5585 | continue; | |
5586 | ||
5587 | for (;;) { | |
5588 | _cleanup_free_ char *partition = NULL, *mount_options = NULL, *mount_options_resolved = NULL; | |
5589 | MountOptions *o = NULL; | |
5590 | PartitionDesignator partition_designator; | |
5591 | ||
5592 | r = extract_many_words(&q, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &partition, &mount_options, NULL); | |
5593 | if (r == -ENOMEM) | |
5594 | return log_oom(); | |
5595 | if (r < 0) { | |
5596 | log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", q); | |
5597 | return 0; | |
5598 | } | |
5599 | if (r == 0) | |
5600 | break; | |
5601 | /* Single set of options, applying to the root partition/single filesystem */ | |
5602 | if (r == 1) { | |
5603 | r = unit_full_printf(u, partition, &mount_options_resolved); | |
5604 | if (r < 0) { | |
5605 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", partition); | |
5606 | continue; | |
5607 | } | |
5608 | ||
5609 | o = new(MountOptions, 1); | |
5610 | if (!o) | |
5611 | return log_oom(); | |
5612 | *o = (MountOptions) { | |
5613 | .partition_designator = PARTITION_ROOT, | |
5614 | .options = TAKE_PTR(mount_options_resolved), | |
5615 | }; | |
5616 | LIST_APPEND(mount_options, options, o); | |
5617 | ||
5618 | break; | |
5619 | } | |
5620 | ||
5621 | partition_designator = partition_designator_from_string(partition); | |
5622 | if (partition_designator < 0) { | |
5623 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid partition name %s, ignoring", partition); | |
5624 | continue; | |
5625 | } | |
5626 | r = unit_full_printf(u, mount_options, &mount_options_resolved); | |
5627 | if (r < 0) { | |
5628 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options); | |
5629 | continue; | |
5630 | } | |
5631 | ||
5632 | o = new(MountOptions, 1); | |
5633 | if (!o) | |
5634 | return log_oom(); | |
5635 | *o = (MountOptions) { | |
5636 | .partition_designator = partition_designator, | |
5637 | .options = TAKE_PTR(mount_options_resolved), | |
5638 | }; | |
5639 | LIST_APPEND(mount_options, options, o); | |
5640 | } | |
5641 | ||
5642 | r = mount_image_add(&c->extension_images, &c->n_extension_images, | |
5643 | &(MountImage) { | |
5644 | .source = sresolved, | |
5645 | .mount_options = options, | |
5646 | .ignore_enoent = permissive, | |
5647 | .type = MOUNT_IMAGE_EXTENSION, | |
b3d13314 LB |
5648 | }); |
5649 | if (r < 0) | |
5650 | return log_oom(); | |
5651 | } | |
b3d13314 LB |
5652 | } |
5653 | ||
eae51da3 LP |
5654 | int config_parse_job_timeout_sec( |
5655 | const char* unit, | |
5656 | const char *filename, | |
5657 | unsigned line, | |
5658 | const char *section, | |
5659 | unsigned section_line, | |
5660 | const char *lvalue, | |
5661 | int ltype, | |
5662 | const char *rvalue, | |
5663 | void *data, | |
5664 | void *userdata) { | |
5665 | ||
99534007 | 5666 | Unit *u = ASSERT_PTR(data); |
eae51da3 LP |
5667 | usec_t usec; |
5668 | int r; | |
5669 | ||
5670 | assert(filename); | |
5671 | assert(lvalue); | |
5672 | assert(rvalue); | |
eae51da3 LP |
5673 | |
5674 | r = parse_sec_fix_0(rvalue, &usec); | |
5675 | if (r < 0) { | |
323dda78 | 5676 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue); |
eae51da3 LP |
5677 | return 0; |
5678 | } | |
5679 | ||
5680 | /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old | |
c05f3c8f | 5681 | * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should |
eae51da3 LP |
5682 | * count. */ |
5683 | ||
5684 | if (!u->job_running_timeout_set) | |
5685 | u->job_running_timeout = usec; | |
5686 | ||
5687 | u->job_timeout = usec; | |
5688 | ||
5689 | return 0; | |
5690 | } | |
5691 | ||
5692 | int config_parse_job_running_timeout_sec( | |
5693 | const char* unit, | |
5694 | const char *filename, | |
5695 | unsigned line, | |
5696 | const char *section, | |
5697 | unsigned section_line, | |
5698 | const char *lvalue, | |
5699 | int ltype, | |
5700 | const char *rvalue, | |
5701 | void *data, | |
5702 | void *userdata) { | |
5703 | ||
99534007 | 5704 | Unit *u = ASSERT_PTR(data); |
eae51da3 LP |
5705 | usec_t usec; |
5706 | int r; | |
5707 | ||
5708 | assert(filename); | |
5709 | assert(lvalue); | |
5710 | assert(rvalue); | |
eae51da3 LP |
5711 | |
5712 | r = parse_sec_fix_0(rvalue, &usec); | |
5713 | if (r < 0) { | |
323dda78 | 5714 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue); |
eae51da3 LP |
5715 | return 0; |
5716 | } | |
5717 | ||
5718 | u->job_running_timeout = usec; | |
5719 | u->job_running_timeout_set = true; | |
5720 | ||
5721 | return 0; | |
5722 | } | |
5723 | ||
54fcb619 ZJS |
5724 | int config_parse_emergency_action( |
5725 | const char* unit, | |
5726 | const char *filename, | |
5727 | unsigned line, | |
5728 | const char *section, | |
5729 | unsigned section_line, | |
5730 | const char *lvalue, | |
5731 | int ltype, | |
5732 | const char *rvalue, | |
5733 | void *data, | |
5734 | void *userdata) { | |
5735 | ||
99534007 | 5736 | EmergencyAction *x = ASSERT_PTR(data); |
4870133b | 5737 | RuntimeScope runtime_scope; |
54fcb619 ZJS |
5738 | int r; |
5739 | ||
5740 | assert(filename); | |
5741 | assert(lvalue); | |
5742 | assert(rvalue); | |
54fcb619 | 5743 | |
724f061d | 5744 | /* If we have a unit determine the scope based on it */ |
54fcb619 | 5745 | if (unit) |
4870133b | 5746 | runtime_scope = ((Unit*) ASSERT_PTR(userdata))->manager->runtime_scope; |
54fcb619 | 5747 | else |
4870133b | 5748 | runtime_scope = ltype; /* otherwise, assume the scope is passed in via ltype */ |
54fcb619 | 5749 | |
4870133b | 5750 | r = parse_emergency_action(rvalue, runtime_scope, x); |
54fcb619 ZJS |
5751 | if (r < 0) { |
5752 | if (r == -EOPNOTSUPP) | |
323dda78 | 5753 | log_syntax(unit, LOG_WARNING, filename, line, r, |
54fcb619 | 5754 | "%s= specified as %s mode action, ignoring: %s", |
4870133b | 5755 | lvalue, runtime_scope_to_string(runtime_scope), rvalue); |
54fcb619 | 5756 | else |
323dda78 | 5757 | log_syntax(unit, LOG_WARNING, filename, line, r, |
54fcb619 ZJS |
5758 | "Failed to parse %s=, ignoring: %s", lvalue, rvalue); |
5759 | return 0; | |
5760 | } | |
5761 | ||
5762 | return 0; | |
5763 | } | |
5764 | ||
a9353a5c LP |
5765 | int config_parse_pid_file( |
5766 | const char *unit, | |
5767 | const char *filename, | |
5768 | unsigned line, | |
5769 | const char *section, | |
5770 | unsigned section_line, | |
5771 | const char *lvalue, | |
5772 | int ltype, | |
5773 | const char *rvalue, | |
5774 | void *data, | |
5775 | void *userdata) { | |
5776 | ||
5777 | _cleanup_free_ char *k = NULL, *n = NULL; | |
99534007 | 5778 | const Unit *u = ASSERT_PTR(userdata); |
a9353a5c | 5779 | char **s = data; |
a9353a5c LP |
5780 | int r; |
5781 | ||
5782 | assert(filename); | |
5783 | assert(lvalue); | |
5784 | assert(rvalue); | |
a9353a5c | 5785 | |
b8055c05 YW |
5786 | if (isempty(rvalue)) { |
5787 | /* An empty assignment removes already set value. */ | |
5788 | *s = mfree(*s); | |
5789 | return 0; | |
5790 | } | |
5791 | ||
06536492 | 5792 | r = unit_path_printf(u, rvalue, &k); |
a9353a5c | 5793 | if (r < 0) { |
323dda78 | 5794 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
a9353a5c LP |
5795 | return 0; |
5796 | } | |
5797 | ||
5798 | /* If this is a relative path make it absolute by prefixing the /run */ | |
5799 | n = path_make_absolute(k, u->manager->prefix[EXEC_DIRECTORY_RUNTIME]); | |
5800 | if (!n) | |
5801 | return log_oom(); | |
5802 | ||
5803 | /* Check that the result is a sensible path */ | |
5804 | r = path_simplify_and_warn(n, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); | |
5805 | if (r < 0) | |
5806 | return r; | |
5807 | ||
4a66b5c9 LP |
5808 | r = patch_var_run(unit, filename, line, lvalue, &n); |
5809 | if (r < 0) | |
5810 | return r; | |
a9353a5c | 5811 | |
4a66b5c9 | 5812 | free_and_replace(*s, n); |
a9353a5c LP |
5813 | return 0; |
5814 | } | |
5815 | ||
7af67e9a LP |
5816 | int config_parse_exit_status( |
5817 | const char *unit, | |
5818 | const char *filename, | |
5819 | unsigned line, | |
5820 | const char *section, | |
5821 | unsigned section_line, | |
5822 | const char *lvalue, | |
5823 | int ltype, | |
5824 | const char *rvalue, | |
5825 | void *data, | |
5826 | void *userdata) { | |
5827 | ||
5828 | int *exit_status = data, r; | |
5829 | uint8_t u; | |
5830 | ||
5831 | assert(filename); | |
5832 | assert(lvalue); | |
5833 | assert(rvalue); | |
5834 | assert(exit_status); | |
5835 | ||
5836 | if (isempty(rvalue)) { | |
5837 | *exit_status = -1; | |
5838 | return 0; | |
5839 | } | |
5840 | ||
5841 | r = safe_atou8(rvalue, &u); | |
5842 | if (r < 0) { | |
323dda78 | 5843 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse exit status '%s', ignoring: %m", rvalue); |
7af67e9a LP |
5844 | return 0; |
5845 | } | |
5846 | ||
5847 | *exit_status = u; | |
5848 | return 0; | |
5849 | } | |
5850 | ||
c72703e2 CD |
5851 | int config_parse_disable_controllers( |
5852 | const char *unit, | |
5853 | const char *filename, | |
5854 | unsigned line, | |
5855 | const char *section, | |
5856 | unsigned section_line, | |
5857 | const char *lvalue, | |
5858 | int ltype, | |
5859 | const char *rvalue, | |
5860 | void *data, | |
5861 | void *userdata) { | |
5862 | ||
5863 | int r; | |
5864 | CGroupContext *c = data; | |
5865 | CGroupMask disabled_mask; | |
5866 | ||
5867 | /* 1. If empty, make all controllers eligible for use again. | |
5868 | * 2. If non-empty, merge all listed controllers, space separated. */ | |
5869 | ||
5870 | if (isempty(rvalue)) { | |
5871 | c->disable_controllers = 0; | |
5872 | return 0; | |
5873 | } | |
5874 | ||
5875 | r = cg_mask_from_string(rvalue, &disabled_mask); | |
5876 | if (r < 0 || disabled_mask <= 0) { | |
323dda78 | 5877 | log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid cgroup string: %s, ignoring", rvalue); |
c72703e2 CD |
5878 | return 0; |
5879 | } | |
5880 | ||
5881 | c->disable_controllers |= disabled_mask; | |
5882 | ||
5883 | return 0; | |
5884 | } | |
5885 | ||
fab34748 KL |
5886 | int config_parse_ip_filter_bpf_progs( |
5887 | const char *unit, | |
5888 | const char *filename, | |
5889 | unsigned line, | |
5890 | const char *section, | |
5891 | unsigned section_line, | |
5892 | const char *lvalue, | |
5893 | int ltype, | |
5894 | const char *rvalue, | |
5895 | void *data, | |
5896 | void *userdata) { | |
5897 | ||
5898 | _cleanup_free_ char *resolved = NULL; | |
47538b76 | 5899 | const Unit *u = userdata; |
99534007 | 5900 | char ***paths = ASSERT_PTR(data); |
fab34748 KL |
5901 | int r; |
5902 | ||
5903 | assert(filename); | |
5904 | assert(lvalue); | |
5905 | assert(rvalue); | |
fab34748 KL |
5906 | |
5907 | if (isempty(rvalue)) { | |
5908 | *paths = strv_free(*paths); | |
5909 | return 0; | |
5910 | } | |
5911 | ||
06536492 | 5912 | r = unit_path_printf(u, rvalue, &resolved); |
fab34748 | 5913 | if (r < 0) { |
323dda78 | 5914 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
fab34748 KL |
5915 | return 0; |
5916 | } | |
5917 | ||
5918 | r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); | |
5919 | if (r < 0) | |
5920 | return 0; | |
5921 | ||
5922 | if (strv_contains(*paths, resolved)) | |
5923 | return 0; | |
5924 | ||
5925 | r = strv_extend(paths, resolved); | |
5926 | if (r < 0) | |
5927 | return log_oom(); | |
5928 | ||
5929 | r = bpf_firewall_supported(); | |
5930 | if (r < 0) | |
5931 | return r; | |
5932 | if (r != BPF_FIREWALL_SUPPORTED_WITH_MULTI) { | |
5933 | static bool warned = false; | |
5934 | ||
5935 | log_full(warned ? LOG_DEBUG : LOG_WARNING, | |
5936 | "File %s:%u configures an IP firewall with BPF programs (%s=%s), but the local system does not support BPF/cgroup based firewalling with multiple filters.\n" | |
5937 | "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename, line, lvalue, rvalue); | |
5938 | ||
5939 | warned = true; | |
5940 | } | |
5941 | ||
5942 | return 0; | |
5943 | } | |
5944 | ||
0879da98 JK |
5945 | int config_parse_bpf_foreign_program( |
5946 | const char *unit, | |
5947 | const char *filename, | |
5948 | unsigned line, | |
5949 | const char *section, | |
5950 | unsigned section_line, | |
5951 | const char *lvalue, | |
5952 | int ltype, | |
5953 | const char *rvalue, | |
5954 | void *data, | |
5955 | void *userdata) { | |
5956 | _cleanup_free_ char *resolved = NULL, *word = NULL; | |
5957 | CGroupContext *c = data; | |
99534007 | 5958 | const char *p = ASSERT_PTR(rvalue); |
0879da98 JK |
5959 | Unit *u = userdata; |
5960 | int attach_type, r; | |
5961 | ||
5962 | assert(filename); | |
5963 | assert(lvalue); | |
0879da98 JK |
5964 | |
5965 | if (isempty(rvalue)) { | |
5966 | while (c->bpf_foreign_programs) | |
5967 | cgroup_context_remove_bpf_foreign_program(c, c->bpf_foreign_programs); | |
5968 | ||
5969 | return 0; | |
5970 | } | |
5971 | ||
6a35d52d | 5972 | r = extract_first_word(&p, &word, ":", 0); |
0879da98 JK |
5973 | if (r == -ENOMEM) |
5974 | return log_oom(); | |
6a35d52d | 5975 | if (r < 0) { |
0879da98 JK |
5976 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse foreign BPF program, ignoring: %s", rvalue); |
5977 | return 0; | |
5978 | } | |
6a35d52d YW |
5979 | if (r == 0 || isempty(p)) { |
5980 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid syntax in %s=, ignoring: %s", lvalue, rvalue); | |
5981 | return 0; | |
5982 | } | |
0879da98 JK |
5983 | |
5984 | attach_type = bpf_cgroup_attach_type_from_string(word); | |
5985 | if (attach_type < 0) { | |
5986 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Unknown BPF attach type=%s, ignoring: %s", word, rvalue); | |
5987 | return 0; | |
5988 | } | |
5989 | ||
6a35d52d | 5990 | r = unit_path_printf(u, p, &resolved); |
0879da98 | 5991 | if (r < 0) { |
6a35d52d | 5992 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %s", p, rvalue); |
0879da98 JK |
5993 | return 0; |
5994 | } | |
5995 | ||
5996 | r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); | |
5997 | if (r < 0) | |
5998 | return 0; | |
5999 | ||
c6f2dca6 | 6000 | r = cgroup_context_add_bpf_foreign_program(c, attach_type, resolved); |
0879da98 JK |
6001 | if (r < 0) |
6002 | return log_error_errno(r, "Failed to add foreign BPF program to cgroup context: %m"); | |
6003 | ||
6004 | return 0; | |
6005 | } | |
6006 | ||
8dd210ab JK |
6007 | int config_parse_cgroup_socket_bind( |
6008 | const char *unit, | |
6009 | const char *filename, | |
6010 | unsigned line, | |
6011 | const char *section, | |
6012 | unsigned section_line, | |
6013 | const char *lvalue, | |
6014 | int ltype, | |
6015 | const char *rvalue, | |
6016 | void *data, | |
6017 | void *userdata) { | |
6018 | _cleanup_free_ CGroupSocketBindItem *item = NULL; | |
8dd210ab | 6019 | CGroupSocketBindItem **head = data; |
5587ce7f JK |
6020 | uint16_t nr_ports, port_min; |
6021 | int af, ip_protocol, r; | |
8dd210ab JK |
6022 | |
6023 | if (isempty(rvalue)) { | |
6024 | cgroup_context_remove_socket_bind(head); | |
6025 | return 0; | |
6026 | } | |
6027 | ||
5587ce7f | 6028 | r = parse_socket_bind_item(rvalue, &af, &ip_protocol, &nr_ports, &port_min); |
8dd210ab JK |
6029 | if (r == -ENOMEM) |
6030 | return log_oom(); | |
5587ce7f | 6031 | if (r < 0) { |
cc87b3f6 ZJS |
6032 | log_syntax(unit, LOG_WARNING, filename, line, r, |
6033 | "Unable to parse %s= assignment, ignoring: %s", lvalue, rvalue); | |
6034 | return 0; | |
6035 | } | |
8dd210ab | 6036 | |
8dd210ab JK |
6037 | item = new(CGroupSocketBindItem, 1); |
6038 | if (!item) | |
6039 | return log_oom(); | |
6040 | *item = (CGroupSocketBindItem) { | |
6041 | .address_family = af, | |
5587ce7f | 6042 | .ip_protocol = ip_protocol, |
8dd210ab JK |
6043 | .nr_ports = nr_ports, |
6044 | .port_min = port_min, | |
6045 | }; | |
6046 | ||
6047 | LIST_PREPEND(socket_bind_items, *head, TAKE_PTR(item)); | |
6048 | ||
6049 | return 0; | |
6050 | } | |
6051 | ||
4f0c25c7 MV |
6052 | int config_parse_restrict_network_interfaces( |
6053 | const char *unit, | |
6054 | const char *filename, | |
6055 | unsigned line, | |
6056 | const char *section, | |
6057 | unsigned section_line, | |
6058 | const char *lvalue, | |
6059 | int ltype, | |
6060 | const char *rvalue, | |
6061 | void *data, | |
6062 | void *userdata) { | |
99534007 | 6063 | CGroupContext *c = ASSERT_PTR(data); |
4f0c25c7 MV |
6064 | bool is_allow_rule = true; |
6065 | int r; | |
6066 | ||
6067 | assert(filename); | |
6068 | assert(lvalue); | |
6069 | assert(rvalue); | |
4f0c25c7 MV |
6070 | |
6071 | if (isempty(rvalue)) { | |
6072 | /* Empty assignment resets the list */ | |
1a572fd0 | 6073 | c->restrict_network_interfaces = set_free_free(c->restrict_network_interfaces); |
4f0c25c7 MV |
6074 | return 0; |
6075 | } | |
6076 | ||
6077 | if (rvalue[0] == '~') { | |
6078 | is_allow_rule = false; | |
6079 | rvalue++; | |
6080 | } | |
6081 | ||
6082 | if (set_isempty(c->restrict_network_interfaces)) | |
6083 | /* Only initialize this when creating the set */ | |
6084 | c->restrict_network_interfaces_is_allow_list = is_allow_rule; | |
6085 | ||
6086 | for (const char *p = rvalue;;) { | |
6087 | _cleanup_free_ char *word = NULL; | |
6088 | ||
6089 | r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); | |
6090 | if (r == 0) | |
6091 | break; | |
6092 | if (r == -ENOMEM) | |
6093 | return log_oom(); | |
6094 | if (r < 0) { | |
6095 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
6096 | "Trailing garbage in %s, ignoring: %s", lvalue, rvalue); | |
6097 | break; | |
6098 | } | |
6099 | ||
4e0db87e | 6100 | if (!ifname_valid_full(word, IFNAME_VALID_ALTERNATIVE)) { |
4f0c25c7 MV |
6101 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid interface name, ignoring: %s", word); |
6102 | continue; | |
6103 | } | |
6104 | ||
6105 | if (c->restrict_network_interfaces_is_allow_list != is_allow_rule) | |
6106 | free(set_remove(c->restrict_network_interfaces, word)); | |
6107 | else { | |
6108 | r = set_put_strdup(&c->restrict_network_interfaces, word); | |
6109 | if (r < 0) | |
6110 | return log_oom(); | |
6111 | } | |
6112 | } | |
6113 | ||
6114 | return 0; | |
6115 | } | |
6116 | ||
435e1098 MY |
6117 | int config_parse_mount_node( |
6118 | const char *unit, | |
6119 | const char *filename, | |
6120 | unsigned line, | |
6121 | const char *section, | |
6122 | unsigned section_line, | |
6123 | const char *lvalue, | |
6124 | int ltype, | |
6125 | const char *rvalue, | |
6126 | void *data, | |
6127 | void *userdata) { | |
6128 | ||
6129 | const Unit *u = ASSERT_PTR(userdata); | |
6130 | _cleanup_free_ char *resolved = NULL, *path = NULL; | |
6131 | int r; | |
6132 | ||
6133 | assert(filename); | |
6134 | assert(lvalue); | |
6135 | assert(rvalue); | |
6136 | ||
6137 | r = unit_full_printf(u, rvalue, &resolved); | |
6138 | if (r < 0) { | |
6139 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); | |
6140 | return 0; | |
6141 | } | |
6142 | ||
6143 | path = fstab_node_to_udev_node(resolved); | |
6144 | if (!path) | |
6145 | return log_oom(); | |
6146 | ||
6147 | /* The source passed is not necessarily something we understand, and we pass it as-is to mount/swapon, | |
6148 | * so path_is_valid is not used. But let's check for basic sanety, i.e. if the source is longer than | |
6149 | * PATH_MAX, you're likely doing something wrong. */ | |
6150 | if (strlen(path) >= PATH_MAX) { | |
6151 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Resolved mount path '%s' too long, ignoring.", path); | |
6152 | return 0; | |
6153 | } | |
6154 | ||
6155 | return config_parse_string(unit, filename, line, section, section_line, lvalue, ltype, path, data, userdata); | |
6156 | } | |
6157 | ||
57ffa99d | 6158 | static int merge_by_names(Unit *u, Set *names, const char *id) { |
23a177ef LP |
6159 | char *k; |
6160 | int r; | |
6161 | ||
6162 | assert(u); | |
23a177ef | 6163 | |
e8630e69 | 6164 | /* Let's try to add in all names that are aliases of this unit */ |
23a177ef | 6165 | while ((k = set_steal_first(names))) { |
e8630e69 | 6166 | _cleanup_free_ _unused_ char *free_k = k; |
23a177ef | 6167 | |
e8630e69 | 6168 | /* First try to merge in the other name into our unit */ |
57ffa99d | 6169 | r = unit_merge_by_name(u, k); |
9946996c | 6170 | if (r < 0) { |
23a177ef LP |
6171 | Unit *other; |
6172 | ||
e8630e69 ZJS |
6173 | /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way |
6174 | * round. */ | |
036643a2 | 6175 | |
57ffa99d | 6176 | other = manager_get_unit(u->manager, k); |
e8630e69 ZJS |
6177 | if (!other) |
6178 | return r; /* return previous failure */ | |
036643a2 | 6179 | |
57ffa99d | 6180 | r = unit_merge(other, u); |
e8630e69 | 6181 | if (r < 0) |
a837f088 | 6182 | return r; |
fe51822e | 6183 | |
57ffa99d | 6184 | return merge_by_names(other, names, NULL); |
036643a2 | 6185 | } |
034c6ed7 | 6186 | |
e8630e69 | 6187 | if (streq_ptr(id, k)) |
57ffa99d | 6188 | unit_choose_id(u, id); |
1b64d026 LP |
6189 | } |
6190 | ||
e48614c4 | 6191 | return 0; |
0301abf4 LP |
6192 | } |
6193 | ||
e537352b | 6194 | int unit_load_fragment(Unit *u) { |
e8630e69 ZJS |
6195 | const char *fragment; |
6196 | _cleanup_set_free_free_ Set *names = NULL; | |
23a177ef | 6197 | int r; |
0301abf4 LP |
6198 | |
6199 | assert(u); | |
ac155bb8 MS |
6200 | assert(u->load_state == UNIT_STUB); |
6201 | assert(u->id); | |
23a177ef | 6202 | |
3f5e8115 | 6203 | if (u->transient) { |
23e9a7dd | 6204 | u->access_selinux_context = mfree(u->access_selinux_context); |
3f5e8115 LP |
6205 | u->load_state = UNIT_LOADED; |
6206 | return 0; | |
6207 | } | |
6208 | ||
91e0ee5f ZJS |
6209 | /* Possibly rebuild the fragment map to catch new units */ |
6210 | r = unit_file_build_name_map(&u->manager->lookup_paths, | |
c2911d48 | 6211 | &u->manager->unit_cache_timestamp_hash, |
91e0ee5f ZJS |
6212 | &u->manager->unit_id_map, |
6213 | &u->manager->unit_name_map, | |
6214 | &u->manager->unit_path_cache); | |
9946996c | 6215 | if (r < 0) |
14140908 | 6216 | return log_error_errno(r, "Failed to rebuild name map: %m"); |
91e0ee5f | 6217 | |
e8630e69 ZJS |
6218 | r = unit_file_find_fragment(u->manager->unit_id_map, |
6219 | u->manager->unit_name_map, | |
6220 | u->id, | |
6221 | &fragment, | |
6222 | &names); | |
6223 | if (r < 0 && r != -ENOENT) | |
294d81f1 LP |
6224 | return r; |
6225 | ||
e8630e69 ZJS |
6226 | if (fragment) { |
6227 | /* Open the file, check if this is a mask, otherwise read. */ | |
6228 | _cleanup_fclose_ FILE *f = NULL; | |
c9e06956 | 6229 | struct stat st; |
0301abf4 | 6230 | |
e8630e69 ZJS |
6231 | /* Try to open the file name. A symlink is OK, for example for linked files or masks. We |
6232 | * expect that all symlinks within the lookup paths have been already resolved, but we don't | |
6233 | * verify this here. */ | |
6234 | f = fopen(fragment, "re"); | |
6235 | if (!f) | |
6236 | return log_unit_notice_errno(u, errno, "Failed to open %s: %m", fragment); | |
6ccb1b44 | 6237 | |
e8630e69 ZJS |
6238 | if (fstat(fileno(f), &st) < 0) |
6239 | return -errno; | |
294d81f1 | 6240 | |
e8630e69 | 6241 | r = free_and_strdup(&u->fragment_path, fragment); |
7410616c LP |
6242 | if (r < 0) |
6243 | return r; | |
294d81f1 | 6244 | |
e8630e69 | 6245 | if (null_or_empty(&st)) { |
88414eed LP |
6246 | /* Unit file is masked */ |
6247 | ||
6248 | u->load_state = u->perpetual ? UNIT_LOADED : UNIT_MASKED; /* don't allow perpetual units to ever be masked */ | |
e8630e69 | 6249 | u->fragment_mtime = 0; |
23e9a7dd | 6250 | u->access_selinux_context = mfree(u->access_selinux_context); |
e8630e69 | 6251 | } else { |
23e9a7dd LP |
6252 | #if HAVE_SELINUX |
6253 | if (mac_selinux_use()) { | |
6254 | _cleanup_freecon_ char *selcon = NULL; | |
6255 | ||
6256 | /* Cache the SELinux context of the unit file here. We'll make use of when checking access permissions to loaded units */ | |
6257 | r = fgetfilecon_raw(fileno(f), &selcon); | |
6258 | if (r < 0) | |
6259 | log_unit_warning_errno(u, r, "Failed to read SELinux context of '%s', ignoring: %m", fragment); | |
6260 | ||
6261 | r = free_and_strdup(&u->access_selinux_context, selcon); | |
6262 | if (r < 0) | |
6263 | return r; | |
6264 | } else | |
6265 | #endif | |
6266 | u->access_selinux_context = mfree(u->access_selinux_context); | |
6267 | ||
e8630e69 ZJS |
6268 | u->load_state = UNIT_LOADED; |
6269 | u->fragment_mtime = timespec_load(&st.st_mtim); | |
6270 | ||
6271 | /* Now, parse the file contents */ | |
6272 | r = config_parse(u->id, fragment, f, | |
6273 | UNIT_VTABLE(u)->sections, | |
6274 | config_item_perf_lookup, load_fragment_gperf_lookup, | |
7ade8982 | 6275 | 0, |
4f9ff96a LP |
6276 | u, |
6277 | NULL); | |
bb28e684 | 6278 | if (r == -ENOEXEC) |
e8630e69 ZJS |
6279 | log_unit_notice_errno(u, r, "Unit configuration has fatal error, unit will not be started."); |
6280 | if (r < 0) | |
6281 | return r; | |
bb28e684 | 6282 | } |
e8630e69 | 6283 | } |
890f434c | 6284 | |
3aa57658 ZJS |
6285 | /* Call merge_by_names with the name derived from the fragment path as the preferred name. |
6286 | * | |
6287 | * We do the merge dance here because for some unit types, the unit might have aliases which are not | |
e8630e69 ZJS |
6288 | * declared in the file system. In particular, this is true (and frequent) for device and swap units. |
6289 | */ | |
e8630e69 | 6290 | const char *id = u->id; |
b58feca6 | 6291 | _cleanup_free_ char *filename = NULL, *free_id = NULL; |
294d81f1 | 6292 | |
e8630e69 | 6293 | if (fragment) { |
b58feca6 JR |
6294 | r = path_extract_filename(fragment, &filename); |
6295 | if (r < 0) | |
6296 | return log_debug_errno(r, "Failed to extract filename from fragment '%s': %m", fragment); | |
6297 | id = filename; | |
6298 | ||
e8630e69 ZJS |
6299 | if (unit_name_is_valid(id, UNIT_NAME_TEMPLATE)) { |
6300 | assert(u->instance); /* If we're not trying to use a template for non-instanced unit, | |
6301 | * this must be set. */ | |
890f434c | 6302 | |
e8630e69 ZJS |
6303 | r = unit_name_replace_instance(id, u->instance, &free_id); |
6304 | if (r < 0) | |
6305 | return log_debug_errno(r, "Failed to build id (%s + %s): %m", id, u->instance); | |
6306 | id = free_id; | |
abc08d4d | 6307 | } |
071830ff LP |
6308 | } |
6309 | ||
57ffa99d | 6310 | return merge_by_names(u, names, id); |
3efd4195 | 6311 | } |
e537352b LP |
6312 | |
6313 | void unit_dump_config_items(FILE *f) { | |
f975e971 LP |
6314 | static const struct { |
6315 | const ConfigParserCallback callback; | |
6316 | const char *rvalue; | |
6317 | } table[] = { | |
17df7223 | 6318 | { config_parse_warn_compat, "NOTSUPPORTED" }, |
f975e971 LP |
6319 | { config_parse_int, "INTEGER" }, |
6320 | { config_parse_unsigned, "UNSIGNED" }, | |
5556b5fe | 6321 | { config_parse_iec_size, "SIZE" }, |
59f448cf | 6322 | { config_parse_iec_uint64, "SIZE" }, |
50299121 | 6323 | { config_parse_si_uint64, "SIZE" }, |
f975e971 LP |
6324 | { config_parse_bool, "BOOLEAN" }, |
6325 | { config_parse_string, "STRING" }, | |
6326 | { config_parse_path, "PATH" }, | |
6327 | { config_parse_unit_path_printf, "PATH" }, | |
8c35c10d | 6328 | { config_parse_colon_separated_paths, "PATH" }, |
f975e971 LP |
6329 | { config_parse_strv, "STRING [...]" }, |
6330 | { config_parse_exec_nice, "NICE" }, | |
6331 | { config_parse_exec_oom_score_adjust, "OOMSCOREADJUST" }, | |
6332 | { config_parse_exec_io_class, "IOCLASS" }, | |
6333 | { config_parse_exec_io_priority, "IOPRIORITY" }, | |
6334 | { config_parse_exec_cpu_sched_policy, "CPUSCHEDPOLICY" }, | |
6335 | { config_parse_exec_cpu_sched_prio, "CPUSCHEDPRIO" }, | |
6336 | { config_parse_exec_cpu_affinity, "CPUAFFINITY" }, | |
6337 | { config_parse_mode, "MODE" }, | |
6338 | { config_parse_unit_env_file, "FILE" }, | |
52c239d7 LB |
6339 | { config_parse_exec_output, "OUTPUT" }, |
6340 | { config_parse_exec_input, "INPUT" }, | |
ca37242e LP |
6341 | { config_parse_log_facility, "FACILITY" }, |
6342 | { config_parse_log_level, "LEVEL" }, | |
f975e971 | 6343 | { config_parse_exec_secure_bits, "SECUREBITS" }, |
a103496c | 6344 | { config_parse_capability_set, "BOUNDINGSET" }, |
4f424df7 | 6345 | { config_parse_rlimit, "LIMIT" }, |
f975e971 | 6346 | { config_parse_unit_deps, "UNIT [...]" }, |
f975e971 LP |
6347 | { config_parse_exec, "PATH [ARGUMENT [...]]" }, |
6348 | { config_parse_service_type, "SERVICETYPE" }, | |
596e4470 | 6349 | { config_parse_service_exit_type, "SERVICEEXITTYPE" }, |
f975e971 | 6350 | { config_parse_service_restart, "SERVICERESTART" }, |
e568fea9 | 6351 | { config_parse_service_restart_mode, "SERVICERESTARTMODE" }, |
bf760801 | 6352 | { config_parse_service_timeout_failure_mode, "TIMEOUTMODE" }, |
f975e971 | 6353 | { config_parse_kill_mode, "KILLMODE" }, |
f757855e | 6354 | { config_parse_signal, "SIGNAL" }, |
f975e971 LP |
6355 | { config_parse_socket_listen, "SOCKET [...]" }, |
6356 | { config_parse_socket_bind, "SOCKETBIND" }, | |
6357 | { config_parse_socket_bindtodevice, "NETWORKINTERFACE" }, | |
7f602784 | 6358 | { config_parse_sec, "SECONDS" }, |
d88a251b | 6359 | { config_parse_nsec, "NANOSECONDS" }, |
94828d2d | 6360 | { config_parse_namespace_path_strv, "PATH [...]" }, |
d2d6c096 | 6361 | { config_parse_bind_paths, "PATH[:PATH[:OPTIONS]] [...]" }, |
9e615fa3 | 6362 | { config_parse_unit_mounts_for, "PATH [...]" }, |
874cdcbc | 6363 | { config_parse_exec_mount_propagation_flag, |
f0a96d19 | 6364 | "MOUNTFLAG" }, |
f975e971 | 6365 | { config_parse_unit_string_printf, "STRING" }, |
3ecaa09b | 6366 | { config_parse_trigger_unit, "UNIT" }, |
f975e971 | 6367 | { config_parse_timer, "TIMER" }, |
f975e971 | 6368 | { config_parse_path_spec, "PATH" }, |
f975e971 LP |
6369 | { config_parse_notify_access, "ACCESS" }, |
6370 | { config_parse_ip_tos, "TOS" }, | |
6371 | { config_parse_unit_condition_path, "CONDITION" }, | |
6372 | { config_parse_unit_condition_string, "CONDITION" }, | |
a016b922 | 6373 | { config_parse_unit_slice, "SLICE" }, |
7f0386f6 LP |
6374 | { config_parse_documentation, "URL" }, |
6375 | { config_parse_service_timeout, "SECONDS" }, | |
87a47f99 | 6376 | { config_parse_emergency_action, "ACTION" }, |
7f0386f6 LP |
6377 | { config_parse_set_status, "STATUS" }, |
6378 | { config_parse_service_sockets, "SOCKETS" }, | |
7f0386f6 | 6379 | { config_parse_environ, "ENVIRON" }, |
349cc4a5 | 6380 | #if HAVE_SECCOMP |
17df7223 | 6381 | { config_parse_syscall_filter, "SYSCALLS" }, |
6a6751fe | 6382 | { config_parse_syscall_archs, "ARCHS" }, |
17df7223 | 6383 | { config_parse_syscall_errno, "ERRNO" }, |
9df2cdd8 | 6384 | { config_parse_syscall_log, "SYSCALLS" }, |
4298d0b5 | 6385 | { config_parse_address_families, "FAMILIES" }, |
add00535 | 6386 | { config_parse_restrict_namespaces, "NAMESPACES" }, |
c0467cf3 | 6387 | #endif |
e59ccd03 | 6388 | { config_parse_restrict_filesystems, "FILESYSTEMS" }, |
7f0386f6 | 6389 | { config_parse_cpu_shares, "SHARES" }, |
984faf29 | 6390 | { config_parse_cg_weight, "WEIGHT" }, |
c8340822 | 6391 | { config_parse_cg_cpu_weight, "CPUWEIGHT" }, |
7f0386f6 LP |
6392 | { config_parse_memory_limit, "LIMIT" }, |
6393 | { config_parse_device_allow, "DEVICE" }, | |
6394 | { config_parse_device_policy, "POLICY" }, | |
13c31542 | 6395 | { config_parse_io_limit, "LIMIT" }, |
13c31542 | 6396 | { config_parse_io_device_weight, "DEVICEWEIGHT" }, |
6ae4283c | 6397 | { config_parse_io_device_latency, "DEVICELATENCY" }, |
7f0386f6 LP |
6398 | { config_parse_blockio_bandwidth, "BANDWIDTH" }, |
6399 | { config_parse_blockio_weight, "WEIGHT" }, | |
6400 | { config_parse_blockio_device_weight, "DEVICEWEIGHT" }, | |
6401 | { config_parse_long, "LONG" }, | |
6402 | { config_parse_socket_service, "SERVICE" }, | |
349cc4a5 | 6403 | #if HAVE_SELINUX |
6a6751fe LP |
6404 | { config_parse_exec_selinux_context, "LABEL" }, |
6405 | #endif | |
6406 | { config_parse_job_mode, "MODE" }, | |
6407 | { config_parse_job_mode_isolate, "BOOLEAN" }, | |
4298d0b5 | 6408 | { config_parse_personality, "PERSONALITY" }, |
523ea123 | 6409 | { config_parse_log_filter_patterns, "REGEX" }, |
435e1098 | 6410 | { config_parse_mount_node, "NODE" }, |
f975e971 LP |
6411 | }; |
6412 | ||
6413 | const char *prev = NULL; | |
f975e971 LP |
6414 | |
6415 | assert(f); | |
e537352b | 6416 | |
f975e971 LP |
6417 | NULSTR_FOREACH(i, load_fragment_gperf_nulstr) { |
6418 | const char *rvalue = "OTHER", *lvalue; | |
313b7856 | 6419 | const ConfigPerfItem *p; |
f975e971 | 6420 | const char *dot; |
f975e971 LP |
6421 | |
6422 | assert_se(p = load_fragment_gperf_lookup(i, strlen(i))); | |
6423 | ||
313b7856 LP |
6424 | /* Hide legacy settings */ |
6425 | if (p->parse == config_parse_warn_compat && | |
6426 | p->ltype == DISABLED_LEGACY) | |
6427 | continue; | |
6428 | ||
601844b7 | 6429 | for (size_t j = 0; j < ELEMENTSOF(table); j++) |
313b7856 LP |
6430 | if (p->parse == table[j].callback) { |
6431 | rvalue = table[j].rvalue; | |
6432 | break; | |
6433 | } | |
6434 | ||
f975e971 LP |
6435 | dot = strchr(i, '.'); |
6436 | lvalue = dot ? dot + 1 : i; | |
f975e971 | 6437 | |
601844b7 YW |
6438 | if (dot) { |
6439 | size_t prefix_len = dot - i; | |
6440 | ||
641906e9 | 6441 | if (!prev || !strneq(prev, i, prefix_len+1)) { |
f975e971 LP |
6442 | if (prev) |
6443 | fputc('\n', f); | |
6444 | ||
6445 | fprintf(f, "[%.*s]\n", (int) prefix_len, i); | |
6446 | } | |
601844b7 | 6447 | } |
f975e971 | 6448 | |
f975e971 LP |
6449 | fprintf(f, "%s=%s\n", lvalue, rvalue); |
6450 | prev = i; | |
6451 | } | |
e537352b | 6452 | } |
a07a7324 FS |
6453 | |
6454 | int config_parse_cpu_affinity2( | |
6455 | const char *unit, | |
6456 | const char *filename, | |
6457 | unsigned line, | |
6458 | const char *section, | |
6459 | unsigned section_line, | |
6460 | const char *lvalue, | |
6461 | int ltype, | |
6462 | const char *rvalue, | |
6463 | void *data, | |
6464 | void *userdata) { | |
6465 | ||
99534007 | 6466 | CPUSet *affinity = ASSERT_PTR(data); |
a07a7324 FS |
6467 | |
6468 | (void) parse_cpu_set_extend(rvalue, affinity, true, unit, filename, line, lvalue); | |
6469 | ||
6470 | return 0; | |
6471 | } | |
6472 | ||
6473 | int config_parse_show_status( | |
6474 | const char* unit, | |
6475 | const char *filename, | |
6476 | unsigned line, | |
6477 | const char *section, | |
6478 | unsigned section_line, | |
6479 | const char *lvalue, | |
6480 | int ltype, | |
6481 | const char *rvalue, | |
6482 | void *data, | |
6483 | void *userdata) { | |
6484 | ||
6485 | int k; | |
99534007 | 6486 | ShowStatus *b = ASSERT_PTR(data); |
a07a7324 FS |
6487 | |
6488 | assert(filename); | |
6489 | assert(lvalue); | |
6490 | assert(rvalue); | |
a07a7324 FS |
6491 | |
6492 | k = parse_show_status(rvalue, b); | |
323dda78 YW |
6493 | if (k < 0) |
6494 | log_syntax(unit, LOG_WARNING, filename, line, k, "Failed to parse show status setting, ignoring: %s", rvalue); | |
a07a7324 FS |
6495 | |
6496 | return 0; | |
6497 | } | |
6498 | ||
6499 | int config_parse_output_restricted( | |
6500 | const char* unit, | |
6501 | const char *filename, | |
6502 | unsigned line, | |
6503 | const char *section, | |
6504 | unsigned section_line, | |
6505 | const char *lvalue, | |
6506 | int ltype, | |
6507 | const char *rvalue, | |
6508 | void *data, | |
6509 | void *userdata) { | |
6510 | ||
99534007 | 6511 | ExecOutput t, *eo = ASSERT_PTR(data); |
f3dc6af2 | 6512 | bool obsolete = false; |
a07a7324 FS |
6513 | |
6514 | assert(filename); | |
6515 | assert(lvalue); | |
6516 | assert(rvalue); | |
a07a7324 | 6517 | |
f3dc6af2 LP |
6518 | if (streq(rvalue, "syslog")) { |
6519 | t = EXEC_OUTPUT_JOURNAL; | |
6520 | obsolete = true; | |
6521 | } else if (streq(rvalue, "syslog+console")) { | |
6522 | t = EXEC_OUTPUT_JOURNAL_AND_CONSOLE; | |
6523 | obsolete = true; | |
6524 | } else { | |
6525 | t = exec_output_from_string(rvalue); | |
6526 | if (t < 0) { | |
b98680b2 | 6527 | log_syntax(unit, LOG_WARNING, filename, line, t, "Failed to parse output type, ignoring: %s", rvalue); |
f3dc6af2 LP |
6528 | return 0; |
6529 | } | |
a07a7324 | 6530 | |
8d7dab1f LW |
6531 | if (IN_SET(t, EXEC_OUTPUT_SOCKET, EXEC_OUTPUT_NAMED_FD, EXEC_OUTPUT_FILE, EXEC_OUTPUT_FILE_APPEND, EXEC_OUTPUT_FILE_TRUNCATE)) { |
6532 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Standard output types socket, fd:, file:, append:, truncate: are not supported as defaults, ignoring: %s", rvalue); | |
f3dc6af2 LP |
6533 | return 0; |
6534 | } | |
a07a7324 FS |
6535 | } |
6536 | ||
f3dc6af2 LP |
6537 | if (obsolete) |
6538 | log_syntax(unit, LOG_NOTICE, filename, line, 0, | |
6539 | "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.", | |
6540 | rvalue, exec_output_to_string(t)); | |
6541 | ||
a07a7324 FS |
6542 | *eo = t; |
6543 | return 0; | |
6544 | } | |
6545 | ||
6546 | int config_parse_crash_chvt( | |
6547 | const char* unit, | |
6548 | const char *filename, | |
6549 | unsigned line, | |
6550 | const char *section, | |
6551 | unsigned section_line, | |
6552 | const char *lvalue, | |
6553 | int ltype, | |
6554 | const char *rvalue, | |
6555 | void *data, | |
6556 | void *userdata) { | |
6557 | ||
6558 | int r; | |
6559 | ||
6560 | assert(filename); | |
6561 | assert(lvalue); | |
6562 | assert(rvalue); | |
6563 | assert(data); | |
6564 | ||
6565 | r = parse_crash_chvt(rvalue, data); | |
323dda78 YW |
6566 | if (r < 0) |
6567 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue); | |
a07a7324 FS |
6568 | |
6569 | return 0; | |
6570 | } | |
eb34a981 LP |
6571 | |
6572 | int config_parse_swap_priority( | |
6573 | const char *unit, | |
6574 | const char *filename, | |
6575 | unsigned line, | |
6576 | const char *section, | |
6577 | unsigned section_line, | |
6578 | const char *lvalue, | |
6579 | int ltype, | |
6580 | const char *rvalue, | |
6581 | void *data, | |
6582 | void *userdata) { | |
6583 | ||
99534007 | 6584 | Swap *s = ASSERT_PTR(userdata); |
eb34a981 LP |
6585 | int r, priority; |
6586 | ||
eb34a981 LP |
6587 | assert(filename); |
6588 | assert(lvalue); | |
6589 | assert(rvalue); | |
6590 | assert(data); | |
6591 | ||
6592 | if (isempty(rvalue)) { | |
6593 | s->parameters_fragment.priority = -1; | |
6594 | s->parameters_fragment.priority_set = false; | |
6595 | return 0; | |
6596 | } | |
6597 | ||
6598 | r = safe_atoi(rvalue, &priority); | |
6599 | if (r < 0) { | |
323dda78 | 6600 | log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid swap priority '%s', ignoring.", rvalue); |
eb34a981 LP |
6601 | return 0; |
6602 | } | |
6603 | ||
6604 | if (priority < -1) { | |
323dda78 | 6605 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Sorry, swap priorities smaller than -1 may only be assigned by the kernel itself, ignoring: %s", rvalue); |
eb34a981 LP |
6606 | return 0; |
6607 | } | |
6608 | ||
6609 | if (priority > 32767) { | |
323dda78 | 6610 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Swap priority out of range, ignoring: %s", rvalue); |
eb34a981 LP |
6611 | return 0; |
6612 | } | |
6613 | ||
6614 | s->parameters_fragment.priority = priority; | |
6615 | s->parameters_fragment.priority_set = true; | |
6616 | return 0; | |
6617 | } | |
8a85c5b6 FB |
6618 | |
6619 | int config_parse_watchdog_sec( | |
6620 | const char *unit, | |
6621 | const char *filename, | |
6622 | unsigned line, | |
6623 | const char *section, | |
6624 | unsigned section_line, | |
6625 | const char *lvalue, | |
6626 | int ltype, | |
6627 | const char *rvalue, | |
6628 | void *data, | |
6629 | void *userdata) { | |
6630 | ||
c91c95e6 LP |
6631 | usec_t *usec = data; |
6632 | ||
8a85c5b6 FB |
6633 | assert(filename); |
6634 | assert(lvalue); | |
6635 | assert(rvalue); | |
6636 | ||
6637 | /* This is called for {Runtime,Reboot,KExec}WatchdogSec= where "default" maps to | |
6638 | * USEC_INFINITY internally. */ | |
6639 | ||
c91c95e6 | 6640 | if (streq(rvalue, "default")) |
8a85c5b6 | 6641 | *usec = USEC_INFINITY; |
c91c95e6 LP |
6642 | else if (streq(rvalue, "off")) |
6643 | *usec = 0; | |
6644 | else | |
6645 | return config_parse_sec(unit, filename, line, section, section_line, lvalue, ltype, rvalue, data, userdata); | |
8a85c5b6 | 6646 | |
c91c95e6 | 6647 | return 0; |
8a85c5b6 | 6648 | } |
51462135 DDM |
6649 | |
6650 | int config_parse_tty_size( | |
6651 | const char *unit, | |
6652 | const char *filename, | |
6653 | unsigned line, | |
6654 | const char *section, | |
6655 | unsigned section_line, | |
6656 | const char *lvalue, | |
6657 | int ltype, | |
6658 | const char *rvalue, | |
6659 | void *data, | |
6660 | void *userdata) { | |
6661 | ||
6662 | unsigned *sz = data; | |
6663 | ||
6664 | assert(filename); | |
6665 | assert(lvalue); | |
6666 | assert(rvalue); | |
6667 | ||
6668 | if (isempty(rvalue)) { | |
6669 | *sz = UINT_MAX; | |
6670 | return 0; | |
6671 | } | |
6672 | ||
6673 | return config_parse_unsigned(unit, filename, line, section, section_line, lvalue, ltype, rvalue, data, userdata); | |
6674 | } | |
523ea123 QD |
6675 | |
6676 | int config_parse_log_filter_patterns( | |
6677 | const char *unit, | |
6678 | const char *filename, | |
6679 | unsigned line, | |
6680 | const char *section, | |
6681 | unsigned section_line, | |
6682 | const char *lvalue, | |
6683 | int ltype, | |
6684 | const char *rvalue, | |
6685 | void *data, | |
6686 | void *userdata) { | |
6687 | ||
6688 | ExecContext *c = ASSERT_PTR(data); | |
523ea123 QD |
6689 | const char *pattern = ASSERT_PTR(rvalue); |
6690 | bool is_allowlist = true; | |
6691 | int r; | |
6692 | ||
6693 | assert(filename); | |
6694 | assert(lvalue); | |
6695 | ||
6696 | if (isempty(pattern)) { | |
6697 | /* Empty assignment resets the lists. */ | |
1a572fd0 DT |
6698 | c->log_filter_allowed_patterns = set_free_free(c->log_filter_allowed_patterns); |
6699 | c->log_filter_denied_patterns = set_free_free(c->log_filter_denied_patterns); | |
523ea123 QD |
6700 | return 0; |
6701 | } | |
6702 | ||
6703 | if (pattern[0] == '~') { | |
6704 | is_allowlist = false; | |
6705 | pattern++; | |
6706 | if (isempty(pattern)) | |
6707 | /* LogFilterPatterns=~ is not considered a valid pattern. */ | |
6708 | return log_syntax(unit, LOG_WARNING, filename, line, 0, | |
6709 | "Regex pattern invalid, ignoring: %s=%s", lvalue, rvalue); | |
6710 | } | |
6711 | ||
48d85160 | 6712 | if (pattern_compile_and_log(pattern, 0, NULL) < 0) |
523ea123 QD |
6713 | return 0; |
6714 | ||
6715 | r = set_put_strdup(is_allowlist ? &c->log_filter_allowed_patterns : &c->log_filter_denied_patterns, | |
6716 | pattern); | |
6717 | if (r < 0) { | |
6718 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
6719 | "Failed to store log filtering pattern, ignoring: %s=%s", lvalue, rvalue); | |
6720 | return 0; | |
6721 | } | |
6722 | ||
6723 | return 0; | |
6724 | } | |
cd48e23f RP |
6725 | |
6726 | int config_parse_open_file( | |
6727 | const char *unit, | |
6728 | const char *filename, | |
6729 | unsigned line, | |
6730 | const char *section, | |
6731 | unsigned section_line, | |
6732 | const char *lvalue, | |
6733 | int ltype, | |
6734 | const char *rvalue, | |
6735 | void *data, | |
6736 | void *userdata) { | |
6737 | ||
6738 | _cleanup_(open_file_freep) OpenFile *of = NULL; | |
6739 | OpenFile **head = ASSERT_PTR(data); | |
6740 | int r; | |
6741 | ||
6742 | assert(filename); | |
6743 | assert(lvalue); | |
6744 | assert(rvalue); | |
6745 | ||
6746 | if (isempty(rvalue)) { | |
6747 | open_file_free_many(head); | |
6748 | return 0; | |
6749 | } | |
6750 | ||
6751 | r = open_file_parse(rvalue, &of); | |
6752 | if (r < 0) { | |
6753 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse OpenFile= setting, ignoring: %s", rvalue); | |
6754 | return 0; | |
6755 | } | |
6756 | ||
6757 | LIST_APPEND(open_files, *head, TAKE_PTR(of)); | |
6758 | ||
6759 | return 0; | |
6760 | } | |
dc7d69b3 TM |
6761 | |
6762 | int config_parse_cgroup_nft_set( | |
6763 | const char *unit, | |
6764 | const char *filename, | |
6765 | unsigned line, | |
6766 | const char *section, | |
6767 | unsigned section_line, | |
6768 | const char *lvalue, | |
6769 | int ltype, | |
6770 | const char *rvalue, | |
6771 | void *data, | |
6772 | void *userdata) { | |
6773 | ||
6774 | CGroupContext *c = ASSERT_PTR(data); | |
6775 | Unit *u = ASSERT_PTR(userdata); | |
6776 | ||
6777 | return config_parse_nft_set(unit, filename, line, section, section_line, lvalue, ltype, rvalue, &c->nft_set_context, u); | |
6778 | } |