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