]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
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 | 9 | #include <linux/oom.h> |
349cc4a5 | 10 | #if HAVE_SECCOMP |
618234a5 LP |
11 | #include <seccomp.h> |
12 | #endif | |
5f5d8eab LP |
13 | #include <sched.h> |
14 | #include <string.h> | |
3d57c6ab | 15 | #include <sys/resource.h> |
5f5d8eab | 16 | #include <sys/stat.h> |
3efd4195 | 17 | |
5f5d8eab | 18 | #include "af-list.h" |
cf0fbc49 | 19 | #include "alloc-util.h" |
57b7a260 | 20 | #include "all-units.h" |
5f5d8eab LP |
21 | #include "bus-error.h" |
22 | #include "bus-internal.h" | |
23 | #include "bus-util.h" | |
24 | #include "cap-list.h" | |
a103496c | 25 | #include "capability-util.h" |
5f5d8eab | 26 | #include "cgroup.h" |
3efd4195 | 27 | #include "conf-parser.h" |
618234a5 | 28 | #include "cpu-set-util.h" |
5f5d8eab LP |
29 | #include "env-util.h" |
30 | #include "errno-list.h" | |
4f5dd394 | 31 | #include "escape.h" |
3ffd4af2 | 32 | #include "fd-util.h" |
f4f15635 | 33 | #include "fs-util.h" |
08f3be7a | 34 | #include "hexdecoct.h" |
d3070fbd | 35 | #include "io-util.h" |
9eba9da4 | 36 | #include "ioprio.h" |
da96ad5a | 37 | #include "ip-protocol-list.h" |
d3070fbd | 38 | #include "journal-util.h" |
eefc66aa | 39 | #include "limits-util.h" |
3ffd4af2 | 40 | #include "load-fragment.h" |
5f5d8eab | 41 | #include "log.h" |
94f04347 | 42 | #include "missing.h" |
049af8ad | 43 | #include "mountpoint-util.h" |
d8b4d14d | 44 | #include "nulstr-util.h" |
6bedfcbb | 45 | #include "parse-util.h" |
9eb977db | 46 | #include "path-util.h" |
7b3e062c | 47 | #include "process-util.h" |
349cc4a5 | 48 | #if HAVE_SECCOMP |
57183d11 LP |
49 | #include "seccomp-util.h" |
50 | #endif | |
07d46372 | 51 | #include "securebits-util.h" |
5f5d8eab | 52 | #include "signal-util.h" |
8fcde012 | 53 | #include "stat-util.h" |
07630cea | 54 | #include "string-util.h" |
5f5d8eab LP |
55 | #include "strv.h" |
56 | #include "unit-name.h" | |
57 | #include "unit-printf.h" | |
66dccd8d | 58 | #include "user-util.h" |
10f28641 | 59 | #include "time-util.h" |
49cf4170 | 60 | #include "web-util.h" |
57183d11 | 61 | |
d2b42d63 | 62 | static int parse_socket_protocol(const char *s) { |
53577580 YW |
63 | int r; |
64 | ||
d2b42d63 | 65 | r = parse_ip_protocol(s); |
53577580 | 66 | if (r < 0) |
acf4d158 | 67 | return r; |
53577580 YW |
68 | if (!IN_SET(r, IPPROTO_UDPLITE, IPPROTO_SCTP)) |
69 | return -EPROTONOSUPPORT; | |
70 | ||
71 | return r; | |
72 | } | |
73 | ||
d2b42d63 | 74 | DEFINE_CONFIG_PARSE(config_parse_socket_protocol, parse_socket_protocol, "Failed to parse socket protocol"); |
53577580 | 75 | DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits, secure_bits_from_string, "Failed to parse secure bits"); |
5afe510c | 76 | DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode, collect_mode, CollectMode, "Failed to parse garbage collection mode"); |
53577580 | 77 | DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy, cgroup_device_policy, CGroupDevicePolicy, "Failed to parse device policy"); |
53577580 YW |
78 | DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode, exec_keyring_mode, ExecKeyringMode, "Failed to parse keyring mode"); |
79 | DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode, exec_utmp_mode, ExecUtmpMode, "Failed to parse utmp mode"); | |
80 | DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode, job_mode, JobMode, "Failed to parse job mode"); | |
81 | DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode, kill_mode, KillMode, "Failed to parse kill mode"); | |
82 | DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access, notify_access, NotifyAccess, "Failed to parse notify access specifier"); | |
1e8c7bd5 YW |
83 | DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home, protect_home, ProtectHome, "Failed to parse protect home value"); |
84 | DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system, protect_system, ProtectSystem, "Failed to parse protect system value"); | |
53577580 YW |
85 | DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode, exec_preserve_mode, ExecPreserveMode, "Failed to parse runtime directory preserve mode"); |
86 | DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type, service_type, ServiceType, "Failed to parse service type"); | |
87 | DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart, service_restart, ServiceRestart, "Failed to parse service restart specifier"); | |
88 | DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind, socket_address_bind_ipv6_only_or_bool, SocketAddressBindIPv6Only, "Failed to parse bind IPv6 only value"); | |
afcfaa69 | 89 | DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy, oom_policy, OOMPolicy, "Failed to parse OOM policy"); |
53577580 YW |
90 | DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos, ip_tos, int, -1, "Failed to parse IP TOS value"); |
91 | DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight, cg_blkio_weight_parse, uint64_t, "Invalid block IO weight"); | |
92 | DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight, cg_weight_parse, uint64_t, "Invalid weight"); | |
93 | DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares, cg_cpu_shares_parse, uint64_t, "Invalid CPU shares"); | |
94 | DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags, mount_propagation_flags_from_string, unsigned long, "Failed to parse mount flag"); | |
b070c7c0 | 95 | DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy, mpol, int, -1, "Invalid NUMA policy type"); |
5afe510c | 96 | |
f32b43bd LP |
97 | int config_parse_unit_deps( |
98 | const char *unit, | |
99 | const char *filename, | |
100 | unsigned line, | |
101 | const char *section, | |
102 | unsigned section_line, | |
103 | const char *lvalue, | |
104 | int ltype, | |
105 | const char *rvalue, | |
106 | void *data, | |
107 | void *userdata) { | |
3efd4195 | 108 | |
f975e971 | 109 | UnitDependency d = ltype; |
87f0e418 | 110 | Unit *u = userdata; |
3d793d29 | 111 | const char *p; |
3efd4195 LP |
112 | |
113 | assert(filename); | |
114 | assert(lvalue); | |
115 | assert(rvalue); | |
3efd4195 | 116 | |
3d793d29 | 117 | p = rvalue; |
9ed794a3 | 118 | for (;;) { |
3d793d29 | 119 | _cleanup_free_ char *word = NULL, *k = NULL; |
3efd4195 | 120 | int r; |
3efd4195 | 121 | |
c89f52ac | 122 | r = extract_first_word(&p, &word, NULL, EXTRACT_RETAIN_ESCAPE); |
3d793d29 SS |
123 | if (r == 0) |
124 | break; | |
125 | if (r == -ENOMEM) | |
74051b9b | 126 | return log_oom(); |
3d793d29 SS |
127 | if (r < 0) { |
128 | log_syntax(unit, LOG_ERR, filename, line, r, "Invalid syntax, ignoring: %s", rvalue); | |
129 | break; | |
130 | } | |
3efd4195 | 131 | |
3d793d29 | 132 | r = unit_name_printf(u, word, &k); |
19f6d710 | 133 | if (r < 0) { |
063c4b1a | 134 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", word); |
19f6d710 LP |
135 | continue; |
136 | } | |
9e2f7c11 | 137 | |
35d8c19a | 138 | r = unit_add_dependency_by_name(u, d, k, true, UNIT_DEPENDENCY_FILE); |
57020a3a | 139 | if (r < 0) |
12ca818f | 140 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to add dependency on %s, ignoring: %m", k); |
3efd4195 LP |
141 | } |
142 | ||
143 | return 0; | |
144 | } | |
145 | ||
f32b43bd LP |
146 | int config_parse_obsolete_unit_deps( |
147 | const char *unit, | |
148 | const char *filename, | |
149 | unsigned line, | |
150 | const char *section, | |
151 | unsigned section_line, | |
152 | const char *lvalue, | |
153 | int ltype, | |
154 | const char *rvalue, | |
155 | void *data, | |
156 | void *userdata) { | |
157 | ||
158 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
159 | "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue, unit_dependency_to_string(ltype)); | |
160 | ||
161 | return config_parse_unit_deps(unit, filename, line, section, section_line, lvalue, ltype, rvalue, data, userdata); | |
162 | } | |
163 | ||
b02cb41c LP |
164 | int config_parse_unit_string_printf( |
165 | const char *unit, | |
166 | const char *filename, | |
167 | unsigned line, | |
168 | const char *section, | |
169 | unsigned section_line, | |
170 | const char *lvalue, | |
171 | int ltype, | |
172 | const char *rvalue, | |
173 | void *data, | |
174 | void *userdata) { | |
932921b5 | 175 | |
74051b9b | 176 | _cleanup_free_ char *k = NULL; |
b02cb41c | 177 | Unit *u = userdata; |
19f6d710 | 178 | int r; |
932921b5 LP |
179 | |
180 | assert(filename); | |
181 | assert(lvalue); | |
182 | assert(rvalue); | |
f2d3769a | 183 | assert(u); |
932921b5 | 184 | |
19f6d710 | 185 | r = unit_full_printf(u, rvalue, &k); |
b02cb41c | 186 | if (r < 0) { |
063c4b1a | 187 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
b02cb41c LP |
188 | return 0; |
189 | } | |
932921b5 | 190 | |
b02cb41c | 191 | return config_parse_string(unit, filename, line, section, section_line, lvalue, ltype, k, data, userdata); |
932921b5 LP |
192 | } |
193 | ||
12ca818f LP |
194 | int config_parse_unit_strv_printf( |
195 | const char *unit, | |
196 | const char *filename, | |
197 | unsigned line, | |
198 | const char *section, | |
199 | unsigned section_line, | |
200 | const char *lvalue, | |
201 | int ltype, | |
202 | const char *rvalue, | |
203 | void *data, | |
204 | void *userdata) { | |
8fef7659 LP |
205 | |
206 | Unit *u = userdata; | |
74051b9b | 207 | _cleanup_free_ char *k = NULL; |
19f6d710 | 208 | int r; |
8fef7659 LP |
209 | |
210 | assert(filename); | |
211 | assert(lvalue); | |
212 | assert(rvalue); | |
213 | assert(u); | |
214 | ||
19f6d710 | 215 | r = unit_full_printf(u, rvalue, &k); |
12ca818f | 216 | if (r < 0) { |
063c4b1a | 217 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
12ca818f LP |
218 | return 0; |
219 | } | |
8fef7659 | 220 | |
12ca818f | 221 | return config_parse_strv(unit, filename, line, section, section_line, lvalue, ltype, k, data, userdata); |
8fef7659 LP |
222 | } |
223 | ||
5f5d8eab LP |
224 | int config_parse_unit_path_printf( |
225 | const char *unit, | |
226 | const char *filename, | |
227 | unsigned line, | |
228 | const char *section, | |
229 | unsigned section_line, | |
230 | const char *lvalue, | |
231 | int ltype, | |
232 | const char *rvalue, | |
233 | void *data, | |
234 | void *userdata) { | |
6ea832a2 | 235 | |
74051b9b | 236 | _cleanup_free_ char *k = NULL; |
811ba7a0 | 237 | Unit *u = userdata; |
19f6d710 | 238 | int r; |
2c75fb73 | 239 | bool fatal = ltype; |
6ea832a2 LP |
240 | |
241 | assert(filename); | |
242 | assert(lvalue); | |
243 | assert(rvalue); | |
6ea832a2 LP |
244 | assert(u); |
245 | ||
e3c3d676 ZJS |
246 | /* Let's not bother with anything that is too long */ |
247 | if (strlen(rvalue) >= PATH_MAX) { | |
248 | log_syntax(unit, LOG_ERR, filename, line, 0, | |
249 | "%s value too long%s.", | |
250 | lvalue, fatal ? "" : ", ignoring"); | |
251 | return fatal ? -ENAMETOOLONG : 0; | |
252 | } | |
253 | ||
19f6d710 | 254 | r = unit_full_printf(u, rvalue, &k); |
811ba7a0 | 255 | if (r < 0) { |
2c75fb73 | 256 | log_syntax(unit, LOG_ERR, filename, line, r, |
063c4b1a | 257 | "Failed to resolve unit specifiers in '%s'%s: %m", |
e3c3d676 | 258 | rvalue, fatal ? "" : ", ignoring"); |
2c75fb73 | 259 | return fatal ? -ENOEXEC : 0; |
811ba7a0 | 260 | } |
6ea832a2 | 261 | |
811ba7a0 LP |
262 | return config_parse_path(unit, filename, line, section, section_line, lvalue, ltype, k, data, userdata); |
263 | } | |
264 | ||
265 | int config_parse_unit_path_strv_printf( | |
266 | const char *unit, | |
267 | const char *filename, | |
268 | unsigned line, | |
269 | const char *section, | |
270 | unsigned section_line, | |
271 | const char *lvalue, | |
272 | int ltype, | |
273 | const char *rvalue, | |
274 | void *data, | |
275 | void *userdata) { | |
276 | ||
a2a5291b | 277 | char ***x = data; |
811ba7a0 | 278 | Unit *u = userdata; |
811ba7a0 | 279 | int r; |
035fe294 | 280 | const char *p; |
811ba7a0 LP |
281 | |
282 | assert(filename); | |
283 | assert(lvalue); | |
284 | assert(rvalue); | |
285 | assert(u); | |
286 | ||
499295fb | 287 | if (isempty(rvalue)) { |
9f2d41a6 | 288 | *x = strv_free(*x); |
499295fb YW |
289 | return 0; |
290 | } | |
291 | ||
035fe294 ZJS |
292 | for (p = rvalue;;) { |
293 | _cleanup_free_ char *word = NULL, *k = NULL; | |
811ba7a0 | 294 | |
035fe294 ZJS |
295 | r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES); |
296 | if (r == 0) | |
297 | return 0; | |
298 | if (r == -ENOMEM) | |
299 | return log_oom(); | |
300 | if (r < 0) { | |
301 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
302 | "Invalid syntax, ignoring: %s", rvalue); | |
303 | return 0; | |
304 | } | |
811ba7a0 | 305 | |
035fe294 | 306 | r = unit_full_printf(u, word, &k); |
811ba7a0 | 307 | if (r < 0) { |
035fe294 | 308 | log_syntax(unit, LOG_ERR, filename, line, r, |
063c4b1a | 309 | "Failed to resolve unit specifiers in '%s', ignoring: %m", word); |
811ba7a0 LP |
310 | return 0; |
311 | } | |
312 | ||
2f4d31c1 YW |
313 | r = path_simplify_and_warn(k, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
314 | if (r < 0) | |
811ba7a0 | 315 | return 0; |
811ba7a0 | 316 | |
7d2c9c6b | 317 | r = strv_consume(x, TAKE_PTR(k)); |
811ba7a0 LP |
318 | if (r < 0) |
319 | return log_oom(); | |
811ba7a0 | 320 | } |
6ea832a2 LP |
321 | } |
322 | ||
4a66b5c9 LP |
323 | static int patch_var_run( |
324 | const char *unit, | |
325 | const char *filename, | |
326 | unsigned line, | |
327 | const char *lvalue, | |
328 | char **path) { | |
329 | ||
330 | const char *e; | |
331 | char *z; | |
332 | ||
333 | e = path_startswith(*path, "/var/run/"); | |
334 | if (!e) | |
335 | return 0; | |
336 | ||
337 | z = path_join("/run/", e); | |
338 | if (!z) | |
339 | return log_oom(); | |
340 | ||
341 | log_syntax(unit, LOG_NOTICE, filename, line, 0, | |
342 | "%s= references a path below legacy directory /var/run/, updating %s → %s; " | |
343 | "please update the unit file accordingly.", lvalue, *path, z); | |
344 | ||
345 | free_and_replace(*path, z); | |
346 | ||
347 | return 1; | |
348 | } | |
349 | ||
350 | int config_parse_socket_listen( | |
351 | const char *unit, | |
352 | const char *filename, | |
353 | unsigned line, | |
354 | const char *section, | |
355 | unsigned section_line, | |
356 | const char *lvalue, | |
357 | int ltype, | |
358 | const char *rvalue, | |
359 | void *data, | |
360 | void *userdata) { | |
42f4e3c4 | 361 | |
b1389b0d ZJS |
362 | _cleanup_free_ SocketPort *p = NULL; |
363 | SocketPort *tail; | |
542563ba | 364 | Socket *s; |
19f6d710 | 365 | int r; |
16354eff | 366 | |
42f4e3c4 LP |
367 | assert(filename); |
368 | assert(lvalue); | |
369 | assert(rvalue); | |
370 | assert(data); | |
371 | ||
595ed347 | 372 | s = SOCKET(data); |
542563ba | 373 | |
74051b9b LP |
374 | if (isempty(rvalue)) { |
375 | /* An empty assignment removes all ports */ | |
376 | socket_free_ports(s); | |
377 | return 0; | |
378 | } | |
379 | ||
7f110ff9 LP |
380 | p = new0(SocketPort, 1); |
381 | if (!p) | |
74051b9b | 382 | return log_oom(); |
916abb21 | 383 | |
74051b9b | 384 | if (ltype != SOCKET_SOCKET) { |
2f4d31c1 | 385 | _cleanup_free_ char *k = NULL; |
916abb21 | 386 | |
2f4d31c1 | 387 | r = unit_full_printf(UNIT(s), rvalue, &k); |
19f6d710 | 388 | if (r < 0) { |
063c4b1a | 389 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
12ca818f | 390 | return 0; |
916abb21 LP |
391 | } |
392 | ||
2f4d31c1 YW |
393 | r = path_simplify_and_warn(k, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
394 | if (r < 0) | |
395 | return 0; | |
396 | ||
4a66b5c9 LP |
397 | if (ltype == SOCKET_FIFO) { |
398 | r = patch_var_run(unit, filename, line, lvalue, &k); | |
399 | if (r < 0) | |
400 | return r; | |
401 | } | |
402 | ||
2f4d31c1 YW |
403 | free_and_replace(p->path, k); |
404 | p->type = ltype; | |
916abb21 | 405 | |
7a22745a | 406 | } else if (streq(lvalue, "ListenNetlink")) { |
74051b9b | 407 | _cleanup_free_ char *k = NULL; |
1fd45a90 | 408 | |
19f6d710 | 409 | r = unit_full_printf(UNIT(s), rvalue, &k); |
12ca818f | 410 | if (r < 0) { |
063c4b1a | 411 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
12ca818f LP |
412 | return 0; |
413 | } | |
7a22745a | 414 | |
12ca818f | 415 | r = socket_address_parse_netlink(&p->address, k); |
1fd45a90 | 416 | if (r < 0) { |
063c4b1a | 417 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse address value in '%s', ignoring: %m", k); |
7a22745a LP |
418 | return 0; |
419 | } | |
420 | ||
2f4d31c1 YW |
421 | p->type = SOCKET_SOCKET; |
422 | ||
542563ba | 423 | } else { |
74051b9b | 424 | _cleanup_free_ char *k = NULL; |
1fd45a90 | 425 | |
19f6d710 | 426 | r = unit_full_printf(UNIT(s), rvalue, &k); |
12ca818f | 427 | if (r < 0) { |
063c4b1a | 428 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
12ca818f LP |
429 | return 0; |
430 | } | |
542563ba | 431 | |
4a66b5c9 LP |
432 | if (k[0] == '/') { /* Only for AF_UNIX file system sockets… */ |
433 | r = patch_var_run(unit, filename, line, lvalue, &k); | |
434 | if (r < 0) | |
435 | return r; | |
436 | } | |
437 | ||
12ca818f | 438 | r = socket_address_parse_and_warn(&p->address, k); |
1fd45a90 | 439 | if (r < 0) { |
f847b8b7 | 440 | if (r != -EAFNOSUPPORT) |
063c4b1a | 441 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse address value in '%s', ignoring: %m", k); |
c0b34696 | 442 | return 0; |
542563ba LP |
443 | } |
444 | ||
445 | if (streq(lvalue, "ListenStream")) | |
446 | p->address.type = SOCK_STREAM; | |
447 | else if (streq(lvalue, "ListenDatagram")) | |
448 | p->address.type = SOCK_DGRAM; | |
449 | else { | |
450 | assert(streq(lvalue, "ListenSequentialPacket")); | |
451 | p->address.type = SOCK_SEQPACKET; | |
452 | } | |
453 | ||
454 | if (socket_address_family(&p->address) != AF_LOCAL && p->address.type == SOCK_SEQPACKET) { | |
12ca818f | 455 | log_syntax(unit, LOG_ERR, filename, line, 0, "Address family not supported, ignoring: %s", rvalue); |
c0b34696 | 456 | return 0; |
542563ba | 457 | } |
2f4d31c1 YW |
458 | |
459 | p->type = SOCKET_SOCKET; | |
16354eff LP |
460 | } |
461 | ||
542563ba | 462 | p->fd = -1; |
15087cdb PS |
463 | p->auxiliary_fds = NULL; |
464 | p->n_auxiliary_fds = 0; | |
2e41a51e | 465 | p->socket = s; |
49f91047 | 466 | |
533f8a67 YW |
467 | LIST_FIND_TAIL(port, s->ports, tail); |
468 | LIST_INSERT_AFTER(port, s->ports, tail, p); | |
469 | ||
b1389b0d | 470 | p = NULL; |
542563ba | 471 | |
16354eff | 472 | return 0; |
42f4e3c4 LP |
473 | } |
474 | ||
41bf0590 LP |
475 | int config_parse_exec_nice( |
476 | const char *unit, | |
477 | const char *filename, | |
478 | unsigned line, | |
479 | const char *section, | |
480 | unsigned section_line, | |
481 | const char *lvalue, | |
482 | int ltype, | |
483 | const char *rvalue, | |
484 | void *data, | |
485 | void *userdata) { | |
034c6ed7 | 486 | |
fb33a393 | 487 | ExecContext *c = data; |
e8e581bf | 488 | int priority, r; |
034c6ed7 LP |
489 | |
490 | assert(filename); | |
491 | assert(lvalue); | |
492 | assert(rvalue); | |
493 | assert(data); | |
494 | ||
de5e6038 YW |
495 | if (isempty(rvalue)) { |
496 | c->nice_set = false; | |
497 | return 0; | |
498 | } | |
499 | ||
41bf0590 | 500 | r = parse_nice(rvalue, &priority); |
e8e581bf | 501 | if (r < 0) { |
41bf0590 LP |
502 | if (r == -ERANGE) |
503 | log_syntax(unit, LOG_ERR, filename, line, r, "Nice priority out of range, ignoring: %s", rvalue); | |
504 | else | |
063c4b1a | 505 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse nice priority '%s', ignoring: %m", rvalue); |
c0b34696 | 506 | return 0; |
034c6ed7 LP |
507 | } |
508 | ||
fb33a393 | 509 | c->nice = priority; |
71155933 | 510 | c->nice_set = true; |
fb33a393 | 511 | |
034c6ed7 LP |
512 | return 0; |
513 | } | |
514 | ||
e9eb2c02 LP |
515 | int config_parse_exec_oom_score_adjust( |
516 | const char* unit, | |
517 | const char *filename, | |
518 | unsigned line, | |
519 | const char *section, | |
520 | unsigned section_line, | |
521 | const char *lvalue, | |
522 | int ltype, | |
523 | const char *rvalue, | |
524 | void *data, | |
525 | void *userdata) { | |
034c6ed7 | 526 | |
fb33a393 | 527 | ExecContext *c = data; |
e8e581bf | 528 | int oa, r; |
034c6ed7 LP |
529 | |
530 | assert(filename); | |
531 | assert(lvalue); | |
532 | assert(rvalue); | |
533 | assert(data); | |
534 | ||
e9eb2c02 LP |
535 | if (isempty(rvalue)) { |
536 | c->oom_score_adjust_set = false; | |
c0b34696 | 537 | return 0; |
034c6ed7 LP |
538 | } |
539 | ||
e9eb2c02 | 540 | r = parse_oom_score_adjust(rvalue, &oa); |
e9eb2c02 | 541 | if (r < 0) { |
063c4b1a YW |
542 | if (r == -ERANGE) |
543 | log_syntax(unit, LOG_ERR, filename, line, r, "OOM score adjust value out of range, ignoring: %s", rvalue); | |
544 | else | |
545 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue); | |
c0b34696 | 546 | return 0; |
034c6ed7 LP |
547 | } |
548 | ||
dd6c17b1 LP |
549 | c->oom_score_adjust = oa; |
550 | c->oom_score_adjust_set = true; | |
fb33a393 | 551 | |
034c6ed7 LP |
552 | return 0; |
553 | } | |
554 | ||
527b7a42 LP |
555 | int config_parse_exec( |
556 | const char *unit, | |
557 | const char *filename, | |
558 | unsigned line, | |
559 | const char *section, | |
560 | unsigned section_line, | |
561 | const char *lvalue, | |
562 | int ltype, | |
563 | const char *rvalue, | |
564 | void *data, | |
565 | void *userdata) { | |
034c6ed7 | 566 | |
46a0d98a | 567 | ExecCommand **e = data; |
5125e762 | 568 | Unit *u = userdata; |
46a0d98a FB |
569 | const char *p; |
570 | bool semicolon; | |
7f110ff9 | 571 | int r; |
034c6ed7 LP |
572 | |
573 | assert(filename); | |
574 | assert(lvalue); | |
575 | assert(rvalue); | |
61e5d8ed | 576 | assert(e); |
034c6ed7 | 577 | |
74051b9b | 578 | e += ltype; |
c83f1f30 | 579 | rvalue += strspn(rvalue, WHITESPACE); |
c83f1f30 | 580 | |
74051b9b LP |
581 | if (isempty(rvalue)) { |
582 | /* An empty assignment resets the list */ | |
f1acf85a | 583 | *e = exec_command_free_list(*e); |
74051b9b LP |
584 | return 0; |
585 | } | |
586 | ||
bd1b973f | 587 | p = rvalue; |
46a0d98a | 588 | do { |
dea7b6b0 | 589 | _cleanup_free_ char *path = NULL, *firstword = NULL; |
165a31c0 LP |
590 | ExecCommandFlags flags = 0; |
591 | bool ignore = false, separate_argv0 = false; | |
dea7b6b0 | 592 | _cleanup_free_ ExecCommand *nce = NULL; |
46a0d98a FB |
593 | _cleanup_strv_free_ char **n = NULL; |
594 | size_t nlen = 0, nbufsize = 0; | |
5125e762 | 595 | const char *f; |
6c666e26 | 596 | |
46a0d98a FB |
597 | semicolon = false; |
598 | ||
9a82ab95 | 599 | r = extract_first_word_and_warn(&p, &firstword, NULL, EXTRACT_QUOTES|EXTRACT_CUNESCAPE, unit, filename, line, rvalue); |
46a0d98a FB |
600 | if (r <= 0) |
601 | return 0; | |
6c666e26 | 602 | |
46a0d98a | 603 | f = firstword; |
007f48bb | 604 | for (;;) { |
165a31c0 LP |
605 | /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't |
606 | * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of | |
7ca69792 AZ |
607 | * argv[0]; if it's prefixed with :, we will not do environment variable substitution; |
608 | * if it's prefixed with +, it will be run with full privileges and no sandboxing; if | |
165a31c0 LP |
609 | * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if |
610 | * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient | |
611 | * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most | |
612 | * other sandboxing, with some special exceptions for changing UID. | |
613 | * | |
614 | * The idea is that '!!' may be used to write services that can take benefit of systemd's | |
615 | * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to | |
616 | * privilege dropping within the daemon if the kernel does not offer that. */ | |
617 | ||
618 | if (*f == '-' && !(flags & EXEC_COMMAND_IGNORE_FAILURE)) { | |
619 | flags |= EXEC_COMMAND_IGNORE_FAILURE; | |
46a0d98a | 620 | ignore = true; |
165a31c0 | 621 | } else if (*f == '@' && !separate_argv0) |
46a0d98a | 622 | separate_argv0 = true; |
7ca69792 AZ |
623 | else if (*f == ':' && !(flags & EXEC_COMMAND_NO_ENV_EXPAND)) |
624 | flags |= EXEC_COMMAND_NO_ENV_EXPAND; | |
165a31c0 LP |
625 | else if (*f == '+' && !(flags & (EXEC_COMMAND_FULLY_PRIVILEGED|EXEC_COMMAND_NO_SETUID|EXEC_COMMAND_AMBIENT_MAGIC))) |
626 | flags |= EXEC_COMMAND_FULLY_PRIVILEGED; | |
627 | else if (*f == '!' && !(flags & (EXEC_COMMAND_FULLY_PRIVILEGED|EXEC_COMMAND_NO_SETUID|EXEC_COMMAND_AMBIENT_MAGIC))) | |
628 | flags |= EXEC_COMMAND_NO_SETUID; | |
629 | else if (*f == '!' && !(flags & (EXEC_COMMAND_FULLY_PRIVILEGED|EXEC_COMMAND_AMBIENT_MAGIC))) { | |
630 | flags &= ~EXEC_COMMAND_NO_SETUID; | |
631 | flags |= EXEC_COMMAND_AMBIENT_MAGIC; | |
632 | } else | |
46a0d98a | 633 | break; |
313cefa1 | 634 | f++; |
61e5d8ed | 635 | } |
46a0d98a | 636 | |
5125e762 LP |
637 | r = unit_full_printf(u, f, &path); |
638 | if (r < 0) { | |
bb28e684 | 639 | log_syntax(unit, LOG_ERR, filename, line, r, |
063c4b1a | 640 | "Failed to resolve unit specifiers in '%s'%s: %m", |
bb28e684 ZJS |
641 | f, ignore ? ", ignoring" : ""); |
642 | return ignore ? 0 : -ENOEXEC; | |
5125e762 LP |
643 | } |
644 | ||
645 | if (isempty(path)) { | |
46a0d98a | 646 | /* First word is either "-" or "@" with no command. */ |
bb28e684 | 647 | log_syntax(unit, LOG_ERR, filename, line, 0, |
063c4b1a | 648 | "Empty path in command line%s: '%s'", |
bb28e684 ZJS |
649 | ignore ? ", ignoring" : "", rvalue); |
650 | return ignore ? 0 : -ENOEXEC; | |
b2fadec6 | 651 | } |
5125e762 | 652 | if (!string_is_safe(path)) { |
bb28e684 | 653 | log_syntax(unit, LOG_ERR, filename, line, 0, |
5008da1e ZJS |
654 | "Executable name contains special characters%s: %s", |
655 | ignore ? ", ignoring" : "", path); | |
bb28e684 | 656 | return ignore ? 0 : -ENOEXEC; |
46a0d98a | 657 | } |
5125e762 | 658 | if (endswith(path, "/")) { |
bb28e684 ZJS |
659 | log_syntax(unit, LOG_ERR, filename, line, 0, |
660 | "Executable path specifies a directory%s: %s", | |
5008da1e | 661 | ignore ? ", ignoring" : "", path); |
bb28e684 | 662 | return ignore ? 0 : -ENOEXEC; |
46a0d98a | 663 | } |
61e5d8ed | 664 | |
5008da1e ZJS |
665 | if (!path_is_absolute(path)) { |
666 | const char *prefix; | |
667 | bool found = false; | |
668 | ||
669 | if (!filename_is_valid(path)) { | |
670 | log_syntax(unit, LOG_ERR, filename, line, 0, | |
671 | "Neither a valid executable name nor an absolute path%s: %s", | |
672 | ignore ? ", ignoring" : "", path); | |
673 | return ignore ? 0 : -ENOEXEC; | |
674 | } | |
675 | ||
676 | /* Resolve a single-component name to a full path */ | |
677 | NULSTR_FOREACH(prefix, DEFAULT_PATH_NULSTR) { | |
678 | _cleanup_free_ char *fullpath = NULL; | |
679 | ||
657ee2d8 | 680 | fullpath = path_join(prefix, path); |
5008da1e ZJS |
681 | if (!fullpath) |
682 | return log_oom(); | |
683 | ||
684 | if (access(fullpath, F_OK) >= 0) { | |
685 | free_and_replace(path, fullpath); | |
686 | found = true; | |
687 | break; | |
688 | } | |
689 | } | |
690 | ||
691 | if (!found) { | |
692 | log_syntax(unit, LOG_ERR, filename, line, 0, | |
693 | "Executable \"%s\" not found in path \"%s\"%s", | |
694 | path, DEFAULT_PATH, ignore ? ", ignoring" : ""); | |
695 | return ignore ? 0 : -ENOEXEC; | |
696 | } | |
697 | } | |
698 | ||
46a0d98a | 699 | if (!separate_argv0) { |
5125e762 LP |
700 | char *w = NULL; |
701 | ||
46a0d98a FB |
702 | if (!GREEDY_REALLOC(n, nbufsize, nlen + 2)) |
703 | return log_oom(); | |
5125e762 LP |
704 | |
705 | w = strdup(path); | |
706 | if (!w) | |
46a0d98a | 707 | return log_oom(); |
5125e762 | 708 | n[nlen++] = w; |
46a0d98a FB |
709 | n[nlen] = NULL; |
710 | } | |
7f110ff9 | 711 | |
858d36c1 | 712 | path_simplify(path, false); |
46a0d98a | 713 | |
4b1c1753 | 714 | while (!isempty(p)) { |
5125e762 | 715 | _cleanup_free_ char *word = NULL, *resolved = NULL; |
46a0d98a FB |
716 | |
717 | /* Check explicitly for an unquoted semicolon as | |
718 | * command separator token. */ | |
719 | if (p[0] == ';' && (!p[1] || strchr(WHITESPACE, p[1]))) { | |
313cefa1 | 720 | p++; |
46a0d98a FB |
721 | p += strspn(p, WHITESPACE); |
722 | semicolon = true; | |
723 | break; | |
c8539536 | 724 | } |
7f110ff9 | 725 | |
5125e762 LP |
726 | /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc. |
727 | * extract_first_word() would return the same for all of those. */ | |
46a0d98a | 728 | if (p[0] == '\\' && p[1] == ';' && (!p[2] || strchr(WHITESPACE, p[2]))) { |
5125e762 LP |
729 | char *w; |
730 | ||
46a0d98a FB |
731 | p += 2; |
732 | p += strspn(p, WHITESPACE); | |
5125e762 | 733 | |
46a0d98a FB |
734 | if (!GREEDY_REALLOC(n, nbufsize, nlen + 2)) |
735 | return log_oom(); | |
5125e762 LP |
736 | |
737 | w = strdup(";"); | |
738 | if (!w) | |
46a0d98a | 739 | return log_oom(); |
5125e762 | 740 | n[nlen++] = w; |
46a0d98a FB |
741 | n[nlen] = NULL; |
742 | continue; | |
61e5d8ed | 743 | } |
c8539536 | 744 | |
9a82ab95 | 745 | r = extract_first_word_and_warn(&p, &word, NULL, EXTRACT_QUOTES|EXTRACT_CUNESCAPE, unit, filename, line, rvalue); |
46a0d98a FB |
746 | if (r == 0) |
747 | break; | |
5125e762 | 748 | if (r < 0) |
bb28e684 | 749 | return ignore ? 0 : -ENOEXEC; |
5125e762 LP |
750 | |
751 | r = unit_full_printf(u, word, &resolved); | |
752 | if (r < 0) { | |
bb28e684 | 753 | log_syntax(unit, LOG_ERR, filename, line, r, |
063c4b1a | 754 | "Failed to resolve unit specifiers in %s%s: %m", |
bb28e684 ZJS |
755 | word, ignore ? ", ignoring" : ""); |
756 | return ignore ? 0 : -ENOEXEC; | |
5125e762 | 757 | } |
46a0d98a FB |
758 | |
759 | if (!GREEDY_REALLOC(n, nbufsize, nlen + 2)) | |
760 | return log_oom(); | |
1cc6c93a YW |
761 | |
762 | n[nlen++] = TAKE_PTR(resolved); | |
46a0d98a | 763 | n[nlen] = NULL; |
61e5d8ed LP |
764 | } |
765 | ||
46a0d98a | 766 | if (!n || !n[0]) { |
bb28e684 ZJS |
767 | log_syntax(unit, LOG_ERR, filename, line, 0, |
768 | "Empty executable name or zeroeth argument%s: %s", | |
769 | ignore ? ", ignoring" : "", rvalue); | |
770 | return ignore ? 0 : -ENOEXEC; | |
7f110ff9 | 771 | } |
6c666e26 | 772 | |
7f110ff9 | 773 | nce = new0(ExecCommand, 1); |
46a0d98a FB |
774 | if (!nce) |
775 | return log_oom(); | |
61e5d8ed | 776 | |
1cc6c93a YW |
777 | nce->argv = TAKE_PTR(n); |
778 | nce->path = TAKE_PTR(path); | |
165a31c0 | 779 | nce->flags = flags; |
034c6ed7 | 780 | |
61e5d8ed | 781 | exec_command_append_list(e, nce); |
01f78473 | 782 | |
46a0d98a | 783 | /* Do not _cleanup_free_ these. */ |
46a0d98a | 784 | nce = NULL; |
034c6ed7 | 785 | |
46a0d98a FB |
786 | rvalue = p; |
787 | } while (semicolon); | |
034c6ed7 | 788 | |
46a0d98a | 789 | return 0; |
034c6ed7 LP |
790 | } |
791 | ||
d31645ad LP |
792 | int config_parse_socket_bindtodevice( |
793 | const char* unit, | |
794 | const char *filename, | |
795 | unsigned line, | |
796 | const char *section, | |
797 | unsigned section_line, | |
798 | const char *lvalue, | |
799 | int ltype, | |
800 | const char *rvalue, | |
801 | void *data, | |
802 | void *userdata) { | |
acbb0225 LP |
803 | |
804 | Socket *s = data; | |
acbb0225 LP |
805 | |
806 | assert(filename); | |
807 | assert(lvalue); | |
808 | assert(rvalue); | |
809 | assert(data); | |
810 | ||
063c4b1a YW |
811 | if (isempty(rvalue) || streq(rvalue, "*")) { |
812 | s->bind_to_device = mfree(s->bind_to_device); | |
813 | return 0; | |
814 | } | |
d31645ad | 815 | |
063c4b1a YW |
816 | if (!ifname_valid(rvalue)) { |
817 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid interface name, ignoring: %s", rvalue); | |
818 | return 0; | |
819 | } | |
acbb0225 | 820 | |
3c381a67 YW |
821 | if (free_and_strdup(&s->bind_to_device, rvalue) < 0) |
822 | return log_oom(); | |
acbb0225 LP |
823 | |
824 | return 0; | |
825 | } | |
826 | ||
9bd6a50e LP |
827 | int config_parse_exec_input( |
828 | const char *unit, | |
829 | const char *filename, | |
830 | unsigned line, | |
831 | const char *section, | |
832 | unsigned section_line, | |
833 | const char *lvalue, | |
834 | int ltype, | |
835 | const char *rvalue, | |
836 | void *data, | |
837 | void *userdata) { | |
52c239d7 | 838 | |
52c239d7 | 839 | ExecContext *c = data; |
2038c3f5 LP |
840 | Unit *u = userdata; |
841 | const char *n; | |
842 | ExecInput ei; | |
52c239d7 LB |
843 | int r; |
844 | ||
845 | assert(data); | |
846 | assert(filename); | |
847 | assert(line); | |
848 | assert(rvalue); | |
849 | ||
2038c3f5 LP |
850 | n = startswith(rvalue, "fd:"); |
851 | if (n) { | |
852 | _cleanup_free_ char *resolved = NULL; | |
853 | ||
854 | r = unit_full_printf(u, n, &resolved); | |
855 | if (r < 0) | |
063c4b1a | 856 | return log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s': %m", n); |
2038c3f5 LP |
857 | |
858 | if (isempty(resolved)) | |
859 | resolved = mfree(resolved); | |
860 | else if (!fdname_is_valid(resolved)) { | |
861 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid file descriptor name: %s", resolved); | |
6f40aa45 | 862 | return -ENOEXEC; |
52c239d7 | 863 | } |
9bd6a50e | 864 | |
2038c3f5 LP |
865 | free_and_replace(c->stdio_fdname[STDIN_FILENO], resolved); |
866 | ||
867 | ei = EXEC_INPUT_NAMED_FD; | |
868 | ||
869 | } else if ((n = startswith(rvalue, "file:"))) { | |
870 | _cleanup_free_ char *resolved = NULL; | |
871 | ||
872 | r = unit_full_printf(u, n, &resolved); | |
52c239d7 | 873 | if (r < 0) |
063c4b1a | 874 | return log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s': %m", n); |
9bd6a50e | 875 | |
2f4d31c1 YW |
876 | r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE | PATH_CHECK_FATAL, unit, filename, line, lvalue); |
877 | if (r < 0) | |
6f40aa45 | 878 | return -ENOEXEC; |
2038c3f5 LP |
879 | |
880 | free_and_replace(c->stdio_file[STDIN_FILENO], resolved); | |
881 | ||
882 | ei = EXEC_INPUT_FILE; | |
9bd6a50e | 883 | |
52c239d7 | 884 | } else { |
9bd6a50e LP |
885 | ei = exec_input_from_string(rvalue); |
886 | if (ei < 0) { | |
52c239d7 | 887 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse input specifier, ignoring: %s", rvalue); |
9bd6a50e LP |
888 | return 0; |
889 | } | |
52c239d7 | 890 | } |
9bd6a50e | 891 | |
2038c3f5 | 892 | c->std_input = ei; |
9bd6a50e | 893 | return 0; |
52c239d7 LB |
894 | } |
895 | ||
08f3be7a LP |
896 | int config_parse_exec_input_text( |
897 | const char *unit, | |
898 | const char *filename, | |
899 | unsigned line, | |
900 | const char *section, | |
901 | unsigned section_line, | |
902 | const char *lvalue, | |
903 | int ltype, | |
904 | const char *rvalue, | |
905 | void *data, | |
906 | void *userdata) { | |
907 | ||
908 | _cleanup_free_ char *unescaped = NULL, *resolved = NULL; | |
909 | ExecContext *c = data; | |
910 | Unit *u = userdata; | |
911 | size_t sz; | |
912 | void *p; | |
913 | int r; | |
914 | ||
915 | assert(data); | |
916 | assert(filename); | |
917 | assert(line); | |
918 | assert(rvalue); | |
919 | ||
920 | if (isempty(rvalue)) { | |
921 | /* Reset if the empty string is assigned */ | |
922 | c->stdin_data = mfree(c->stdin_data); | |
923 | c->stdin_data_size = 0; | |
52c239d7 LB |
924 | return 0; |
925 | } | |
08f3be7a LP |
926 | |
927 | r = cunescape(rvalue, 0, &unescaped); | |
2038c3f5 | 928 | if (r < 0) |
063c4b1a | 929 | return log_syntax(unit, LOG_ERR, filename, line, r, "Failed to decode C escaped text '%s': %m", rvalue); |
08f3be7a LP |
930 | |
931 | r = unit_full_printf(u, unescaped, &resolved); | |
2038c3f5 | 932 | if (r < 0) |
063c4b1a | 933 | return log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s': %m", unescaped); |
08f3be7a LP |
934 | |
935 | sz = strlen(resolved); | |
936 | if (c->stdin_data_size + sz + 1 < c->stdin_data_size || /* check for overflow */ | |
937 | c->stdin_data_size + sz + 1 > EXEC_STDIN_DATA_MAX) { | |
2038c3f5 LP |
938 | log_syntax(unit, LOG_ERR, filename, line, 0, "Standard input data too large (%zu), maximum of %zu permitted, ignoring.", c->stdin_data_size + sz, (size_t) EXEC_STDIN_DATA_MAX); |
939 | return -E2BIG; | |
08f3be7a LP |
940 | } |
941 | ||
942 | p = realloc(c->stdin_data, c->stdin_data_size + sz + 1); | |
943 | if (!p) | |
944 | return log_oom(); | |
945 | ||
946 | *((char*) mempcpy((char*) p + c->stdin_data_size, resolved, sz)) = '\n'; | |
947 | ||
948 | c->stdin_data = p; | |
949 | c->stdin_data_size += sz + 1; | |
950 | ||
951 | return 0; | |
52c239d7 LB |
952 | } |
953 | ||
08f3be7a LP |
954 | int config_parse_exec_input_data( |
955 | const char *unit, | |
956 | const char *filename, | |
957 | unsigned line, | |
958 | const char *section, | |
959 | unsigned section_line, | |
960 | const char *lvalue, | |
961 | int ltype, | |
962 | const char *rvalue, | |
963 | void *data, | |
964 | void *userdata) { | |
965 | ||
08f3be7a LP |
966 | _cleanup_free_ void *p = NULL; |
967 | ExecContext *c = data; | |
968 | size_t sz; | |
969 | void *q; | |
970 | int r; | |
971 | ||
972 | assert(data); | |
973 | assert(filename); | |
974 | assert(line); | |
975 | assert(rvalue); | |
976 | ||
977 | if (isempty(rvalue)) { | |
978 | /* Reset if the empty string is assigned */ | |
979 | c->stdin_data = mfree(c->stdin_data); | |
980 | c->stdin_data_size = 0; | |
981 | return 0; | |
982 | } | |
983 | ||
081f36d8 | 984 | r = unbase64mem(rvalue, (size_t) -1, &p, &sz); |
2038c3f5 | 985 | if (r < 0) |
081f36d8 | 986 | return log_syntax(unit, LOG_ERR, filename, line, r, "Failed to decode base64 data, ignoring: %s", rvalue); |
08f3be7a LP |
987 | |
988 | assert(sz > 0); | |
989 | ||
990 | if (c->stdin_data_size + sz < c->stdin_data_size || /* check for overflow */ | |
991 | c->stdin_data_size + sz > EXEC_STDIN_DATA_MAX) { | |
2038c3f5 LP |
992 | log_syntax(unit, LOG_ERR, filename, line, 0, "Standard input data too large (%zu), maximum of %zu permitted, ignoring.", c->stdin_data_size + sz, (size_t) EXEC_STDIN_DATA_MAX); |
993 | return -E2BIG; | |
08f3be7a LP |
994 | } |
995 | ||
996 | q = realloc(c->stdin_data, c->stdin_data_size + sz); | |
997 | if (!q) | |
998 | return log_oom(); | |
999 | ||
1000 | memcpy((uint8_t*) q + c->stdin_data_size, p, sz); | |
1001 | ||
1002 | c->stdin_data = q; | |
1003 | c->stdin_data_size += sz; | |
1004 | ||
1005 | return 0; | |
1006 | } | |
1007 | ||
2038c3f5 LP |
1008 | int config_parse_exec_output( |
1009 | const char *unit, | |
1010 | const char *filename, | |
1011 | unsigned line, | |
1012 | const char *section, | |
1013 | unsigned section_line, | |
1014 | const char *lvalue, | |
1015 | int ltype, | |
1016 | const char *rvalue, | |
1017 | void *data, | |
1018 | void *userdata) { | |
1019 | ||
1020 | _cleanup_free_ char *resolved = NULL; | |
1021 | const char *n; | |
52c239d7 | 1022 | ExecContext *c = data; |
2038c3f5 | 1023 | Unit *u = userdata; |
52c239d7 | 1024 | ExecOutput eo; |
52c239d7 LB |
1025 | int r; |
1026 | ||
1027 | assert(data); | |
1028 | assert(filename); | |
1029 | assert(line); | |
1030 | assert(lvalue); | |
1031 | assert(rvalue); | |
1032 | ||
2038c3f5 LP |
1033 | n = startswith(rvalue, "fd:"); |
1034 | if (n) { | |
1035 | r = unit_full_printf(u, n, &resolved); | |
1036 | if (r < 0) | |
063c4b1a | 1037 | return log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s: %m", n); |
2038c3f5 LP |
1038 | |
1039 | if (isempty(resolved)) | |
1040 | resolved = mfree(resolved); | |
1041 | else if (!fdname_is_valid(resolved)) { | |
1042 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid file descriptor name: %s", resolved); | |
6f40aa45 | 1043 | return -ENOEXEC; |
52c239d7 | 1044 | } |
2038c3f5 | 1045 | |
52c239d7 | 1046 | eo = EXEC_OUTPUT_NAMED_FD; |
2038c3f5 LP |
1047 | |
1048 | } else if ((n = startswith(rvalue, "file:"))) { | |
1049 | ||
1050 | r = unit_full_printf(u, n, &resolved); | |
1051 | if (r < 0) | |
063c4b1a | 1052 | return log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s: %m", n); |
2038c3f5 | 1053 | |
2f4d31c1 YW |
1054 | r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE | PATH_CHECK_FATAL, unit, filename, line, lvalue); |
1055 | if (r < 0) | |
6f40aa45 | 1056 | return -ENOEXEC; |
2038c3f5 LP |
1057 | |
1058 | eo = EXEC_OUTPUT_FILE; | |
1059 | ||
566b7d23 ZD |
1060 | } else if ((n = startswith(rvalue, "append:"))) { |
1061 | ||
1062 | r = unit_full_printf(u, n, &resolved); | |
1063 | if (r < 0) | |
1064 | return log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s: %m", n); | |
1065 | ||
1066 | r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE | PATH_CHECK_FATAL, unit, filename, line, lvalue); | |
1067 | if (r < 0) | |
1068 | return -ENOEXEC; | |
1069 | ||
1070 | eo = EXEC_OUTPUT_FILE_APPEND; | |
52c239d7 LB |
1071 | } else { |
1072 | eo = exec_output_from_string(rvalue); | |
2038c3f5 | 1073 | if (eo < 0) { |
52c239d7 LB |
1074 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse output specifier, ignoring: %s", rvalue); |
1075 | return 0; | |
1076 | } | |
1077 | } | |
1078 | ||
1079 | if (streq(lvalue, "StandardOutput")) { | |
2038c3f5 LP |
1080 | if (eo == EXEC_OUTPUT_NAMED_FD) |
1081 | free_and_replace(c->stdio_fdname[STDOUT_FILENO], resolved); | |
1082 | else | |
1083 | free_and_replace(c->stdio_file[STDOUT_FILENO], resolved); | |
1084 | ||
52c239d7 | 1085 | c->std_output = eo; |
2038c3f5 | 1086 | |
52c239d7 | 1087 | } else { |
2038c3f5 LP |
1088 | assert(streq(lvalue, "StandardError")); |
1089 | ||
1090 | if (eo == EXEC_OUTPUT_NAMED_FD) | |
1091 | free_and_replace(c->stdio_fdname[STDERR_FILENO], resolved); | |
1092 | else | |
1093 | free_and_replace(c->stdio_file[STDERR_FILENO], resolved); | |
1094 | ||
1095 | c->std_error = eo; | |
52c239d7 | 1096 | } |
2038c3f5 LP |
1097 | |
1098 | return 0; | |
52c239d7 | 1099 | } |
87f0e418 | 1100 | |
e8e581bf ZJS |
1101 | int config_parse_exec_io_class(const char *unit, |
1102 | const char *filename, | |
1103 | unsigned line, | |
1104 | const char *section, | |
71a61510 | 1105 | unsigned section_line, |
e8e581bf ZJS |
1106 | const char *lvalue, |
1107 | int ltype, | |
1108 | const char *rvalue, | |
1109 | void *data, | |
1110 | void *userdata) { | |
94f04347 LP |
1111 | |
1112 | ExecContext *c = data; | |
1113 | int x; | |
1114 | ||
1115 | assert(filename); | |
1116 | assert(lvalue); | |
1117 | assert(rvalue); | |
1118 | assert(data); | |
1119 | ||
617d253a YW |
1120 | if (isempty(rvalue)) { |
1121 | c->ioprio_set = false; | |
1122 | c->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 0); | |
1123 | return 0; | |
1124 | } | |
1125 | ||
f8b69d1d MS |
1126 | x = ioprio_class_from_string(rvalue); |
1127 | if (x < 0) { | |
12ca818f | 1128 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue); |
c0b34696 | 1129 | return 0; |
0d87eb42 | 1130 | } |
94f04347 LP |
1131 | |
1132 | c->ioprio = IOPRIO_PRIO_VALUE(x, IOPRIO_PRIO_DATA(c->ioprio)); | |
1133 | c->ioprio_set = true; | |
1134 | ||
1135 | return 0; | |
1136 | } | |
1137 | ||
e8e581bf ZJS |
1138 | int config_parse_exec_io_priority(const char *unit, |
1139 | const char *filename, | |
1140 | unsigned line, | |
1141 | const char *section, | |
71a61510 | 1142 | unsigned section_line, |
e8e581bf ZJS |
1143 | const char *lvalue, |
1144 | int ltype, | |
1145 | const char *rvalue, | |
1146 | void *data, | |
1147 | void *userdata) { | |
94f04347 LP |
1148 | |
1149 | ExecContext *c = data; | |
e8e581bf | 1150 | int i, r; |
94f04347 LP |
1151 | |
1152 | assert(filename); | |
1153 | assert(lvalue); | |
1154 | assert(rvalue); | |
1155 | assert(data); | |
1156 | ||
617d253a YW |
1157 | if (isempty(rvalue)) { |
1158 | c->ioprio_set = false; | |
1159 | c->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 0); | |
1160 | return 0; | |
1161 | } | |
1162 | ||
7f452159 LP |
1163 | r = ioprio_parse_priority(rvalue, &i); |
1164 | if (r < 0) { | |
12ca818f | 1165 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse IO priority, ignoring: %s", rvalue); |
c0b34696 | 1166 | return 0; |
071830ff LP |
1167 | } |
1168 | ||
94f04347 LP |
1169 | c->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c->ioprio), i); |
1170 | c->ioprio_set = true; | |
1171 | ||
071830ff LP |
1172 | return 0; |
1173 | } | |
1174 | ||
e8e581bf ZJS |
1175 | int config_parse_exec_cpu_sched_policy(const char *unit, |
1176 | const char *filename, | |
1177 | unsigned line, | |
1178 | const char *section, | |
71a61510 | 1179 | unsigned section_line, |
e8e581bf ZJS |
1180 | const char *lvalue, |
1181 | int ltype, | |
1182 | const char *rvalue, | |
1183 | void *data, | |
1184 | void *userdata) { | |
9eba9da4 | 1185 | |
94f04347 LP |
1186 | ExecContext *c = data; |
1187 | int x; | |
1188 | ||
1189 | assert(filename); | |
1190 | assert(lvalue); | |
1191 | assert(rvalue); | |
1192 | assert(data); | |
1193 | ||
b00e1a9e YW |
1194 | if (isempty(rvalue)) { |
1195 | c->cpu_sched_set = false; | |
1196 | c->cpu_sched_policy = SCHED_OTHER; | |
1197 | c->cpu_sched_priority = 0; | |
1198 | return 0; | |
1199 | } | |
1200 | ||
f8b69d1d MS |
1201 | x = sched_policy_from_string(rvalue); |
1202 | if (x < 0) { | |
12ca818f | 1203 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue); |
c0b34696 | 1204 | return 0; |
0d87eb42 | 1205 | } |
94f04347 LP |
1206 | |
1207 | c->cpu_sched_policy = x; | |
bb112710 HHPF |
1208 | /* Moving to or from real-time policy? We need to adjust the priority */ |
1209 | c->cpu_sched_priority = CLAMP(c->cpu_sched_priority, sched_get_priority_min(x), sched_get_priority_max(x)); | |
94f04347 LP |
1210 | c->cpu_sched_set = true; |
1211 | ||
1212 | return 0; | |
1213 | } | |
1214 | ||
b070c7c0 MS |
1215 | int config_parse_numa_mask(const char *unit, |
1216 | const char *filename, | |
1217 | unsigned line, | |
1218 | const char *section, | |
1219 | unsigned section_line, | |
1220 | const char *lvalue, | |
1221 | int ltype, | |
1222 | const char *rvalue, | |
1223 | void *data, | |
1224 | void *userdata) { | |
1225 | int r; | |
1226 | NUMAPolicy *p = data; | |
1227 | ||
1228 | assert(filename); | |
1229 | assert(lvalue); | |
1230 | assert(rvalue); | |
1231 | assert(data); | |
1232 | ||
1233 | r = parse_cpu_set_extend(rvalue, &p->nodes, true, unit, filename, line, lvalue); | |
1234 | if (r < 0) { | |
1235 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse NUMA node mask, ignoring: %s", rvalue); | |
1236 | return 0; | |
1237 | } | |
1238 | ||
1239 | return r; | |
1240 | } | |
1241 | ||
e8e581bf ZJS |
1242 | int config_parse_exec_cpu_sched_prio(const char *unit, |
1243 | const char *filename, | |
1244 | unsigned line, | |
1245 | const char *section, | |
71a61510 | 1246 | unsigned section_line, |
e8e581bf ZJS |
1247 | const char *lvalue, |
1248 | int ltype, | |
1249 | const char *rvalue, | |
1250 | void *data, | |
1251 | void *userdata) { | |
9eba9da4 LP |
1252 | |
1253 | ExecContext *c = data; | |
e8e581bf | 1254 | int i, min, max, r; |
9eba9da4 LP |
1255 | |
1256 | assert(filename); | |
1257 | assert(lvalue); | |
1258 | assert(rvalue); | |
1259 | assert(data); | |
1260 | ||
e8e581bf ZJS |
1261 | r = safe_atoi(rvalue, &i); |
1262 | if (r < 0) { | |
063c4b1a | 1263 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue); |
c0b34696 | 1264 | return 0; |
94f04347 | 1265 | } |
9eba9da4 | 1266 | |
bb112710 HHPF |
1267 | /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */ |
1268 | min = sched_get_priority_min(c->cpu_sched_policy); | |
1269 | max = sched_get_priority_max(c->cpu_sched_policy); | |
1270 | ||
1271 | if (i < min || i > max) { | |
12ca818f | 1272 | log_syntax(unit, LOG_ERR, filename, line, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue); |
bb112710 HHPF |
1273 | return 0; |
1274 | } | |
1275 | ||
94f04347 LP |
1276 | c->cpu_sched_priority = i; |
1277 | c->cpu_sched_set = true; | |
1278 | ||
1279 | return 0; | |
1280 | } | |
1281 | ||
e8e581bf ZJS |
1282 | int config_parse_exec_cpu_affinity(const char *unit, |
1283 | const char *filename, | |
1284 | unsigned line, | |
1285 | const char *section, | |
71a61510 | 1286 | unsigned section_line, |
e8e581bf ZJS |
1287 | const char *lvalue, |
1288 | int ltype, | |
1289 | const char *rvalue, | |
1290 | void *data, | |
1291 | void *userdata) { | |
94f04347 LP |
1292 | |
1293 | ExecContext *c = data; | |
94f04347 LP |
1294 | |
1295 | assert(filename); | |
1296 | assert(lvalue); | |
1297 | assert(rvalue); | |
1298 | assert(data); | |
1299 | ||
0985c7c4 | 1300 | return parse_cpu_set_extend(rvalue, &c->cpu_set, true, unit, filename, line, lvalue); |
94f04347 LP |
1301 | } |
1302 | ||
a103496c | 1303 | int config_parse_capability_set( |
65dce264 LP |
1304 | const char *unit, |
1305 | const char *filename, | |
1306 | unsigned line, | |
1307 | const char *section, | |
1308 | unsigned section_line, | |
1309 | const char *lvalue, | |
1310 | int ltype, | |
1311 | const char *rvalue, | |
1312 | void *data, | |
1313 | void *userdata) { | |
94f04347 | 1314 | |
a103496c IP |
1315 | uint64_t *capability_set = data; |
1316 | uint64_t sum = 0, initial = 0; | |
260abb78 | 1317 | bool invert = false; |
dd1f5bd0 | 1318 | int r; |
94f04347 LP |
1319 | |
1320 | assert(filename); | |
1321 | assert(lvalue); | |
1322 | assert(rvalue); | |
1323 | assert(data); | |
1324 | ||
260abb78 LP |
1325 | if (rvalue[0] == '~') { |
1326 | invert = true; | |
1327 | rvalue++; | |
1328 | } | |
1329 | ||
70d54d90 | 1330 | if (streq(lvalue, "CapabilityBoundingSet")) |
a103496c | 1331 | initial = CAP_ALL; /* initialized to all bits on */ |
755d4b67 | 1332 | /* else "AmbientCapabilities" initialized to all bits off */ |
260abb78 | 1333 | |
dd1f5bd0 | 1334 | r = capability_set_from_string(rvalue, &sum); |
dd1f5bd0 | 1335 | if (r < 0) { |
063c4b1a | 1336 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue, rvalue); |
dd1f5bd0 | 1337 | return 0; |
94f04347 | 1338 | } |
9eba9da4 | 1339 | |
a103496c | 1340 | if (sum == 0 || *capability_set == initial) |
c792ec2e IP |
1341 | /* "", "~" or uninitialized data -> replace */ |
1342 | *capability_set = invert ? ~sum : sum; | |
1343 | else { | |
a103496c | 1344 | /* previous data -> merge */ |
c792ec2e IP |
1345 | if (invert) |
1346 | *capability_set &= ~sum; | |
1347 | else | |
1348 | *capability_set |= sum; | |
1349 | } | |
260abb78 | 1350 | |
9eba9da4 LP |
1351 | return 0; |
1352 | } | |
1353 | ||
5f8640fb LP |
1354 | int config_parse_exec_selinux_context( |
1355 | const char *unit, | |
1356 | const char *filename, | |
1357 | unsigned line, | |
1358 | const char *section, | |
1359 | unsigned section_line, | |
1360 | const char *lvalue, | |
1361 | int ltype, | |
1362 | const char *rvalue, | |
1363 | void *data, | |
1364 | void *userdata) { | |
1365 | ||
1366 | ExecContext *c = data; | |
1367 | Unit *u = userdata; | |
1368 | bool ignore; | |
1369 | char *k; | |
1370 | int r; | |
1371 | ||
1372 | assert(filename); | |
1373 | assert(lvalue); | |
1374 | assert(rvalue); | |
1375 | assert(data); | |
1376 | ||
1377 | if (isempty(rvalue)) { | |
a1e58e8e | 1378 | c->selinux_context = mfree(c->selinux_context); |
5f8640fb LP |
1379 | c->selinux_context_ignore = false; |
1380 | return 0; | |
1381 | } | |
1382 | ||
1383 | if (rvalue[0] == '-') { | |
1384 | ignore = true; | |
1385 | rvalue++; | |
1386 | } else | |
1387 | ignore = false; | |
1388 | ||
18913df9 | 1389 | r = unit_full_printf(u, rvalue, &k); |
5f8640fb | 1390 | if (r < 0) { |
bb28e684 | 1391 | log_syntax(unit, LOG_ERR, filename, line, r, |
063c4b1a YW |
1392 | "Failed to resolve unit specifiers in '%s'%s: %m", |
1393 | rvalue, ignore ? ", ignoring" : ""); | |
bb28e684 | 1394 | return ignore ? 0 : -ENOEXEC; |
5f8640fb LP |
1395 | } |
1396 | ||
063c4b1a | 1397 | free_and_replace(c->selinux_context, k); |
5f8640fb LP |
1398 | c->selinux_context_ignore = ignore; |
1399 | ||
1400 | return 0; | |
1401 | } | |
1402 | ||
eef65bf3 MS |
1403 | int config_parse_exec_apparmor_profile( |
1404 | const char *unit, | |
1405 | const char *filename, | |
1406 | unsigned line, | |
1407 | const char *section, | |
1408 | unsigned section_line, | |
1409 | const char *lvalue, | |
1410 | int ltype, | |
1411 | const char *rvalue, | |
1412 | void *data, | |
1413 | void *userdata) { | |
1414 | ||
1415 | ExecContext *c = data; | |
1416 | Unit *u = userdata; | |
1417 | bool ignore; | |
1418 | char *k; | |
1419 | int r; | |
1420 | ||
1421 | assert(filename); | |
1422 | assert(lvalue); | |
1423 | assert(rvalue); | |
1424 | assert(data); | |
1425 | ||
1426 | if (isempty(rvalue)) { | |
a1e58e8e | 1427 | c->apparmor_profile = mfree(c->apparmor_profile); |
eef65bf3 MS |
1428 | c->apparmor_profile_ignore = false; |
1429 | return 0; | |
1430 | } | |
1431 | ||
1432 | if (rvalue[0] == '-') { | |
1433 | ignore = true; | |
1434 | rvalue++; | |
1435 | } else | |
1436 | ignore = false; | |
1437 | ||
18913df9 | 1438 | r = unit_full_printf(u, rvalue, &k); |
eef65bf3 | 1439 | if (r < 0) { |
bb28e684 | 1440 | log_syntax(unit, LOG_ERR, filename, line, r, |
063c4b1a YW |
1441 | "Failed to resolve unit specifiers in '%s'%s: %m", |
1442 | rvalue, ignore ? ", ignoring" : ""); | |
bb28e684 | 1443 | return ignore ? 0 : -ENOEXEC; |
eef65bf3 MS |
1444 | } |
1445 | ||
063c4b1a | 1446 | free_and_replace(c->apparmor_profile, k); |
eef65bf3 MS |
1447 | c->apparmor_profile_ignore = ignore; |
1448 | ||
1449 | return 0; | |
1450 | } | |
1451 | ||
2ca620c4 WC |
1452 | int config_parse_exec_smack_process_label( |
1453 | const char *unit, | |
1454 | const char *filename, | |
1455 | unsigned line, | |
1456 | const char *section, | |
1457 | unsigned section_line, | |
1458 | const char *lvalue, | |
1459 | int ltype, | |
1460 | const char *rvalue, | |
1461 | void *data, | |
1462 | void *userdata) { | |
1463 | ||
1464 | ExecContext *c = data; | |
1465 | Unit *u = userdata; | |
1466 | bool ignore; | |
1467 | char *k; | |
1468 | int r; | |
1469 | ||
1470 | assert(filename); | |
1471 | assert(lvalue); | |
1472 | assert(rvalue); | |
1473 | assert(data); | |
1474 | ||
1475 | if (isempty(rvalue)) { | |
a1e58e8e | 1476 | c->smack_process_label = mfree(c->smack_process_label); |
2ca620c4 WC |
1477 | c->smack_process_label_ignore = false; |
1478 | return 0; | |
1479 | } | |
1480 | ||
1481 | if (rvalue[0] == '-') { | |
1482 | ignore = true; | |
1483 | rvalue++; | |
1484 | } else | |
1485 | ignore = false; | |
1486 | ||
18913df9 | 1487 | r = unit_full_printf(u, rvalue, &k); |
2ca620c4 | 1488 | if (r < 0) { |
bb28e684 | 1489 | log_syntax(unit, LOG_ERR, filename, line, r, |
063c4b1a YW |
1490 | "Failed to resolve unit specifiers in '%s'%s: %m", |
1491 | rvalue, ignore ? ", ignoring" : ""); | |
bb28e684 | 1492 | return ignore ? 0 : -ENOEXEC; |
2ca620c4 WC |
1493 | } |
1494 | ||
063c4b1a | 1495 | free_and_replace(c->smack_process_label, k); |
2ca620c4 WC |
1496 | c->smack_process_label_ignore = ignore; |
1497 | ||
1498 | return 0; | |
1499 | } | |
1500 | ||
25a04ae5 LP |
1501 | int config_parse_timer( |
1502 | const char *unit, | |
1503 | const char *filename, | |
1504 | unsigned line, | |
1505 | const char *section, | |
1506 | unsigned section_line, | |
1507 | const char *lvalue, | |
1508 | int ltype, | |
1509 | const char *rvalue, | |
1510 | void *data, | |
1511 | void *userdata) { | |
871d7de4 | 1512 | |
25a04ae5 LP |
1513 | _cleanup_(calendar_spec_freep) CalendarSpec *c = NULL; |
1514 | _cleanup_free_ char *k = NULL; | |
1515 | Unit *u = userdata; | |
871d7de4 | 1516 | Timer *t = data; |
2507992f | 1517 | usec_t usec = 0; |
871d7de4 | 1518 | TimerValue *v; |
2507992f | 1519 | int r; |
871d7de4 LP |
1520 | |
1521 | assert(filename); | |
1522 | assert(lvalue); | |
1523 | assert(rvalue); | |
1524 | assert(data); | |
1525 | ||
74051b9b LP |
1526 | if (isempty(rvalue)) { |
1527 | /* Empty assignment resets list */ | |
1528 | timer_free_values(t); | |
1529 | return 0; | |
1530 | } | |
1531 | ||
2507992f DC |
1532 | r = unit_full_printf(u, rvalue, &k); |
1533 | if (r < 0) { | |
063c4b1a | 1534 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
2507992f DC |
1535 | return 0; |
1536 | } | |
1537 | ||
25a04ae5 | 1538 | if (ltype == TIMER_CALENDAR) { |
dc44c96d LP |
1539 | r = calendar_spec_from_string(k, &c); |
1540 | if (r < 0) { | |
1541 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse calendar specification, ignoring: %s", k); | |
36697dc0 LP |
1542 | return 0; |
1543 | } | |
dc44c96d LP |
1544 | } else { |
1545 | r = parse_sec(k, &usec); | |
1546 | if (r < 0) { | |
1547 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse timer value, ignoring: %s", k); | |
36697dc0 LP |
1548 | return 0; |
1549 | } | |
dc44c96d | 1550 | } |
871d7de4 | 1551 | |
25a04ae5 | 1552 | v = new(TimerValue, 1); |
921b5987 | 1553 | if (!v) |
74051b9b | 1554 | return log_oom(); |
871d7de4 | 1555 | |
25a04ae5 LP |
1556 | *v = (TimerValue) { |
1557 | .base = ltype, | |
1558 | .value = usec, | |
1559 | .calendar_spec = TAKE_PTR(c), | |
1560 | }; | |
871d7de4 | 1561 | |
71fda00f | 1562 | LIST_PREPEND(value, t->values, v); |
871d7de4 LP |
1563 | |
1564 | return 0; | |
1565 | } | |
1566 | ||
3ecaa09b LP |
1567 | int config_parse_trigger_unit( |
1568 | const char *unit, | |
1569 | const char *filename, | |
1570 | unsigned line, | |
1571 | const char *section, | |
71a61510 | 1572 | unsigned section_line, |
3ecaa09b LP |
1573 | const char *lvalue, |
1574 | int ltype, | |
1575 | const char *rvalue, | |
1576 | void *data, | |
1577 | void *userdata) { | |
871d7de4 | 1578 | |
74051b9b | 1579 | _cleanup_free_ char *p = NULL; |
3ecaa09b LP |
1580 | Unit *u = data; |
1581 | UnitType type; | |
1582 | int r; | |
398ef8ba LP |
1583 | |
1584 | assert(filename); | |
1585 | assert(lvalue); | |
1586 | assert(rvalue); | |
1587 | assert(data); | |
1588 | ||
eef85c4a | 1589 | if (!hashmap_isempty(u->dependencies[UNIT_TRIGGERS])) { |
12ca818f | 1590 | log_syntax(unit, LOG_ERR, filename, line, 0, "Multiple units to trigger specified, ignoring: %s", rvalue); |
3ecaa09b LP |
1591 | return 0; |
1592 | } | |
871d7de4 | 1593 | |
19f6d710 | 1594 | r = unit_name_printf(u, rvalue, &p); |
12ca818f | 1595 | if (r < 0) { |
063c4b1a | 1596 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue); |
12ca818f LP |
1597 | return 0; |
1598 | } | |
74051b9b | 1599 | |
12ca818f | 1600 | type = unit_name_to_type(p); |
3ecaa09b | 1601 | if (type < 0) { |
12ca818f | 1602 | log_syntax(unit, LOG_ERR, filename, line, 0, "Unit type not valid, ignoring: %s", rvalue); |
c0b34696 | 1603 | return 0; |
871d7de4 | 1604 | } |
49219a1c JR |
1605 | if (unit_has_name(u, p)) { |
1606 | log_syntax(unit, LOG_ERR, filename, line, 0, "Units cannot trigger themselves, ignoring: %s", rvalue); | |
3ecaa09b LP |
1607 | return 0; |
1608 | } | |
1609 | ||
5a724170 | 1610 | r = unit_add_two_dependencies_by_name(u, UNIT_BEFORE, UNIT_TRIGGERS, p, true, UNIT_DEPENDENCY_FILE); |
57020a3a | 1611 | if (r < 0) { |
12ca818f | 1612 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to add trigger on %s, ignoring: %m", p); |
c0b34696 | 1613 | return 0; |
871d7de4 LP |
1614 | } |
1615 | ||
1616 | return 0; | |
1617 | } | |
1618 | ||
e8e581bf ZJS |
1619 | int config_parse_path_spec(const char *unit, |
1620 | const char *filename, | |
1621 | unsigned line, | |
1622 | const char *section, | |
71a61510 | 1623 | unsigned section_line, |
e8e581bf ZJS |
1624 | const char *lvalue, |
1625 | int ltype, | |
1626 | const char *rvalue, | |
1627 | void *data, | |
1628 | void *userdata) { | |
01f78473 LP |
1629 | |
1630 | Path *p = data; | |
1631 | PathSpec *s; | |
1632 | PathType b; | |
7fd1b19b | 1633 | _cleanup_free_ char *k = NULL; |
19f6d710 | 1634 | int r; |
01f78473 LP |
1635 | |
1636 | assert(filename); | |
1637 | assert(lvalue); | |
1638 | assert(rvalue); | |
1639 | assert(data); | |
1640 | ||
74051b9b LP |
1641 | if (isempty(rvalue)) { |
1642 | /* Empty assignment clears list */ | |
1643 | path_free_specs(p); | |
1644 | return 0; | |
1645 | } | |
1646 | ||
93e4c84b LP |
1647 | b = path_type_from_string(lvalue); |
1648 | if (b < 0) { | |
12ca818f | 1649 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse path type, ignoring: %s", lvalue); |
c0b34696 | 1650 | return 0; |
01f78473 LP |
1651 | } |
1652 | ||
19f6d710 LP |
1653 | r = unit_full_printf(UNIT(p), rvalue, &k); |
1654 | if (r < 0) { | |
063c4b1a | 1655 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue); |
12ca818f | 1656 | return 0; |
487060c2 | 1657 | } |
93e4c84b | 1658 | |
2f4d31c1 YW |
1659 | r = path_simplify_and_warn(k, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
1660 | if (r < 0) | |
c0b34696 | 1661 | return 0; |
01f78473 | 1662 | |
93e4c84b | 1663 | s = new0(PathSpec, 1); |
543295ad | 1664 | if (!s) |
93e4c84b | 1665 | return log_oom(); |
01f78473 | 1666 | |
718db961 | 1667 | s->unit = UNIT(p); |
063c4b1a | 1668 | s->path = TAKE_PTR(k); |
01f78473 LP |
1669 | s->type = b; |
1670 | s->inotify_fd = -1; | |
1671 | ||
71fda00f | 1672 | LIST_PREPEND(spec, p->specs, s); |
01f78473 LP |
1673 | |
1674 | return 0; | |
1675 | } | |
1676 | ||
b02cb41c LP |
1677 | int config_parse_socket_service( |
1678 | const char *unit, | |
1679 | const char *filename, | |
1680 | unsigned line, | |
1681 | const char *section, | |
1682 | unsigned section_line, | |
1683 | const char *lvalue, | |
1684 | int ltype, | |
1685 | const char *rvalue, | |
1686 | void *data, | |
1687 | void *userdata) { | |
d9ff321a | 1688 | |
4afd3348 | 1689 | _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; |
8dd4c05b | 1690 | _cleanup_free_ char *p = NULL; |
d9ff321a | 1691 | Socket *s = data; |
4ff77f66 | 1692 | Unit *x; |
8dd4c05b | 1693 | int r; |
d9ff321a LP |
1694 | |
1695 | assert(filename); | |
1696 | assert(lvalue); | |
1697 | assert(rvalue); | |
1698 | assert(data); | |
1699 | ||
19f6d710 | 1700 | r = unit_name_printf(UNIT(s), rvalue, &p); |
613b411c | 1701 | if (r < 0) { |
063c4b1a | 1702 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s: %m", rvalue); |
bb28e684 | 1703 | return -ENOEXEC; |
613b411c | 1704 | } |
74051b9b | 1705 | |
613b411c | 1706 | if (!endswith(p, ".service")) { |
bb28e684 ZJS |
1707 | log_syntax(unit, LOG_ERR, filename, line, 0, "Unit must be of type service: %s", rvalue); |
1708 | return -ENOEXEC; | |
d9ff321a LP |
1709 | } |
1710 | ||
613b411c | 1711 | r = manager_load_unit(UNIT(s)->manager, p, NULL, &error, &x); |
4ff77f66 | 1712 | if (r < 0) { |
bb28e684 ZJS |
1713 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to load unit %s: %s", rvalue, bus_error_message(&error, r)); |
1714 | return -ENOEXEC; | |
d9ff321a LP |
1715 | } |
1716 | ||
7f7d01ed | 1717 | unit_ref_set(&s->service, UNIT(s), x); |
4ff77f66 | 1718 | |
d9ff321a LP |
1719 | return 0; |
1720 | } | |
1721 | ||
8dd4c05b LP |
1722 | int config_parse_fdname( |
1723 | const char *unit, | |
1724 | const char *filename, | |
1725 | unsigned line, | |
1726 | const char *section, | |
1727 | unsigned section_line, | |
1728 | const char *lvalue, | |
1729 | int ltype, | |
1730 | const char *rvalue, | |
1731 | void *data, | |
1732 | void *userdata) { | |
1733 | ||
1734 | _cleanup_free_ char *p = NULL; | |
1735 | Socket *s = data; | |
1736 | int r; | |
1737 | ||
1738 | assert(filename); | |
1739 | assert(lvalue); | |
1740 | assert(rvalue); | |
1741 | assert(data); | |
1742 | ||
1743 | if (isempty(rvalue)) { | |
1744 | s->fdname = mfree(s->fdname); | |
1745 | return 0; | |
1746 | } | |
1747 | ||
18913df9 | 1748 | r = unit_full_printf(UNIT(s), rvalue, &p); |
8dd4c05b | 1749 | if (r < 0) { |
063c4b1a | 1750 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
8dd4c05b LP |
1751 | return 0; |
1752 | } | |
1753 | ||
1754 | if (!fdname_is_valid(p)) { | |
1755 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid file descriptor name, ignoring: %s", p); | |
1756 | return 0; | |
1757 | } | |
1758 | ||
3b319885 | 1759 | return free_and_replace(s->fdname, p); |
8dd4c05b LP |
1760 | } |
1761 | ||
b02cb41c LP |
1762 | int config_parse_service_sockets( |
1763 | const char *unit, | |
1764 | const char *filename, | |
1765 | unsigned line, | |
1766 | const char *section, | |
1767 | unsigned section_line, | |
1768 | const char *lvalue, | |
1769 | int ltype, | |
1770 | const char *rvalue, | |
1771 | void *data, | |
1772 | void *userdata) { | |
f976f3f6 LP |
1773 | |
1774 | Service *s = data; | |
7b2313f5 | 1775 | const char *p; |
b02cb41c | 1776 | int r; |
f976f3f6 LP |
1777 | |
1778 | assert(filename); | |
1779 | assert(lvalue); | |
1780 | assert(rvalue); | |
1781 | assert(data); | |
1782 | ||
7b2313f5 | 1783 | p = rvalue; |
9ed794a3 | 1784 | for (;;) { |
6a0f3175 | 1785 | _cleanup_free_ char *word = NULL, *k = NULL; |
f976f3f6 | 1786 | |
7b2313f5 SS |
1787 | r = extract_first_word(&p, &word, NULL, 0); |
1788 | if (r == 0) | |
1789 | break; | |
1790 | if (r == -ENOMEM) | |
74051b9b | 1791 | return log_oom(); |
7b2313f5 SS |
1792 | if (r < 0) { |
1793 | log_syntax(unit, LOG_ERR, filename, line, r, "Trailing garbage in sockets, ignoring: %s", rvalue); | |
1794 | break; | |
1795 | } | |
f976f3f6 | 1796 | |
7b2313f5 | 1797 | r = unit_name_printf(UNIT(s), word, &k); |
b02cb41c | 1798 | if (r < 0) { |
063c4b1a | 1799 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", word); |
b02cb41c LP |
1800 | continue; |
1801 | } | |
57020a3a | 1802 | |
b02cb41c | 1803 | if (!endswith(k, ".socket")) { |
12ca818f | 1804 | log_syntax(unit, LOG_ERR, filename, line, 0, "Unit must be of type socket, ignoring: %s", k); |
f976f3f6 LP |
1805 | continue; |
1806 | } | |
1807 | ||
5a724170 | 1808 | r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_WANTS, UNIT_AFTER, k, true, UNIT_DEPENDENCY_FILE); |
57020a3a | 1809 | if (r < 0) |
b02cb41c | 1810 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to add dependency on %s, ignoring: %m", k); |
f976f3f6 | 1811 | |
35d8c19a | 1812 | r = unit_add_dependency_by_name(UNIT(s), UNIT_TRIGGERED_BY, k, true, UNIT_DEPENDENCY_FILE); |
57020a3a | 1813 | if (r < 0) |
b02cb41c | 1814 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to add dependency on %s, ignoring: %m", k); |
f976f3f6 LP |
1815 | } |
1816 | ||
1817 | return 0; | |
1818 | } | |
1819 | ||
b02cb41c LP |
1820 | int config_parse_bus_name( |
1821 | const char *unit, | |
1822 | const char *filename, | |
1823 | unsigned line, | |
1824 | const char *section, | |
1825 | unsigned section_line, | |
1826 | const char *lvalue, | |
1827 | int ltype, | |
1828 | const char *rvalue, | |
1829 | void *data, | |
1830 | void *userdata) { | |
1831 | ||
1832 | _cleanup_free_ char *k = NULL; | |
1833 | Unit *u = userdata; | |
1834 | int r; | |
1835 | ||
1836 | assert(filename); | |
1837 | assert(lvalue); | |
1838 | assert(rvalue); | |
1839 | assert(u); | |
1840 | ||
1841 | r = unit_full_printf(u, rvalue, &k); | |
1842 | if (r < 0) { | |
063c4b1a | 1843 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue); |
b02cb41c LP |
1844 | return 0; |
1845 | } | |
1846 | ||
1847 | if (!service_name_is_valid(k)) { | |
063c4b1a | 1848 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid bus name, ignoring: %s", k); |
b02cb41c LP |
1849 | return 0; |
1850 | } | |
1851 | ||
1852 | return config_parse_string(unit, filename, line, section, section_line, lvalue, ltype, k, data, userdata); | |
1853 | } | |
1854 | ||
aad41f08 LP |
1855 | int config_parse_service_timeout( |
1856 | const char *unit, | |
1857 | const char *filename, | |
1858 | unsigned line, | |
1859 | const char *section, | |
1860 | unsigned section_line, | |
1861 | const char *lvalue, | |
1862 | int ltype, | |
1863 | const char *rvalue, | |
1864 | void *data, | |
1865 | void *userdata) { | |
98709151 LN |
1866 | |
1867 | Service *s = userdata; | |
aad41f08 | 1868 | usec_t usec; |
98709151 LN |
1869 | int r; |
1870 | ||
1871 | assert(filename); | |
1872 | assert(lvalue); | |
1873 | assert(rvalue); | |
1874 | assert(s); | |
1875 | ||
6c58305a | 1876 | /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */ |
98709151 | 1877 | |
fb27be3f YW |
1878 | /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens |
1879 | * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle | |
1880 | * all other timeouts. */ | |
1881 | r = parse_sec_fix_0(rvalue, &usec); | |
aad41f08 LP |
1882 | if (r < 0) { |
1883 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse %s= parameter, ignoring: %s", lvalue, rvalue); | |
1884 | return 0; | |
1885 | } | |
d568a335 | 1886 | |
6c58305a YW |
1887 | s->start_timeout_defined = true; |
1888 | s->timeout_start_usec = usec; | |
36c16a7c | 1889 | |
6c58305a | 1890 | if (streq(lvalue, "TimeoutSec")) |
aad41f08 | 1891 | s->timeout_stop_usec = usec; |
36c16a7c | 1892 | |
d568a335 | 1893 | return 0; |
98709151 LN |
1894 | } |
1895 | ||
dc653bf4 JK |
1896 | int config_parse_service_timeout_abort( |
1897 | const char *unit, | |
1898 | const char *filename, | |
1899 | unsigned line, | |
1900 | const char *section, | |
1901 | unsigned section_line, | |
1902 | const char *lvalue, | |
1903 | int ltype, | |
1904 | const char *rvalue, | |
1905 | void *data, | |
1906 | void *userdata) { | |
1907 | ||
1908 | Service *s = userdata; | |
1909 | int r; | |
1910 | ||
1911 | assert(filename); | |
1912 | assert(lvalue); | |
1913 | assert(rvalue); | |
1914 | assert(s); | |
1915 | ||
1916 | rvalue += strspn(rvalue, WHITESPACE); | |
1917 | if (isempty(rvalue)) { | |
1918 | s->timeout_abort_set = false; | |
1919 | return 0; | |
1920 | } | |
1921 | ||
1922 | r = parse_sec(rvalue, &s->timeout_abort_usec); | |
1923 | if (r < 0) { | |
1924 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse TimeoutAbortSec= setting, ignoring: %s", rvalue); | |
1925 | return 0; | |
1926 | } | |
1927 | ||
1928 | s->timeout_abort_set = true; | |
1929 | return 0; | |
1930 | } | |
1931 | ||
89beff89 LP |
1932 | int config_parse_sec_fix_0( |
1933 | const char *unit, | |
1934 | const char *filename, | |
1935 | unsigned line, | |
1936 | const char *section, | |
1937 | unsigned section_line, | |
1938 | const char *lvalue, | |
1939 | int ltype, | |
1940 | const char *rvalue, | |
1941 | void *data, | |
1942 | void *userdata) { | |
1943 | ||
1944 | usec_t *usec = data; | |
1945 | int r; | |
1946 | ||
1947 | assert(filename); | |
1948 | assert(lvalue); | |
1949 | assert(rvalue); | |
1950 | assert(usec); | |
1951 | ||
1952 | /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for | |
1953 | * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a | |
1954 | * timeout. */ | |
1955 | ||
0004f698 | 1956 | r = parse_sec_fix_0(rvalue, usec); |
89beff89 LP |
1957 | if (r < 0) { |
1958 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse %s= parameter, ignoring: %s", lvalue, rvalue); | |
1959 | return 0; | |
1960 | } | |
1961 | ||
89beff89 LP |
1962 | return 0; |
1963 | } | |
1964 | ||
66dccd8d LP |
1965 | int config_parse_user_group( |
1966 | const char *unit, | |
1967 | const char *filename, | |
1968 | unsigned line, | |
1969 | const char *section, | |
1970 | unsigned section_line, | |
1971 | const char *lvalue, | |
1972 | int ltype, | |
1973 | const char *rvalue, | |
1974 | void *data, | |
1975 | void *userdata) { | |
1976 | ||
063c4b1a YW |
1977 | _cleanup_free_ char *k = NULL; |
1978 | char **user = data; | |
66dccd8d LP |
1979 | Unit *u = userdata; |
1980 | int r; | |
1981 | ||
1982 | assert(filename); | |
1983 | assert(lvalue); | |
1984 | assert(rvalue); | |
1985 | assert(u); | |
1986 | ||
063c4b1a YW |
1987 | if (isempty(rvalue)) { |
1988 | *user = mfree(*user); | |
1989 | return 0; | |
1990 | } | |
66dccd8d | 1991 | |
063c4b1a YW |
1992 | r = unit_full_printf(u, rvalue, &k); |
1993 | if (r < 0) { | |
1994 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s: %m", rvalue); | |
1995 | return -ENOEXEC; | |
66dccd8d LP |
1996 | } |
1997 | ||
063c4b1a YW |
1998 | if (!valid_user_group_name_or_id(k)) { |
1999 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid user/group name or numeric ID: %s", k); | |
2000 | return -ENOEXEC; | |
2001 | } | |
66dccd8d | 2002 | |
063c4b1a | 2003 | return free_and_replace(*user, k); |
66dccd8d LP |
2004 | } |
2005 | ||
2006 | int config_parse_user_group_strv( | |
2007 | const char *unit, | |
2008 | const char *filename, | |
2009 | unsigned line, | |
2010 | const char *section, | |
2011 | unsigned section_line, | |
2012 | const char *lvalue, | |
2013 | int ltype, | |
2014 | const char *rvalue, | |
2015 | void *data, | |
2016 | void *userdata) { | |
2017 | ||
2018 | char ***users = data; | |
2019 | Unit *u = userdata; | |
063c4b1a | 2020 | const char *p = rvalue; |
66dccd8d LP |
2021 | int r; |
2022 | ||
2023 | assert(filename); | |
2024 | assert(lvalue); | |
2025 | assert(rvalue); | |
2026 | assert(u); | |
2027 | ||
2028 | if (isempty(rvalue)) { | |
9f2d41a6 | 2029 | *users = strv_free(*users); |
66dccd8d LP |
2030 | return 0; |
2031 | } | |
2032 | ||
66dccd8d LP |
2033 | for (;;) { |
2034 | _cleanup_free_ char *word = NULL, *k = NULL; | |
2035 | ||
9a82ab95 | 2036 | r = extract_first_word(&p, &word, NULL, 0); |
66dccd8d LP |
2037 | if (r == 0) |
2038 | break; | |
2039 | if (r == -ENOMEM) | |
2040 | return log_oom(); | |
2041 | if (r < 0) { | |
bb28e684 ZJS |
2042 | log_syntax(unit, LOG_ERR, filename, line, r, "Invalid syntax: %s", rvalue); |
2043 | return -ENOEXEC; | |
66dccd8d LP |
2044 | } |
2045 | ||
2046 | r = unit_full_printf(u, word, &k); | |
2047 | if (r < 0) { | |
bb28e684 ZJS |
2048 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s: %m", word); |
2049 | return -ENOEXEC; | |
66dccd8d LP |
2050 | } |
2051 | ||
2052 | if (!valid_user_group_name_or_id(k)) { | |
bb28e684 ZJS |
2053 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid user/group name or numeric ID: %s", k); |
2054 | return -ENOEXEC; | |
66dccd8d LP |
2055 | } |
2056 | ||
2057 | r = strv_push(users, k); | |
2058 | if (r < 0) | |
2059 | return log_oom(); | |
2060 | ||
2061 | k = NULL; | |
2062 | } | |
2063 | ||
2064 | return 0; | |
2065 | } | |
2066 | ||
5f5d8eab LP |
2067 | int config_parse_working_directory( |
2068 | const char *unit, | |
2069 | const char *filename, | |
2070 | unsigned line, | |
2071 | const char *section, | |
2072 | unsigned section_line, | |
2073 | const char *lvalue, | |
2074 | int ltype, | |
2075 | const char *rvalue, | |
2076 | void *data, | |
2077 | void *userdata) { | |
2078 | ||
2079 | ExecContext *c = data; | |
2080 | Unit *u = userdata; | |
2081 | bool missing_ok; | |
2082 | int r; | |
2083 | ||
2084 | assert(filename); | |
2085 | assert(lvalue); | |
2086 | assert(rvalue); | |
2087 | assert(c); | |
2088 | assert(u); | |
2089 | ||
862fcffd YW |
2090 | if (isempty(rvalue)) { |
2091 | c->working_directory_home = false; | |
2092 | c->working_directory = mfree(c->working_directory); | |
2093 | return 0; | |
2094 | } | |
2095 | ||
5f5d8eab LP |
2096 | if (rvalue[0] == '-') { |
2097 | missing_ok = true; | |
2098 | rvalue++; | |
2099 | } else | |
2100 | missing_ok = false; | |
2101 | ||
2102 | if (streq(rvalue, "~")) { | |
2103 | c->working_directory_home = true; | |
2104 | c->working_directory = mfree(c->working_directory); | |
2105 | } else { | |
2106 | _cleanup_free_ char *k = NULL; | |
2107 | ||
2108 | r = unit_full_printf(u, rvalue, &k); | |
2109 | if (r < 0) { | |
bb28e684 ZJS |
2110 | log_syntax(unit, LOG_ERR, filename, line, r, |
2111 | "Failed to resolve unit specifiers in working directory path '%s'%s: %m", | |
2112 | rvalue, missing_ok ? ", ignoring" : ""); | |
2113 | return missing_ok ? 0 : -ENOEXEC; | |
5f5d8eab LP |
2114 | } |
2115 | ||
2f4d31c1 YW |
2116 | r = path_simplify_and_warn(k, PATH_CHECK_ABSOLUTE | (missing_ok ? 0 : PATH_CHECK_FATAL), unit, filename, line, lvalue); |
2117 | if (r < 0) | |
bb28e684 | 2118 | return missing_ok ? 0 : -ENOEXEC; |
5f5d8eab | 2119 | |
5f5d8eab | 2120 | c->working_directory_home = false; |
bb28e684 | 2121 | free_and_replace(c->working_directory, k); |
5f5d8eab LP |
2122 | } |
2123 | ||
2124 | c->working_directory_missing_ok = missing_ok; | |
2125 | return 0; | |
2126 | } | |
2127 | ||
e8e581bf ZJS |
2128 | int config_parse_unit_env_file(const char *unit, |
2129 | const char *filename, | |
2130 | unsigned line, | |
2131 | const char *section, | |
71a61510 | 2132 | unsigned section_line, |
e8e581bf ZJS |
2133 | const char *lvalue, |
2134 | int ltype, | |
2135 | const char *rvalue, | |
2136 | void *data, | |
2137 | void *userdata) { | |
ddb26e18 | 2138 | |
853b8397 | 2139 | char ***env = data; |
8fef7659 | 2140 | Unit *u = userdata; |
19f6d710 | 2141 | _cleanup_free_ char *n = NULL; |
853b8397 | 2142 | int r; |
ddb26e18 LP |
2143 | |
2144 | assert(filename); | |
2145 | assert(lvalue); | |
2146 | assert(rvalue); | |
2147 | assert(data); | |
2148 | ||
74051b9b LP |
2149 | if (isempty(rvalue)) { |
2150 | /* Empty assignment frees the list */ | |
6796073e | 2151 | *env = strv_free(*env); |
74051b9b LP |
2152 | return 0; |
2153 | } | |
2154 | ||
19f6d710 | 2155 | r = unit_full_printf(u, rvalue, &n); |
12ca818f | 2156 | if (r < 0) { |
063c4b1a | 2157 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
12ca818f LP |
2158 | return 0; |
2159 | } | |
8fef7659 | 2160 | |
2f4d31c1 YW |
2161 | r = path_simplify_and_warn(n[0] == '-' ? n + 1 : n, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
2162 | if (r < 0) | |
afe4bfe2 | 2163 | return 0; |
afe4bfe2 | 2164 | |
2f4d31c1 | 2165 | r = strv_push(env, n); |
853b8397 LP |
2166 | if (r < 0) |
2167 | return log_oom(); | |
2168 | ||
2f4d31c1 YW |
2169 | n = NULL; |
2170 | ||
853b8397 LP |
2171 | return 0; |
2172 | } | |
2173 | ||
f7f3f5c3 LP |
2174 | int config_parse_environ( |
2175 | const char *unit, | |
2176 | const char *filename, | |
2177 | unsigned line, | |
2178 | const char *section, | |
2179 | unsigned section_line, | |
2180 | const char *lvalue, | |
2181 | int ltype, | |
2182 | const char *rvalue, | |
2183 | void *data, | |
2184 | void *userdata) { | |
853b8397 LP |
2185 | |
2186 | Unit *u = userdata; | |
035fe294 ZJS |
2187 | char ***env = data; |
2188 | const char *p; | |
19f6d710 | 2189 | int r; |
853b8397 LP |
2190 | |
2191 | assert(filename); | |
2192 | assert(lvalue); | |
2193 | assert(rvalue); | |
97d0e5f8 | 2194 | assert(data); |
853b8397 LP |
2195 | |
2196 | if (isempty(rvalue)) { | |
2197 | /* Empty assignment resets the list */ | |
6796073e | 2198 | *env = strv_free(*env); |
853b8397 LP |
2199 | return 0; |
2200 | } | |
2201 | ||
035fe294 ZJS |
2202 | for (p = rvalue;; ) { |
2203 | _cleanup_free_ char *word = NULL, *k = NULL; | |
035fe294 ZJS |
2204 | |
2205 | r = extract_first_word(&p, &word, NULL, EXTRACT_CUNESCAPE|EXTRACT_QUOTES); | |
2206 | if (r == 0) | |
2207 | return 0; | |
2208 | if (r == -ENOMEM) | |
2209 | return log_oom(); | |
12ca818f | 2210 | if (r < 0) { |
035fe294 ZJS |
2211 | log_syntax(unit, LOG_WARNING, filename, line, r, |
2212 | "Invalid syntax, ignoring: %s", rvalue); | |
12ca818f LP |
2213 | return 0; |
2214 | } | |
97d0e5f8 | 2215 | |
035fe294 ZJS |
2216 | if (u) { |
2217 | r = unit_full_printf(u, word, &k); | |
2218 | if (r < 0) { | |
2219 | log_syntax(unit, LOG_ERR, filename, line, r, | |
063c4b1a | 2220 | "Failed to resolve unit specifiers in %s, ignoring: %m", word); |
035fe294 ZJS |
2221 | continue; |
2222 | } | |
ae2a15bc LP |
2223 | } else |
2224 | k = TAKE_PTR(word); | |
853b8397 | 2225 | |
035fe294 ZJS |
2226 | if (!env_assignment_is_valid(k)) { |
2227 | log_syntax(unit, LOG_ERR, filename, line, 0, | |
2228 | "Invalid environment assignment, ignoring: %s", k); | |
853b8397 LP |
2229 | continue; |
2230 | } | |
2231 | ||
54ac3494 ZJS |
2232 | r = strv_env_replace(env, k); |
2233 | if (r < 0) | |
853b8397 | 2234 | return log_oom(); |
f7f3f5c3 | 2235 | |
54ac3494 | 2236 | k = NULL; |
853b8397 | 2237 | } |
ddb26e18 LP |
2238 | } |
2239 | ||
00819cc1 LP |
2240 | int config_parse_pass_environ( |
2241 | const char *unit, | |
2242 | const char *filename, | |
2243 | unsigned line, | |
2244 | const char *section, | |
2245 | unsigned section_line, | |
2246 | const char *lvalue, | |
2247 | int ltype, | |
2248 | const char *rvalue, | |
2249 | void *data, | |
2250 | void *userdata) { | |
b4c14404 | 2251 | |
b4c14404 FB |
2252 | _cleanup_strv_free_ char **n = NULL; |
2253 | size_t nlen = 0, nbufsize = 0; | |
41de9cc2 | 2254 | char*** passenv = data; |
063c4b1a | 2255 | const char *p = rvalue; |
41de9cc2 | 2256 | Unit *u = userdata; |
b4c14404 FB |
2257 | int r; |
2258 | ||
2259 | assert(filename); | |
2260 | assert(lvalue); | |
2261 | assert(rvalue); | |
2262 | assert(data); | |
2263 | ||
2264 | if (isempty(rvalue)) { | |
2265 | /* Empty assignment resets the list */ | |
2266 | *passenv = strv_free(*passenv); | |
2267 | return 0; | |
2268 | } | |
2269 | ||
2270 | for (;;) { | |
41de9cc2 | 2271 | _cleanup_free_ char *word = NULL, *k = NULL; |
b4c14404 | 2272 | |
063c4b1a | 2273 | r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES); |
b4c14404 FB |
2274 | if (r == 0) |
2275 | break; | |
2276 | if (r == -ENOMEM) | |
2277 | return log_oom(); | |
2278 | if (r < 0) { | |
2279 | log_syntax(unit, LOG_ERR, filename, line, r, | |
063c4b1a | 2280 | "Trailing garbage in %s, ignoring: %s", lvalue, rvalue); |
b4c14404 FB |
2281 | break; |
2282 | } | |
2283 | ||
41de9cc2 LP |
2284 | if (u) { |
2285 | r = unit_full_printf(u, word, &k); | |
2286 | if (r < 0) { | |
2287 | log_syntax(unit, LOG_ERR, filename, line, r, | |
063c4b1a | 2288 | "Failed to resolve specifiers in %s, ignoring: %m", word); |
41de9cc2 LP |
2289 | continue; |
2290 | } | |
ae2a15bc LP |
2291 | } else |
2292 | k = TAKE_PTR(word); | |
41de9cc2 LP |
2293 | |
2294 | if (!env_name_is_valid(k)) { | |
2295 | log_syntax(unit, LOG_ERR, filename, line, 0, | |
2296 | "Invalid environment name for %s, ignoring: %s", lvalue, k); | |
b4c14404 FB |
2297 | continue; |
2298 | } | |
2299 | ||
2300 | if (!GREEDY_REALLOC(n, nbufsize, nlen + 2)) | |
2301 | return log_oom(); | |
41de9cc2 | 2302 | |
1cc6c93a | 2303 | n[nlen++] = TAKE_PTR(k); |
b4c14404 | 2304 | n[nlen] = NULL; |
b4c14404 FB |
2305 | } |
2306 | ||
2307 | if (n) { | |
2308 | r = strv_extend_strv(passenv, n, true); | |
2309 | if (r < 0) | |
2310 | return r; | |
2311 | } | |
2312 | ||
2313 | return 0; | |
2314 | } | |
2315 | ||
00819cc1 LP |
2316 | int config_parse_unset_environ( |
2317 | const char *unit, | |
2318 | const char *filename, | |
2319 | unsigned line, | |
2320 | const char *section, | |
2321 | unsigned section_line, | |
2322 | const char *lvalue, | |
2323 | int ltype, | |
2324 | const char *rvalue, | |
2325 | void *data, | |
2326 | void *userdata) { | |
2327 | ||
2328 | _cleanup_strv_free_ char **n = NULL; | |
00819cc1 LP |
2329 | size_t nlen = 0, nbufsize = 0; |
2330 | char*** unsetenv = data; | |
063c4b1a | 2331 | const char *p = rvalue; |
00819cc1 LP |
2332 | Unit *u = userdata; |
2333 | int r; | |
2334 | ||
2335 | assert(filename); | |
2336 | assert(lvalue); | |
2337 | assert(rvalue); | |
2338 | assert(data); | |
2339 | ||
2340 | if (isempty(rvalue)) { | |
2341 | /* Empty assignment resets the list */ | |
2342 | *unsetenv = strv_free(*unsetenv); | |
2343 | return 0; | |
2344 | } | |
2345 | ||
2346 | for (;;) { | |
2347 | _cleanup_free_ char *word = NULL, *k = NULL; | |
2348 | ||
063c4b1a | 2349 | r = extract_first_word(&p, &word, NULL, EXTRACT_CUNESCAPE|EXTRACT_QUOTES); |
00819cc1 LP |
2350 | if (r == 0) |
2351 | break; | |
2352 | if (r == -ENOMEM) | |
2353 | return log_oom(); | |
2354 | if (r < 0) { | |
2355 | log_syntax(unit, LOG_ERR, filename, line, r, | |
063c4b1a | 2356 | "Trailing garbage in %s, ignoring: %s", lvalue, rvalue); |
00819cc1 LP |
2357 | break; |
2358 | } | |
2359 | ||
2360 | if (u) { | |
2361 | r = unit_full_printf(u, word, &k); | |
2362 | if (r < 0) { | |
2363 | log_syntax(unit, LOG_ERR, filename, line, r, | |
063c4b1a | 2364 | "Failed to resolve unit specifiers in %s, ignoring: %m", word); |
00819cc1 LP |
2365 | continue; |
2366 | } | |
ae2a15bc LP |
2367 | } else |
2368 | k = TAKE_PTR(word); | |
00819cc1 LP |
2369 | |
2370 | if (!env_assignment_is_valid(k) && !env_name_is_valid(k)) { | |
2371 | log_syntax(unit, LOG_ERR, filename, line, 0, | |
2372 | "Invalid environment name or assignment %s, ignoring: %s", lvalue, k); | |
2373 | continue; | |
2374 | } | |
2375 | ||
2376 | if (!GREEDY_REALLOC(n, nbufsize, nlen + 2)) | |
2377 | return log_oom(); | |
2378 | ||
1cc6c93a | 2379 | n[nlen++] = TAKE_PTR(k); |
00819cc1 | 2380 | n[nlen] = NULL; |
00819cc1 LP |
2381 | } |
2382 | ||
2383 | if (n) { | |
2384 | r = strv_extend_strv(unsetenv, n, true); | |
2385 | if (r < 0) | |
2386 | return r; | |
2387 | } | |
2388 | ||
2389 | return 0; | |
2390 | } | |
2391 | ||
d3070fbd LP |
2392 | int config_parse_log_extra_fields( |
2393 | const char *unit, | |
2394 | const char *filename, | |
2395 | unsigned line, | |
2396 | const char *section, | |
2397 | unsigned section_line, | |
2398 | const char *lvalue, | |
2399 | int ltype, | |
2400 | const char *rvalue, | |
2401 | void *data, | |
2402 | void *userdata) { | |
2403 | ||
2404 | ExecContext *c = data; | |
2405 | Unit *u = userdata; | |
063c4b1a | 2406 | const char *p = rvalue; |
d3070fbd LP |
2407 | int r; |
2408 | ||
2409 | assert(filename); | |
2410 | assert(lvalue); | |
2411 | assert(rvalue); | |
2412 | assert(c); | |
2413 | ||
2414 | if (isempty(rvalue)) { | |
2415 | exec_context_free_log_extra_fields(c); | |
2416 | return 0; | |
2417 | } | |
2418 | ||
063c4b1a | 2419 | for (;;) { |
d3070fbd LP |
2420 | _cleanup_free_ char *word = NULL, *k = NULL; |
2421 | struct iovec *t; | |
2422 | const char *eq; | |
2423 | ||
2424 | r = extract_first_word(&p, &word, NULL, EXTRACT_CUNESCAPE|EXTRACT_QUOTES); | |
2425 | if (r == 0) | |
063c4b1a | 2426 | return 0; |
d3070fbd LP |
2427 | if (r == -ENOMEM) |
2428 | return log_oom(); | |
2429 | if (r < 0) { | |
2430 | log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue); | |
2431 | return 0; | |
2432 | } | |
2433 | ||
2434 | r = unit_full_printf(u, word, &k); | |
2435 | if (r < 0) { | |
063c4b1a | 2436 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", word); |
d3070fbd LP |
2437 | continue; |
2438 | } | |
2439 | ||
2440 | eq = strchr(k, '='); | |
2441 | if (!eq) { | |
063c4b1a | 2442 | log_syntax(unit, LOG_ERR, filename, line, 0, "Log field lacks '=' character, ignoring: %s", k); |
d3070fbd LP |
2443 | continue; |
2444 | } | |
2445 | ||
2446 | if (!journal_field_valid(k, eq-k, false)) { | |
063c4b1a | 2447 | log_syntax(unit, LOG_ERR, filename, line, 0, "Log field name is invalid, ignoring: %s", k); |
d3070fbd LP |
2448 | continue; |
2449 | } | |
2450 | ||
aa484f35 | 2451 | t = reallocarray(c->log_extra_fields, c->n_log_extra_fields+1, sizeof(struct iovec)); |
d3070fbd LP |
2452 | if (!t) |
2453 | return log_oom(); | |
2454 | ||
2455 | c->log_extra_fields = t; | |
2456 | c->log_extra_fields[c->n_log_extra_fields++] = IOVEC_MAKE_STRING(k); | |
2457 | ||
2458 | k = NULL; | |
2459 | } | |
d3070fbd LP |
2460 | } |
2461 | ||
59fccdc5 LP |
2462 | int config_parse_unit_condition_path( |
2463 | const char *unit, | |
2464 | const char *filename, | |
2465 | unsigned line, | |
2466 | const char *section, | |
2467 | unsigned section_line, | |
2468 | const char *lvalue, | |
2469 | int ltype, | |
2470 | const char *rvalue, | |
2471 | void *data, | |
2472 | void *userdata) { | |
52661efd | 2473 | |
2fbe635a | 2474 | _cleanup_free_ char *p = NULL; |
59fccdc5 LP |
2475 | Condition **list = data, *c; |
2476 | ConditionType t = ltype; | |
2477 | bool trigger, negate; | |
2478 | Unit *u = userdata; | |
19f6d710 | 2479 | int r; |
52661efd LP |
2480 | |
2481 | assert(filename); | |
2482 | assert(lvalue); | |
2483 | assert(rvalue); | |
2484 | assert(data); | |
2485 | ||
74051b9b LP |
2486 | if (isempty(rvalue)) { |
2487 | /* Empty assignment resets the list */ | |
447021aa | 2488 | *list = condition_free_list(*list); |
74051b9b LP |
2489 | return 0; |
2490 | } | |
2491 | ||
ab7f148f LP |
2492 | trigger = rvalue[0] == '|'; |
2493 | if (trigger) | |
267632f0 LP |
2494 | rvalue++; |
2495 | ||
ab7f148f LP |
2496 | negate = rvalue[0] == '!'; |
2497 | if (negate) | |
52661efd LP |
2498 | rvalue++; |
2499 | ||
19f6d710 | 2500 | r = unit_full_printf(u, rvalue, &p); |
59fccdc5 | 2501 | if (r < 0) { |
063c4b1a | 2502 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue); |
59fccdc5 | 2503 | return 0; |
19f6d710 | 2504 | } |
095b2d7a | 2505 | |
2f4d31c1 YW |
2506 | r = path_simplify_and_warn(p, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
2507 | if (r < 0) | |
52661efd | 2508 | return 0; |
52661efd | 2509 | |
59fccdc5 | 2510 | c = condition_new(t, p, trigger, negate); |
ab7f148f | 2511 | if (!c) |
74051b9b | 2512 | return log_oom(); |
52661efd | 2513 | |
59fccdc5 | 2514 | LIST_PREPEND(conditions, *list, c); |
52661efd LP |
2515 | return 0; |
2516 | } | |
2517 | ||
59fccdc5 LP |
2518 | int config_parse_unit_condition_string( |
2519 | const char *unit, | |
2520 | const char *filename, | |
2521 | unsigned line, | |
2522 | const char *section, | |
2523 | unsigned section_line, | |
2524 | const char *lvalue, | |
2525 | int ltype, | |
2526 | const char *rvalue, | |
2527 | void *data, | |
2528 | void *userdata) { | |
039655a4 | 2529 | |
2fbe635a | 2530 | _cleanup_free_ char *s = NULL; |
59fccdc5 LP |
2531 | Condition **list = data, *c; |
2532 | ConditionType t = ltype; | |
2533 | bool trigger, negate; | |
2534 | Unit *u = userdata; | |
19f6d710 | 2535 | int r; |
039655a4 LP |
2536 | |
2537 | assert(filename); | |
2538 | assert(lvalue); | |
2539 | assert(rvalue); | |
2540 | assert(data); | |
2541 | ||
74051b9b LP |
2542 | if (isempty(rvalue)) { |
2543 | /* Empty assignment resets the list */ | |
447021aa | 2544 | *list = condition_free_list(*list); |
74051b9b LP |
2545 | return 0; |
2546 | } | |
2547 | ||
c0d6e764 LP |
2548 | trigger = rvalue[0] == '|'; |
2549 | if (trigger) | |
267632f0 LP |
2550 | rvalue++; |
2551 | ||
c0d6e764 LP |
2552 | negate = rvalue[0] == '!'; |
2553 | if (negate) | |
039655a4 LP |
2554 | rvalue++; |
2555 | ||
19f6d710 | 2556 | r = unit_full_printf(u, rvalue, &s); |
59fccdc5 | 2557 | if (r < 0) { |
063c4b1a | 2558 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
59fccdc5 | 2559 | return 0; |
19f6d710 | 2560 | } |
095b2d7a | 2561 | |
59fccdc5 | 2562 | c = condition_new(t, s, trigger, negate); |
c0d6e764 LP |
2563 | if (!c) |
2564 | return log_oom(); | |
039655a4 | 2565 | |
59fccdc5 | 2566 | LIST_PREPEND(conditions, *list, c); |
039655a4 LP |
2567 | return 0; |
2568 | } | |
2569 | ||
59fccdc5 LP |
2570 | int config_parse_unit_condition_null( |
2571 | const char *unit, | |
2572 | const char *filename, | |
2573 | unsigned line, | |
2574 | const char *section, | |
2575 | unsigned section_line, | |
2576 | const char *lvalue, | |
2577 | int ltype, | |
2578 | const char *rvalue, | |
2579 | void *data, | |
2580 | void *userdata) { | |
d257ddef | 2581 | |
59fccdc5 | 2582 | Condition **list = data, *c; |
267632f0 | 2583 | bool trigger, negate; |
d257ddef LP |
2584 | int b; |
2585 | ||
2586 | assert(filename); | |
2587 | assert(lvalue); | |
2588 | assert(rvalue); | |
2589 | assert(data); | |
2590 | ||
55dadc5c LP |
2591 | log_syntax(unit, LOG_WARNING, filename, line, 0, "%s= is deprecated, please do not use.", lvalue); |
2592 | ||
74051b9b LP |
2593 | if (isempty(rvalue)) { |
2594 | /* Empty assignment resets the list */ | |
447021aa | 2595 | *list = condition_free_list(*list); |
74051b9b LP |
2596 | return 0; |
2597 | } | |
2598 | ||
2599 | trigger = rvalue[0] == '|'; | |
2600 | if (trigger) | |
267632f0 LP |
2601 | rvalue++; |
2602 | ||
74051b9b LP |
2603 | negate = rvalue[0] == '!'; |
2604 | if (negate) | |
d257ddef LP |
2605 | rvalue++; |
2606 | ||
74051b9b LP |
2607 | b = parse_boolean(rvalue); |
2608 | if (b < 0) { | |
12ca818f | 2609 | log_syntax(unit, LOG_ERR, filename, line, b, "Failed to parse boolean value in condition, ignoring: %s", rvalue); |
d257ddef LP |
2610 | return 0; |
2611 | } | |
2612 | ||
2613 | if (!b) | |
2614 | negate = !negate; | |
2615 | ||
74051b9b LP |
2616 | c = condition_new(CONDITION_NULL, NULL, trigger, negate); |
2617 | if (!c) | |
2618 | return log_oom(); | |
d257ddef | 2619 | |
59fccdc5 | 2620 | LIST_PREPEND(conditions, *list, c); |
d257ddef LP |
2621 | return 0; |
2622 | } | |
2623 | ||
a57f7e2c LP |
2624 | int config_parse_unit_requires_mounts_for( |
2625 | const char *unit, | |
2626 | const char *filename, | |
2627 | unsigned line, | |
2628 | const char *section, | |
71a61510 | 2629 | unsigned section_line, |
a57f7e2c LP |
2630 | const char *lvalue, |
2631 | int ltype, | |
2632 | const char *rvalue, | |
2633 | void *data, | |
2634 | void *userdata) { | |
7c8fa05c | 2635 | |
063c4b1a | 2636 | const char *p = rvalue; |
7c8fa05c | 2637 | Unit *u = userdata; |
035fe294 | 2638 | int r; |
7c8fa05c LP |
2639 | |
2640 | assert(filename); | |
2641 | assert(lvalue); | |
2642 | assert(rvalue); | |
2643 | assert(data); | |
2644 | ||
063c4b1a | 2645 | for (;;) { |
744bb5b1 | 2646 | _cleanup_free_ char *word = NULL, *resolved = NULL; |
a57f7e2c | 2647 | |
035fe294 ZJS |
2648 | r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES); |
2649 | if (r == 0) | |
2650 | return 0; | |
2651 | if (r == -ENOMEM) | |
a57f7e2c | 2652 | return log_oom(); |
035fe294 ZJS |
2653 | if (r < 0) { |
2654 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
2655 | "Invalid syntax, ignoring: %s", rvalue); | |
2656 | return 0; | |
2657 | } | |
7c8fa05c | 2658 | |
744bb5b1 LP |
2659 | r = unit_full_printf(u, word, &resolved); |
2660 | if (r < 0) { | |
063c4b1a | 2661 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", word); |
744bb5b1 LP |
2662 | continue; |
2663 | } | |
2664 | ||
2f4d31c1 YW |
2665 | r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
2666 | if (r < 0) | |
2667 | continue; | |
2668 | ||
eef85c4a | 2669 | r = unit_require_mounts_for(u, resolved, UNIT_DEPENDENCY_FILE); |
a57f7e2c | 2670 | if (r < 0) { |
063c4b1a | 2671 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to add required mount '%s', ignoring: %m", resolved); |
a57f7e2c LP |
2672 | continue; |
2673 | } | |
2674 | } | |
7c8fa05c | 2675 | } |
9e372868 | 2676 | |
e8e581bf ZJS |
2677 | int config_parse_documentation(const char *unit, |
2678 | const char *filename, | |
2679 | unsigned line, | |
2680 | const char *section, | |
71a61510 | 2681 | unsigned section_line, |
e8e581bf ZJS |
2682 | const char *lvalue, |
2683 | int ltype, | |
2684 | const char *rvalue, | |
2685 | void *data, | |
2686 | void *userdata) { | |
49dbfa7b LP |
2687 | |
2688 | Unit *u = userdata; | |
2689 | int r; | |
2690 | char **a, **b; | |
2691 | ||
2692 | assert(filename); | |
2693 | assert(lvalue); | |
2694 | assert(rvalue); | |
2695 | assert(u); | |
2696 | ||
74051b9b LP |
2697 | if (isempty(rvalue)) { |
2698 | /* Empty assignment resets the list */ | |
6796073e | 2699 | u->documentation = strv_free(u->documentation); |
74051b9b LP |
2700 | return 0; |
2701 | } | |
2702 | ||
71a61510 | 2703 | r = config_parse_unit_strv_printf(unit, filename, line, section, section_line, lvalue, ltype, |
e8e581bf | 2704 | rvalue, data, userdata); |
49dbfa7b LP |
2705 | if (r < 0) |
2706 | return r; | |
2707 | ||
2708 | for (a = b = u->documentation; a && *a; a++) { | |
2709 | ||
a2e03378 | 2710 | if (documentation_url_is_valid(*a)) |
49dbfa7b LP |
2711 | *(b++) = *a; |
2712 | else { | |
12ca818f | 2713 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid URL, ignoring: %s", *a); |
49dbfa7b LP |
2714 | free(*a); |
2715 | } | |
2716 | } | |
f6d2d421 ZJS |
2717 | if (b) |
2718 | *b = NULL; | |
49dbfa7b LP |
2719 | |
2720 | return r; | |
2721 | } | |
2722 | ||
349cc4a5 | 2723 | #if HAVE_SECCOMP |
17df7223 LP |
2724 | int config_parse_syscall_filter( |
2725 | const char *unit, | |
2726 | const char *filename, | |
2727 | unsigned line, | |
2728 | const char *section, | |
2729 | unsigned section_line, | |
2730 | const char *lvalue, | |
2731 | int ltype, | |
2732 | const char *rvalue, | |
2733 | void *data, | |
2734 | void *userdata) { | |
2735 | ||
8351ceae LP |
2736 | ExecContext *c = data; |
2737 | Unit *u = userdata; | |
b5fb3789 | 2738 | bool invert = false; |
8130926d | 2739 | const char *p; |
17df7223 | 2740 | int r; |
8351ceae LP |
2741 | |
2742 | assert(filename); | |
2743 | assert(lvalue); | |
2744 | assert(rvalue); | |
2745 | assert(u); | |
2746 | ||
74051b9b LP |
2747 | if (isempty(rvalue)) { |
2748 | /* Empty assignment resets the list */ | |
8cfa775f | 2749 | c->syscall_filter = hashmap_free(c->syscall_filter); |
17df7223 | 2750 | c->syscall_whitelist = false; |
74051b9b LP |
2751 | return 0; |
2752 | } | |
2753 | ||
8351ceae LP |
2754 | if (rvalue[0] == '~') { |
2755 | invert = true; | |
2756 | rvalue++; | |
2757 | } | |
2758 | ||
17df7223 | 2759 | if (!c->syscall_filter) { |
8cfa775f | 2760 | c->syscall_filter = hashmap_new(NULL); |
17df7223 LP |
2761 | if (!c->syscall_filter) |
2762 | return log_oom(); | |
2763 | ||
c0467cf3 | 2764 | if (invert) |
17df7223 LP |
2765 | /* Allow everything but the ones listed */ |
2766 | c->syscall_whitelist = false; | |
c0467cf3 | 2767 | else { |
17df7223 LP |
2768 | /* Allow nothing but the ones listed */ |
2769 | c->syscall_whitelist = true; | |
8351ceae | 2770 | |
17df7223 | 2771 | /* Accept default syscalls if we are on a whitelist */ |
2f6b9110 LP |
2772 | r = seccomp_parse_syscall_filter( |
2773 | "@default", -1, c->syscall_filter, | |
58f6ab44 ZJS |
2774 | SECCOMP_PARSE_PERMISSIVE|SECCOMP_PARSE_WHITELIST, |
2775 | unit, | |
2776 | NULL, 0); | |
201c1cc2 TM |
2777 | if (r < 0) |
2778 | return r; | |
c0467cf3 | 2779 | } |
8351ceae LP |
2780 | } |
2781 | ||
8130926d LP |
2782 | p = rvalue; |
2783 | for (;;) { | |
8cfa775f YW |
2784 | _cleanup_free_ char *word = NULL, *name = NULL; |
2785 | int num; | |
8351ceae | 2786 | |
8130926d LP |
2787 | r = extract_first_word(&p, &word, NULL, 0); |
2788 | if (r == 0) | |
063c4b1a | 2789 | return 0; |
8130926d | 2790 | if (r == -ENOMEM) |
74051b9b | 2791 | return log_oom(); |
8130926d LP |
2792 | if (r < 0) { |
2793 | log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue); | |
063c4b1a | 2794 | return 0; |
8130926d | 2795 | } |
8351ceae | 2796 | |
8cfa775f YW |
2797 | r = parse_syscall_and_errno(word, &name, &num); |
2798 | if (r < 0) { | |
2799 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse syscall:errno, ignoring: %s", word); | |
2800 | continue; | |
2801 | } | |
2802 | ||
58f6ab44 | 2803 | r = seccomp_parse_syscall_filter( |
acd142af LP |
2804 | name, num, c->syscall_filter, |
2805 | SECCOMP_PARSE_LOG|SECCOMP_PARSE_PERMISSIVE| | |
2806 | (invert ? SECCOMP_PARSE_INVERT : 0)| | |
2807 | (c->syscall_whitelist ? SECCOMP_PARSE_WHITELIST : 0), | |
2808 | unit, filename, line); | |
201c1cc2 TM |
2809 | if (r < 0) |
2810 | return r; | |
c0467cf3 | 2811 | } |
17df7223 LP |
2812 | } |
2813 | ||
57183d11 LP |
2814 | int config_parse_syscall_archs( |
2815 | const char *unit, | |
2816 | const char *filename, | |
2817 | unsigned line, | |
2818 | const char *section, | |
2819 | unsigned section_line, | |
2820 | const char *lvalue, | |
2821 | int ltype, | |
2822 | const char *rvalue, | |
2823 | void *data, | |
2824 | void *userdata) { | |
2825 | ||
063c4b1a | 2826 | const char *p = rvalue; |
d3b1c508 | 2827 | Set **archs = data; |
57183d11 LP |
2828 | int r; |
2829 | ||
2830 | if (isempty(rvalue)) { | |
525d3cc7 | 2831 | *archs = set_free(*archs); |
57183d11 LP |
2832 | return 0; |
2833 | } | |
2834 | ||
d5099efc | 2835 | r = set_ensure_allocated(archs, NULL); |
57183d11 LP |
2836 | if (r < 0) |
2837 | return log_oom(); | |
2838 | ||
063c4b1a | 2839 | for (;;) { |
035fe294 | 2840 | _cleanup_free_ char *word = NULL; |
57183d11 LP |
2841 | uint32_t a; |
2842 | ||
035fe294 ZJS |
2843 | r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES); |
2844 | if (r == 0) | |
2845 | return 0; | |
2846 | if (r == -ENOMEM) | |
57183d11 | 2847 | return log_oom(); |
035fe294 ZJS |
2848 | if (r < 0) { |
2849 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
2850 | "Invalid syntax, ignoring: %s", rvalue); | |
2851 | return 0; | |
2852 | } | |
57183d11 | 2853 | |
035fe294 | 2854 | r = seccomp_arch_from_string(word, &a); |
57183d11 | 2855 | if (r < 0) { |
035fe294 ZJS |
2856 | log_syntax(unit, LOG_ERR, filename, line, r, |
2857 | "Failed to parse system call architecture \"%s\", ignoring: %m", word); | |
57183d11 LP |
2858 | continue; |
2859 | } | |
2860 | ||
d3b1c508 | 2861 | r = set_put(*archs, UINT32_TO_PTR(a + 1)); |
57183d11 LP |
2862 | if (r < 0) |
2863 | return log_oom(); | |
2864 | } | |
57183d11 LP |
2865 | } |
2866 | ||
17df7223 LP |
2867 | int config_parse_syscall_errno( |
2868 | const char *unit, | |
2869 | const char *filename, | |
2870 | unsigned line, | |
2871 | const char *section, | |
2872 | unsigned section_line, | |
2873 | const char *lvalue, | |
2874 | int ltype, | |
2875 | const char *rvalue, | |
2876 | void *data, | |
2877 | void *userdata) { | |
2878 | ||
2879 | ExecContext *c = data; | |
2880 | int e; | |
2881 | ||
2882 | assert(filename); | |
2883 | assert(lvalue); | |
2884 | assert(rvalue); | |
2885 | ||
2886 | if (isempty(rvalue)) { | |
2887 | /* Empty assignment resets to KILL */ | |
2888 | c->syscall_errno = 0; | |
2889 | return 0; | |
8351ceae LP |
2890 | } |
2891 | ||
3df90f24 YW |
2892 | e = parse_errno(rvalue); |
2893 | if (e <= 0) { | |
12ca818f | 2894 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse error number, ignoring: %s", rvalue); |
17df7223 LP |
2895 | return 0; |
2896 | } | |
8351ceae | 2897 | |
17df7223 | 2898 | c->syscall_errno = e; |
8351ceae LP |
2899 | return 0; |
2900 | } | |
4298d0b5 LP |
2901 | |
2902 | int config_parse_address_families( | |
2903 | const char *unit, | |
2904 | const char *filename, | |
2905 | unsigned line, | |
2906 | const char *section, | |
2907 | unsigned section_line, | |
2908 | const char *lvalue, | |
2909 | int ltype, | |
2910 | const char *rvalue, | |
2911 | void *data, | |
2912 | void *userdata) { | |
2913 | ||
2914 | ExecContext *c = data; | |
4298d0b5 | 2915 | bool invert = false; |
035fe294 | 2916 | const char *p; |
4298d0b5 LP |
2917 | int r; |
2918 | ||
2919 | assert(filename); | |
2920 | assert(lvalue); | |
2921 | assert(rvalue); | |
4298d0b5 LP |
2922 | |
2923 | if (isempty(rvalue)) { | |
2924 | /* Empty assignment resets the list */ | |
525d3cc7 | 2925 | c->address_families = set_free(c->address_families); |
4298d0b5 LP |
2926 | c->address_families_whitelist = false; |
2927 | return 0; | |
2928 | } | |
2929 | ||
2930 | if (rvalue[0] == '~') { | |
2931 | invert = true; | |
2932 | rvalue++; | |
2933 | } | |
2934 | ||
2935 | if (!c->address_families) { | |
d5099efc | 2936 | c->address_families = set_new(NULL); |
4298d0b5 LP |
2937 | if (!c->address_families) |
2938 | return log_oom(); | |
2939 | ||
2940 | c->address_families_whitelist = !invert; | |
2941 | } | |
2942 | ||
035fe294 ZJS |
2943 | for (p = rvalue;;) { |
2944 | _cleanup_free_ char *word = NULL; | |
4298d0b5 LP |
2945 | int af; |
2946 | ||
035fe294 ZJS |
2947 | r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES); |
2948 | if (r == 0) | |
2949 | return 0; | |
2950 | if (r == -ENOMEM) | |
4298d0b5 | 2951 | return log_oom(); |
035fe294 ZJS |
2952 | if (r < 0) { |
2953 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
2954 | "Invalid syntax, ignoring: %s", rvalue); | |
2955 | return 0; | |
2956 | } | |
4298d0b5 | 2957 | |
035fe294 | 2958 | af = af_from_name(word); |
acf4d158 YW |
2959 | if (af < 0) { |
2960 | log_syntax(unit, LOG_ERR, filename, line, af, | |
063c4b1a | 2961 | "Failed to parse address family, ignoring: %s", word); |
4298d0b5 LP |
2962 | continue; |
2963 | } | |
2964 | ||
2965 | /* If we previously wanted to forbid an address family and now | |
035fe294 | 2966 | * we want to allow it, then just remove it from the list. |
4298d0b5 LP |
2967 | */ |
2968 | if (!invert == c->address_families_whitelist) { | |
2969 | r = set_put(c->address_families, INT_TO_PTR(af)); | |
4298d0b5 LP |
2970 | if (r < 0) |
2971 | return log_oom(); | |
2972 | } else | |
2973 | set_remove(c->address_families, INT_TO_PTR(af)); | |
2974 | } | |
4298d0b5 | 2975 | } |
add00535 LP |
2976 | |
2977 | int config_parse_restrict_namespaces( | |
2978 | const char *unit, | |
2979 | const char *filename, | |
2980 | unsigned line, | |
2981 | const char *section, | |
2982 | unsigned section_line, | |
2983 | const char *lvalue, | |
2984 | int ltype, | |
2985 | const char *rvalue, | |
2986 | void *data, | |
2987 | void *userdata) { | |
2988 | ||
2989 | ExecContext *c = data; | |
aa9d574d | 2990 | unsigned long flags; |
add00535 LP |
2991 | bool invert = false; |
2992 | int r; | |
2993 | ||
2994 | if (isempty(rvalue)) { | |
2995 | /* Reset to the default. */ | |
aa9d574d YW |
2996 | c->restrict_namespaces = NAMESPACE_FLAGS_INITIAL; |
2997 | return 0; | |
2998 | } | |
2999 | ||
3000 | /* Boolean parameter ignores the previous settings */ | |
3001 | r = parse_boolean(rvalue); | |
3002 | if (r > 0) { | |
3003 | c->restrict_namespaces = 0; | |
3004 | return 0; | |
3005 | } else if (r == 0) { | |
add00535 LP |
3006 | c->restrict_namespaces = NAMESPACE_FLAGS_ALL; |
3007 | return 0; | |
3008 | } | |
3009 | ||
3010 | if (rvalue[0] == '~') { | |
3011 | invert = true; | |
3012 | rvalue++; | |
3013 | } | |
3014 | ||
aa9d574d YW |
3015 | /* Not a boolean argument, in this case it's a list of namespace types. */ |
3016 | r = namespace_flags_from_string(rvalue, &flags); | |
3017 | if (r < 0) { | |
3018 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse namespace type string, ignoring: %s", rvalue); | |
3019 | return 0; | |
add00535 LP |
3020 | } |
3021 | ||
aa9d574d YW |
3022 | if (c->restrict_namespaces == NAMESPACE_FLAGS_INITIAL) |
3023 | /* Initial assignment. Just set the value. */ | |
3024 | c->restrict_namespaces = invert ? (~flags) & NAMESPACE_FLAGS_ALL : flags; | |
3025 | else | |
3026 | /* Merge the value with the previous one. */ | |
3027 | SET_FLAG(c->restrict_namespaces, flags, !invert); | |
add00535 LP |
3028 | |
3029 | return 0; | |
3030 | } | |
c0467cf3 | 3031 | #endif |
8351ceae | 3032 | |
a016b922 LP |
3033 | int config_parse_unit_slice( |
3034 | const char *unit, | |
3035 | const char *filename, | |
3036 | unsigned line, | |
3037 | const char *section, | |
71a61510 | 3038 | unsigned section_line, |
a016b922 LP |
3039 | const char *lvalue, |
3040 | int ltype, | |
3041 | const char *rvalue, | |
3042 | void *data, | |
3043 | void *userdata) { | |
3044 | ||
063c4b1a | 3045 | _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; |
a016b922 | 3046 | _cleanup_free_ char *k = NULL; |
d79200e2 | 3047 | Unit *u = userdata, *slice = NULL; |
a016b922 LP |
3048 | int r; |
3049 | ||
3050 | assert(filename); | |
3051 | assert(lvalue); | |
3052 | assert(rvalue); | |
3053 | assert(u); | |
3054 | ||
19f6d710 | 3055 | r = unit_name_printf(u, rvalue, &k); |
d79200e2 | 3056 | if (r < 0) { |
063c4b1a | 3057 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue); |
d79200e2 | 3058 | return 0; |
19f6d710 | 3059 | } |
a016b922 | 3060 | |
063c4b1a | 3061 | r = manager_load_unit(u->manager, k, NULL, &error, &slice); |
a016b922 | 3062 | if (r < 0) { |
063c4b1a | 3063 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to load slice unit %s, ignoring: %s", k, bus_error_message(&error, r)); |
a016b922 LP |
3064 | return 0; |
3065 | } | |
3066 | ||
d79200e2 LP |
3067 | r = unit_set_slice(u, slice); |
3068 | if (r < 0) { | |
063c4b1a | 3069 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to assign slice %s to unit %s, ignoring: %m", slice->id, u->id); |
a016b922 LP |
3070 | return 0; |
3071 | } | |
3072 | ||
a016b922 LP |
3073 | return 0; |
3074 | } | |
3075 | ||
b2f8b02e LP |
3076 | int config_parse_cpu_quota( |
3077 | const char *unit, | |
3078 | const char *filename, | |
3079 | unsigned line, | |
3080 | const char *section, | |
3081 | unsigned section_line, | |
3082 | const char *lvalue, | |
3083 | int ltype, | |
3084 | const char *rvalue, | |
3085 | void *data, | |
3086 | void *userdata) { | |
3087 | ||
3088 | CGroupContext *c = data; | |
9184ca48 | 3089 | int r; |
b2f8b02e LP |
3090 | |
3091 | assert(filename); | |
3092 | assert(lvalue); | |
3093 | assert(rvalue); | |
3094 | ||
3095 | if (isempty(rvalue)) { | |
3a43da28 | 3096 | c->cpu_quota_per_sec_usec = USEC_INFINITY; |
b2f8b02e LP |
3097 | return 0; |
3098 | } | |
3099 | ||
f806dfd3 | 3100 | r = parse_permille_unbounded(rvalue); |
9184ca48 | 3101 | if (r <= 0) { |
063c4b1a | 3102 | log_syntax(unit, LOG_ERR, filename, line, r, "Invalid CPU quota '%s', ignoring.", rvalue); |
9a054909 | 3103 | return 0; |
b2f8b02e LP |
3104 | } |
3105 | ||
f806dfd3 | 3106 | c->cpu_quota_per_sec_usec = ((usec_t) r * USEC_PER_SEC) / 1000U; |
b2f8b02e LP |
3107 | return 0; |
3108 | } | |
3109 | ||
4ad49000 LP |
3110 | int config_parse_memory_limit( |
3111 | const char *unit, | |
3112 | const char *filename, | |
3113 | unsigned line, | |
3114 | const char *section, | |
71a61510 | 3115 | unsigned section_line, |
4ad49000 LP |
3116 | const char *lvalue, |
3117 | int ltype, | |
3118 | const char *rvalue, | |
3119 | void *data, | |
3120 | void *userdata) { | |
3121 | ||
3122 | CGroupContext *c = data; | |
da4d897e | 3123 | uint64_t bytes = CGROUP_LIMIT_MAX; |
4ad49000 LP |
3124 | int r; |
3125 | ||
e57c9ce1 | 3126 | if (!isempty(rvalue) && !streq(rvalue, "infinity")) { |
875ae566 | 3127 | |
f806dfd3 | 3128 | r = parse_permille(rvalue); |
875ae566 LP |
3129 | if (r < 0) { |
3130 | r = parse_size(rvalue, 1024, &bytes); | |
3131 | if (r < 0) { | |
063c4b1a | 3132 | log_syntax(unit, LOG_ERR, filename, line, r, "Invalid memory limit '%s', ignoring: %m", rvalue); |
875ae566 LP |
3133 | return 0; |
3134 | } | |
3135 | } else | |
f806dfd3 | 3136 | bytes = physical_memory_scale(r, 1000U); |
875ae566 | 3137 | |
906bdbf5 | 3138 | if (bytes >= UINT64_MAX || |
22bf131b | 3139 | (bytes <= 0 && !STR_IN_SET(lvalue, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) { |
063c4b1a | 3140 | log_syntax(unit, LOG_ERR, filename, line, 0, "Memory limit '%s' out of range, ignoring.", rvalue); |
da4d897e TH |
3141 | return 0; |
3142 | } | |
4ad49000 LP |
3143 | } |
3144 | ||
c52db42b CD |
3145 | if (streq(lvalue, "DefaultMemoryLow")) { |
3146 | c->default_memory_low_set = true; | |
3147 | if (isempty(rvalue)) | |
3148 | c->default_memory_low = CGROUP_LIMIT_MIN; | |
3149 | else | |
3150 | c->default_memory_low = bytes; | |
7ad5439e CD |
3151 | } else if (streq(lvalue, "DefaultMemoryMin")) { |
3152 | c->default_memory_min_set = true; | |
3153 | if (isempty(rvalue)) | |
3154 | c->default_memory_min = CGROUP_LIMIT_MIN; | |
3155 | else | |
3156 | c->default_memory_min = bytes; | |
3157 | } else if (streq(lvalue, "MemoryMin")) { | |
48422635 | 3158 | c->memory_min = bytes; |
7ad5439e CD |
3159 | c->memory_min_set = true; |
3160 | } else if (streq(lvalue, "MemoryLow")) { | |
da4d897e | 3161 | c->memory_low = bytes; |
c52db42b CD |
3162 | c->memory_low_set = true; |
3163 | } else if (streq(lvalue, "MemoryHigh")) | |
da4d897e TH |
3164 | c->memory_high = bytes; |
3165 | else if (streq(lvalue, "MemoryMax")) | |
3166 | c->memory_max = bytes; | |
96e131ea WC |
3167 | else if (streq(lvalue, "MemorySwapMax")) |
3168 | c->memory_swap_max = bytes; | |
3169 | else if (streq(lvalue, "MemoryLimit")) | |
da4d897e | 3170 | c->memory_limit = bytes; |
96e131ea WC |
3171 | else |
3172 | return -EINVAL; | |
4ad49000 | 3173 | |
4ad49000 LP |
3174 | return 0; |
3175 | } | |
3176 | ||
03a7b521 LP |
3177 | int config_parse_tasks_max( |
3178 | const char *unit, | |
3179 | const char *filename, | |
3180 | unsigned line, | |
3181 | const char *section, | |
3182 | unsigned section_line, | |
3183 | const char *lvalue, | |
3184 | int ltype, | |
3185 | const char *rvalue, | |
3186 | void *data, | |
3187 | void *userdata) { | |
3188 | ||
f5058264 TH |
3189 | uint64_t *tasks_max = data, v; |
3190 | Unit *u = userdata; | |
03a7b521 LP |
3191 | int r; |
3192 | ||
f5058264 | 3193 | if (isempty(rvalue)) { |
958b8c7b | 3194 | *tasks_max = u ? u->manager->default_tasks_max : UINT64_MAX; |
f5058264 TH |
3195 | return 0; |
3196 | } | |
3197 | ||
3198 | if (streq(rvalue, "infinity")) { | |
3199 | *tasks_max = CGROUP_LIMIT_MAX; | |
03a7b521 LP |
3200 | return 0; |
3201 | } | |
3202 | ||
f806dfd3 | 3203 | r = parse_permille(rvalue); |
83f8e808 | 3204 | if (r < 0) { |
f5058264 | 3205 | r = safe_atou64(rvalue, &v); |
83f8e808 | 3206 | if (r < 0) { |
063c4b1a | 3207 | log_syntax(unit, LOG_ERR, filename, line, r, "Invalid maximum tasks value '%s', ignoring: %m", rvalue); |
83f8e808 LP |
3208 | return 0; |
3209 | } | |
3210 | } else | |
f806dfd3 | 3211 | v = system_tasks_max_scale(r, 1000U); |
83f8e808 | 3212 | |
f5058264 | 3213 | if (v <= 0 || v >= UINT64_MAX) { |
063c4b1a | 3214 | log_syntax(unit, LOG_ERR, filename, line, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue); |
03a7b521 LP |
3215 | return 0; |
3216 | } | |
3217 | ||
f5058264 | 3218 | *tasks_max = v; |
03a7b521 LP |
3219 | return 0; |
3220 | } | |
3221 | ||
02638280 LP |
3222 | int config_parse_delegate( |
3223 | const char *unit, | |
3224 | const char *filename, | |
3225 | unsigned line, | |
3226 | const char *section, | |
3227 | unsigned section_line, | |
3228 | const char *lvalue, | |
3229 | int ltype, | |
3230 | const char *rvalue, | |
3231 | void *data, | |
3232 | void *userdata) { | |
3233 | ||
3234 | CGroupContext *c = data; | |
ecae73d7 | 3235 | UnitType t; |
02638280 LP |
3236 | int r; |
3237 | ||
ecae73d7 ZJS |
3238 | t = unit_name_to_type(unit); |
3239 | assert(t != _UNIT_TYPE_INVALID); | |
3240 | ||
3241 | if (!unit_vtable[t]->can_delegate) { | |
3242 | log_syntax(unit, LOG_ERR, filename, line, 0, "Delegate= setting not supported for this unit type, ignoring."); | |
3243 | return 0; | |
3244 | } | |
3245 | ||
02638280 LP |
3246 | /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it |
3247 | * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the | |
3248 | * mask to delegate. */ | |
3249 | ||
1bdfc7b9 | 3250 | if (isempty(rvalue)) { |
d48013f8 YW |
3251 | /* An empty string resets controllers and set Delegate=yes. */ |
3252 | c->delegate = true; | |
1bdfc7b9 YW |
3253 | c->delegate_controllers = 0; |
3254 | return 0; | |
3255 | } | |
3256 | ||
02638280 LP |
3257 | r = parse_boolean(rvalue); |
3258 | if (r < 0) { | |
3259 | const char *p = rvalue; | |
3260 | CGroupMask mask = 0; | |
3261 | ||
3262 | for (;;) { | |
3263 | _cleanup_free_ char *word = NULL; | |
3264 | CGroupController cc; | |
3265 | ||
3266 | r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES); | |
3267 | if (r == 0) | |
3268 | break; | |
3269 | if (r == -ENOMEM) | |
3270 | return log_oom(); | |
3271 | if (r < 0) { | |
3272 | log_syntax(unit, LOG_ERR, filename, line, r, "Invalid syntax, ignoring: %s", rvalue); | |
ff1b8455 | 3273 | return 0; |
02638280 LP |
3274 | } |
3275 | ||
3276 | cc = cgroup_controller_from_string(word); | |
3277 | if (cc < 0) { | |
063c4b1a | 3278 | log_syntax(unit, LOG_ERR, filename, line, r, "Invalid controller name '%s', ignoring", word); |
02638280 LP |
3279 | continue; |
3280 | } | |
3281 | ||
3282 | mask |= CGROUP_CONTROLLER_TO_MASK(cc); | |
3283 | } | |
3284 | ||
3285 | c->delegate = true; | |
3286 | c->delegate_controllers |= mask; | |
3287 | ||
3288 | } else if (r > 0) { | |
3289 | c->delegate = true; | |
3290 | c->delegate_controllers = _CGROUP_MASK_ALL; | |
3291 | } else { | |
3292 | c->delegate = false; | |
3293 | c->delegate_controllers = 0; | |
3294 | } | |
3295 | ||
3296 | return 0; | |
3297 | } | |
3298 | ||
4ad49000 LP |
3299 | int config_parse_device_allow( |
3300 | const char *unit, | |
3301 | const char *filename, | |
3302 | unsigned line, | |
3303 | const char *section, | |
71a61510 | 3304 | unsigned section_line, |
4ad49000 LP |
3305 | const char *lvalue, |
3306 | int ltype, | |
3307 | const char *rvalue, | |
3308 | void *data, | |
3309 | void *userdata) { | |
3310 | ||
c9f620bf | 3311 | _cleanup_free_ char *path = NULL, *resolved = NULL; |
4ad49000 | 3312 | CGroupContext *c = data; |
c9f620bf | 3313 | const char *p = rvalue; |
1116e14c | 3314 | int r; |
4ad49000 LP |
3315 | |
3316 | if (isempty(rvalue)) { | |
3317 | while (c->device_allow) | |
3318 | cgroup_context_free_device_allow(c, c->device_allow); | |
3319 | ||
3320 | return 0; | |
3321 | } | |
3322 | ||
c9f620bf YW |
3323 | r = extract_first_word(&p, &path, NULL, EXTRACT_QUOTES); |
3324 | if (r == -ENOMEM) | |
3325 | return log_oom(); | |
508f63b4 | 3326 | if (r < 0) { |
1116e14c | 3327 | log_syntax(unit, LOG_WARNING, filename, line, r, |
c9f620bf YW |
3328 | "Invalid syntax, ignoring: %s", rvalue); |
3329 | return 0; | |
3330 | } | |
3331 | if (r == 0) { | |
3332 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
3333 | "Failed to extract device path and rights from '%s', ignoring.", rvalue); | |
20d52ab6 | 3334 | return 0; |
1116e14c NBS |
3335 | } |
3336 | ||
c9f620bf YW |
3337 | r = unit_full_printf(userdata, path, &resolved); |
3338 | if (r < 0) { | |
3339 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3340 | "Failed to resolve unit specifiers in '%s', ignoring: %m", path); | |
4ad49000 LP |
3341 | return 0; |
3342 | } | |
3343 | ||
49fe5c09 | 3344 | if (!STARTSWITH_SET(resolved, "block-", "char-")) { |
2f4d31c1 | 3345 | |
57e84e75 LP |
3346 | r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue); |
3347 | if (r < 0) | |
3348 | return 0; | |
3349 | ||
3350 | if (!valid_device_node_path(resolved)) { | |
3351 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid device node path '%s', ignoring.", resolved); | |
3352 | return 0; | |
3353 | } | |
c9f620bf | 3354 | } |
4ad49000 | 3355 | |
c9f620bf YW |
3356 | if (!isempty(p) && !in_charset(p, "rwm")) { |
3357 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid device rights '%s', ignoring.", p); | |
4ad49000 LP |
3358 | return 0; |
3359 | } | |
3360 | ||
fd870bac | 3361 | return cgroup_add_device_allow(c, resolved, p); |
4ad49000 LP |
3362 | } |
3363 | ||
13c31542 TH |
3364 | int config_parse_io_device_weight( |
3365 | const char *unit, | |
3366 | const char *filename, | |
3367 | unsigned line, | |
3368 | const char *section, | |
3369 | unsigned section_line, | |
3370 | const char *lvalue, | |
3371 | int ltype, | |
3372 | const char *rvalue, | |
3373 | void *data, | |
3374 | void *userdata) { | |
3375 | ||
c9f620bf | 3376 | _cleanup_free_ char *path = NULL, *resolved = NULL; |
13c31542 TH |
3377 | CGroupIODeviceWeight *w; |
3378 | CGroupContext *c = data; | |
c9f620bf | 3379 | const char *p = rvalue; |
13c31542 | 3380 | uint64_t u; |
13c31542 TH |
3381 | int r; |
3382 | ||
3383 | assert(filename); | |
3384 | assert(lvalue); | |
3385 | assert(rvalue); | |
3386 | ||
3387 | if (isempty(rvalue)) { | |
3388 | while (c->io_device_weights) | |
3389 | cgroup_context_free_io_device_weight(c, c->io_device_weights); | |
3390 | ||
3391 | return 0; | |
3392 | } | |
3393 | ||
c9f620bf YW |
3394 | r = extract_first_word(&p, &path, NULL, EXTRACT_QUOTES); |
3395 | if (r == -ENOMEM) | |
3396 | return log_oom(); | |
3397 | if (r < 0) { | |
3398 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3399 | "Invalid syntax, ignoring: %s", rvalue); | |
3400 | return 0; | |
3401 | } | |
3402 | if (r == 0 || isempty(p)) { | |
3403 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
3404 | "Failed to extract device path and weight from '%s', ignoring.", rvalue); | |
13c31542 TH |
3405 | return 0; |
3406 | } | |
3407 | ||
c9f620bf YW |
3408 | r = unit_full_printf(userdata, path, &resolved); |
3409 | if (r < 0) { | |
3410 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3411 | "Failed to resolve unit specifiers in '%s', ignoring: %m", path); | |
3412 | return 0; | |
3413 | } | |
13c31542 | 3414 | |
2f4d31c1 YW |
3415 | r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue); |
3416 | if (r < 0) | |
3417 | return 0; | |
3418 | ||
c9f620bf | 3419 | r = cg_weight_parse(p, &u); |
13c31542 | 3420 | if (r < 0) { |
c9f620bf | 3421 | log_syntax(unit, LOG_ERR, filename, line, r, "IO weight '%s' invalid, ignoring: %m", p); |
13c31542 TH |
3422 | return 0; |
3423 | } | |
3424 | ||
3425 | assert(u != CGROUP_WEIGHT_INVALID); | |
3426 | ||
3427 | w = new0(CGroupIODeviceWeight, 1); | |
3428 | if (!w) | |
3429 | return log_oom(); | |
3430 | ||
c9f620bf | 3431 | w->path = TAKE_PTR(resolved); |
13c31542 TH |
3432 | w->weight = u; |
3433 | ||
3434 | LIST_PREPEND(device_weights, c->io_device_weights, w); | |
3435 | return 0; | |
3436 | } | |
3437 | ||
6ae4283c TH |
3438 | int config_parse_io_device_latency( |
3439 | const char *unit, | |
3440 | const char *filename, | |
3441 | unsigned line, | |
3442 | const char *section, | |
3443 | unsigned section_line, | |
3444 | const char *lvalue, | |
3445 | int ltype, | |
3446 | const char *rvalue, | |
3447 | void *data, | |
3448 | void *userdata) { | |
3449 | ||
3450 | _cleanup_free_ char *path = NULL, *resolved = NULL; | |
3451 | CGroupIODeviceLatency *l; | |
3452 | CGroupContext *c = data; | |
3453 | const char *p = rvalue; | |
3454 | usec_t usec; | |
3455 | int r; | |
3456 | ||
3457 | assert(filename); | |
3458 | assert(lvalue); | |
3459 | assert(rvalue); | |
3460 | ||
3461 | if (isempty(rvalue)) { | |
3462 | while (c->io_device_latencies) | |
3463 | cgroup_context_free_io_device_latency(c, c->io_device_latencies); | |
3464 | ||
3465 | return 0; | |
3466 | } | |
3467 | ||
3468 | r = extract_first_word(&p, &path, NULL, EXTRACT_QUOTES); | |
3469 | if (r == -ENOMEM) | |
3470 | return log_oom(); | |
3471 | if (r < 0) { | |
3472 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3473 | "Invalid syntax, ignoring: %s", rvalue); | |
3474 | return 0; | |
3475 | } | |
3476 | if (r == 0 || isempty(p)) { | |
3477 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
3478 | "Failed to extract device path and latency from '%s', ignoring.", rvalue); | |
3479 | return 0; | |
3480 | } | |
3481 | ||
3482 | r = unit_full_printf(userdata, path, &resolved); | |
3483 | if (r < 0) { | |
3484 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3485 | "Failed to resolve unit specifiers in '%s', ignoring: %m", path); | |
3486 | return 0; | |
3487 | } | |
3488 | ||
3489 | r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue); | |
3490 | if (r < 0) | |
3491 | return 0; | |
3492 | ||
3493 | if (parse_sec(p, &usec) < 0) { | |
3494 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse timer value, ignoring: %s", p); | |
3495 | return 0; | |
3496 | } | |
3497 | ||
3498 | l = new0(CGroupIODeviceLatency, 1); | |
3499 | if (!l) | |
3500 | return log_oom(); | |
3501 | ||
3502 | l->path = TAKE_PTR(resolved); | |
3503 | l->target_usec = usec; | |
3504 | ||
3505 | LIST_PREPEND(device_latencies, c->io_device_latencies, l); | |
3506 | return 0; | |
3507 | } | |
3508 | ||
13c31542 TH |
3509 | int config_parse_io_limit( |
3510 | const char *unit, | |
3511 | const char *filename, | |
3512 | unsigned line, | |
3513 | const char *section, | |
3514 | unsigned section_line, | |
3515 | const char *lvalue, | |
3516 | int ltype, | |
3517 | const char *rvalue, | |
3518 | void *data, | |
3519 | void *userdata) { | |
3520 | ||
c9f620bf | 3521 | _cleanup_free_ char *path = NULL, *resolved = NULL; |
13c31542 TH |
3522 | CGroupIODeviceLimit *l = NULL, *t; |
3523 | CGroupContext *c = data; | |
9be57249 | 3524 | CGroupIOLimitType type; |
c9f620bf | 3525 | const char *p = rvalue; |
13c31542 | 3526 | uint64_t num; |
13c31542 TH |
3527 | int r; |
3528 | ||
3529 | assert(filename); | |
3530 | assert(lvalue); | |
3531 | assert(rvalue); | |
3532 | ||
9be57249 TH |
3533 | type = cgroup_io_limit_type_from_string(lvalue); |
3534 | assert(type >= 0); | |
13c31542 TH |
3535 | |
3536 | if (isempty(rvalue)) { | |
3537 | LIST_FOREACH(device_limits, l, c->io_device_limits) | |
9be57249 | 3538 | l->limits[type] = cgroup_io_limit_defaults[type]; |
13c31542 TH |
3539 | return 0; |
3540 | } | |
3541 | ||
c9f620bf YW |
3542 | r = extract_first_word(&p, &path, NULL, EXTRACT_QUOTES); |
3543 | if (r == -ENOMEM) | |
3544 | return log_oom(); | |
3545 | if (r < 0) { | |
3546 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3547 | "Invalid syntax, ignoring: %s", rvalue); | |
3548 | return 0; | |
3549 | } | |
3550 | if (r == 0 || isempty(p)) { | |
3551 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
3552 | "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue); | |
13c31542 TH |
3553 | return 0; |
3554 | } | |
3555 | ||
c9f620bf YW |
3556 | r = unit_full_printf(userdata, path, &resolved); |
3557 | if (r < 0) { | |
3558 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3559 | "Failed to resolve unit specifiers in '%s', ignoring: %m", path); | |
3560 | return 0; | |
3561 | } | |
13c31542 | 3562 | |
2f4d31c1 YW |
3563 | r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue); |
3564 | if (r < 0) | |
3565 | return 0; | |
3566 | ||
9d5e9b4a | 3567 | if (streq("infinity", p)) |
13c31542 | 3568 | num = CGROUP_LIMIT_MAX; |
9d5e9b4a | 3569 | else { |
c9f620bf | 3570 | r = parse_size(p, 1000, &num); |
13c31542 | 3571 | if (r < 0 || num <= 0) { |
c9f620bf | 3572 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid IO limit '%s', ignoring.", p); |
13c31542 TH |
3573 | return 0; |
3574 | } | |
3575 | } | |
3576 | ||
3577 | LIST_FOREACH(device_limits, t, c->io_device_limits) { | |
c9f620bf | 3578 | if (path_equal(resolved, t->path)) { |
13c31542 TH |
3579 | l = t; |
3580 | break; | |
3581 | } | |
3582 | } | |
3583 | ||
3584 | if (!l) { | |
9be57249 TH |
3585 | CGroupIOLimitType ttype; |
3586 | ||
13c31542 TH |
3587 | l = new0(CGroupIODeviceLimit, 1); |
3588 | if (!l) | |
3589 | return log_oom(); | |
3590 | ||
c9f620bf | 3591 | l->path = TAKE_PTR(resolved); |
9be57249 TH |
3592 | for (ttype = 0; ttype < _CGROUP_IO_LIMIT_TYPE_MAX; ttype++) |
3593 | l->limits[ttype] = cgroup_io_limit_defaults[ttype]; | |
13c31542 TH |
3594 | |
3595 | LIST_PREPEND(device_limits, c->io_device_limits, l); | |
3596 | } | |
3597 | ||
9be57249 | 3598 | l->limits[type] = num; |
13c31542 TH |
3599 | |
3600 | return 0; | |
3601 | } | |
3602 | ||
8e7076ca LP |
3603 | int config_parse_blockio_device_weight( |
3604 | const char *unit, | |
3605 | const char *filename, | |
3606 | unsigned line, | |
3607 | const char *section, | |
71a61510 | 3608 | unsigned section_line, |
8e7076ca LP |
3609 | const char *lvalue, |
3610 | int ltype, | |
3611 | const char *rvalue, | |
3612 | void *data, | |
3613 | void *userdata) { | |
3614 | ||
c9f620bf | 3615 | _cleanup_free_ char *path = NULL, *resolved = NULL; |
8e7076ca | 3616 | CGroupBlockIODeviceWeight *w; |
4ad49000 | 3617 | CGroupContext *c = data; |
c9f620bf | 3618 | const char *p = rvalue; |
d53d9474 | 3619 | uint64_t u; |
4ad49000 LP |
3620 | int r; |
3621 | ||
3622 | assert(filename); | |
3623 | assert(lvalue); | |
3624 | assert(rvalue); | |
3625 | ||
3626 | if (isempty(rvalue)) { | |
4ad49000 LP |
3627 | while (c->blockio_device_weights) |
3628 | cgroup_context_free_blockio_device_weight(c, c->blockio_device_weights); | |
3629 | ||
3630 | return 0; | |
3631 | } | |
3632 | ||
c9f620bf YW |
3633 | r = extract_first_word(&p, &path, NULL, EXTRACT_QUOTES); |
3634 | if (r == -ENOMEM) | |
3635 | return log_oom(); | |
3636 | if (r < 0) { | |
3637 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3638 | "Invalid syntax, ignoring: %s", rvalue); | |
3639 | return 0; | |
3640 | } | |
3641 | if (r == 0 || isempty(p)) { | |
3642 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
3643 | "Failed to extract device node and weight from '%s', ignoring.", rvalue); | |
8e7076ca LP |
3644 | return 0; |
3645 | } | |
4ad49000 | 3646 | |
c9f620bf YW |
3647 | r = unit_full_printf(userdata, path, &resolved); |
3648 | if (r < 0) { | |
3649 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3650 | "Failed to resolve unit specifiers in '%s', ignoring: %m", path); | |
3651 | return 0; | |
3652 | } | |
4ad49000 | 3653 | |
2f4d31c1 YW |
3654 | r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue); |
3655 | if (r < 0) | |
3656 | return 0; | |
3657 | ||
c9f620bf | 3658 | r = cg_blkio_weight_parse(p, &u); |
d53d9474 | 3659 | if (r < 0) { |
c9f620bf | 3660 | log_syntax(unit, LOG_ERR, filename, line, r, "Invalid block IO weight '%s', ignoring: %m", p); |
4ad49000 LP |
3661 | return 0; |
3662 | } | |
3663 | ||
d53d9474 LP |
3664 | assert(u != CGROUP_BLKIO_WEIGHT_INVALID); |
3665 | ||
8e7076ca LP |
3666 | w = new0(CGroupBlockIODeviceWeight, 1); |
3667 | if (!w) | |
3668 | return log_oom(); | |
4ad49000 | 3669 | |
c9f620bf | 3670 | w->path = TAKE_PTR(resolved); |
d53d9474 | 3671 | w->weight = u; |
4ad49000 | 3672 | |
71fda00f | 3673 | LIST_PREPEND(device_weights, c->blockio_device_weights, w); |
4ad49000 LP |
3674 | return 0; |
3675 | } | |
3676 | ||
3677 | int config_parse_blockio_bandwidth( | |
3678 | const char *unit, | |
3679 | const char *filename, | |
3680 | unsigned line, | |
3681 | const char *section, | |
71a61510 | 3682 | unsigned section_line, |
4ad49000 LP |
3683 | const char *lvalue, |
3684 | int ltype, | |
3685 | const char *rvalue, | |
3686 | void *data, | |
3687 | void *userdata) { | |
3688 | ||
c9f620bf | 3689 | _cleanup_free_ char *path = NULL, *resolved = NULL; |
979d0311 | 3690 | CGroupBlockIODeviceBandwidth *b = NULL, *t; |
4ad49000 | 3691 | CGroupContext *c = data; |
c9f620bf | 3692 | const char *p = rvalue; |
59f448cf | 3693 | uint64_t bytes; |
47c0980d | 3694 | bool read; |
4ad49000 LP |
3695 | int r; |
3696 | ||
3697 | assert(filename); | |
3698 | assert(lvalue); | |
3699 | assert(rvalue); | |
3700 | ||
47c0980d G |
3701 | read = streq("BlockIOReadBandwidth", lvalue); |
3702 | ||
4ad49000 | 3703 | if (isempty(rvalue)) { |
979d0311 TH |
3704 | LIST_FOREACH(device_bandwidths, b, c->blockio_device_bandwidths) { |
3705 | b->rbps = CGROUP_LIMIT_MAX; | |
3706 | b->wbps = CGROUP_LIMIT_MAX; | |
3707 | } | |
4ad49000 LP |
3708 | return 0; |
3709 | } | |
3710 | ||
c9f620bf YW |
3711 | r = extract_first_word(&p, &path, NULL, EXTRACT_QUOTES); |
3712 | if (r == -ENOMEM) | |
3713 | return log_oom(); | |
3714 | if (r < 0) { | |
3715 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3716 | "Invalid syntax, ignoring: %s", rvalue); | |
3717 | return 0; | |
3718 | } | |
3719 | if (r == 0 || isempty(p)) { | |
3720 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
3721 | "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue); | |
4ad49000 LP |
3722 | return 0; |
3723 | } | |
3724 | ||
c9f620bf YW |
3725 | r = unit_full_printf(userdata, path, &resolved); |
3726 | if (r < 0) { | |
3727 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3728 | "Failed to resolve unit specifiers in '%s', ignoring: %m", path); | |
3729 | return 0; | |
3730 | } | |
4ad49000 | 3731 | |
2f4d31c1 YW |
3732 | r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue); |
3733 | if (r < 0) | |
3734 | return 0; | |
3735 | ||
c9f620bf | 3736 | r = parse_size(p, 1000, &bytes); |
4ad49000 | 3737 | if (r < 0 || bytes <= 0) { |
c9f620bf | 3738 | log_syntax(unit, LOG_ERR, filename, line, r, "Invalid Block IO Bandwidth '%s', ignoring.", p); |
4ad49000 LP |
3739 | return 0; |
3740 | } | |
3741 | ||
979d0311 | 3742 | LIST_FOREACH(device_bandwidths, t, c->blockio_device_bandwidths) { |
c9f620bf | 3743 | if (path_equal(resolved, t->path)) { |
979d0311 TH |
3744 | b = t; |
3745 | break; | |
3746 | } | |
3747 | } | |
4ad49000 | 3748 | |
979d0311 TH |
3749 | if (!t) { |
3750 | b = new0(CGroupBlockIODeviceBandwidth, 1); | |
3751 | if (!b) | |
3752 | return log_oom(); | |
3753 | ||
c9f620bf | 3754 | b->path = TAKE_PTR(resolved); |
979d0311 TH |
3755 | b->rbps = CGROUP_LIMIT_MAX; |
3756 | b->wbps = CGROUP_LIMIT_MAX; | |
3757 | ||
3758 | LIST_PREPEND(device_bandwidths, c->blockio_device_bandwidths, b); | |
3759 | } | |
4ad49000 | 3760 | |
979d0311 TH |
3761 | if (read) |
3762 | b->rbps = bytes; | |
3763 | else | |
3764 | b->wbps = bytes; | |
4ad49000 LP |
3765 | |
3766 | return 0; | |
3767 | } | |
3768 | ||
d420282b LP |
3769 | int config_parse_job_mode_isolate( |
3770 | const char *unit, | |
3771 | const char *filename, | |
3772 | unsigned line, | |
3773 | const char *section, | |
3774 | unsigned section_line, | |
3775 | const char *lvalue, | |
3776 | int ltype, | |
3777 | const char *rvalue, | |
3778 | void *data, | |
3779 | void *userdata) { | |
3780 | ||
3781 | JobMode *m = data; | |
3782 | int r; | |
3783 | ||
3784 | assert(filename); | |
3785 | assert(lvalue); | |
3786 | assert(rvalue); | |
3787 | ||
3788 | r = parse_boolean(rvalue); | |
3789 | if (r < 0) { | |
12ca818f | 3790 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse boolean, ignoring: %s", rvalue); |
d420282b LP |
3791 | return 0; |
3792 | } | |
3793 | ||
8ab39347 YW |
3794 | log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue); |
3795 | ||
d420282b LP |
3796 | *m = r ? JOB_ISOLATE : JOB_REPLACE; |
3797 | return 0; | |
3798 | } | |
3799 | ||
3536f49e | 3800 | int config_parse_exec_directories( |
e66cf1a3 LP |
3801 | const char *unit, |
3802 | const char *filename, | |
3803 | unsigned line, | |
3804 | const char *section, | |
3805 | unsigned section_line, | |
3806 | const char *lvalue, | |
3807 | int ltype, | |
3808 | const char *rvalue, | |
3809 | void *data, | |
3810 | void *userdata) { | |
3811 | ||
a2a5291b | 3812 | char***rt = data; |
9b5864d9 | 3813 | Unit *u = userdata; |
035fe294 | 3814 | const char *p; |
e66cf1a3 LP |
3815 | int r; |
3816 | ||
3817 | assert(filename); | |
3818 | assert(lvalue); | |
3819 | assert(rvalue); | |
3820 | assert(data); | |
3821 | ||
3822 | if (isempty(rvalue)) { | |
3823 | /* Empty assignment resets the list */ | |
6796073e | 3824 | *rt = strv_free(*rt); |
e66cf1a3 LP |
3825 | return 0; |
3826 | } | |
3827 | ||
035fe294 ZJS |
3828 | for (p = rvalue;;) { |
3829 | _cleanup_free_ char *word = NULL, *k = NULL; | |
e66cf1a3 | 3830 | |
035fe294 | 3831 | r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES); |
035fe294 | 3832 | if (r == -ENOMEM) |
e66cf1a3 | 3833 | return log_oom(); |
035fe294 ZJS |
3834 | if (r < 0) { |
3835 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3836 | "Invalid syntax, ignoring: %s", rvalue); | |
3837 | return 0; | |
3838 | } | |
091e9efe LP |
3839 | if (r == 0) |
3840 | return 0; | |
e66cf1a3 | 3841 | |
18913df9 | 3842 | r = unit_full_printf(u, word, &k); |
9b5864d9 | 3843 | if (r < 0) { |
035fe294 | 3844 | log_syntax(unit, LOG_ERR, filename, line, r, |
063c4b1a | 3845 | "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word); |
9b5864d9 MG |
3846 | continue; |
3847 | } | |
3848 | ||
2f4d31c1 YW |
3849 | r = path_simplify_and_warn(k, PATH_CHECK_RELATIVE, unit, filename, line, lvalue); |
3850 | if (r < 0) | |
e8865688 | 3851 | continue; |
e8865688 LP |
3852 | |
3853 | if (path_startswith(k, "private")) { | |
3854 | log_syntax(unit, LOG_ERR, filename, line, 0, | |
4605de11 | 3855 | "%s= path can't be 'private', ignoring assignment: %s", lvalue, word); |
e66cf1a3 LP |
3856 | continue; |
3857 | } | |
3858 | ||
035fe294 | 3859 | r = strv_push(rt, k); |
e66cf1a3 LP |
3860 | if (r < 0) |
3861 | return log_oom(); | |
035fe294 | 3862 | k = NULL; |
e66cf1a3 | 3863 | } |
e66cf1a3 LP |
3864 | } |
3865 | ||
3af00fb8 LP |
3866 | int config_parse_set_status( |
3867 | const char *unit, | |
3868 | const char *filename, | |
3869 | unsigned line, | |
3870 | const char *section, | |
3871 | unsigned section_line, | |
3872 | const char *lvalue, | |
3873 | int ltype, | |
3874 | const char *rvalue, | |
3875 | void *data, | |
3876 | void *userdata) { | |
3877 | ||
3af00fb8 | 3878 | size_t l; |
a2a5291b | 3879 | const char *word, *state; |
3af00fb8 LP |
3880 | int r; |
3881 | ExitStatusSet *status_set = data; | |
3882 | ||
3883 | assert(filename); | |
3884 | assert(lvalue); | |
3885 | assert(rvalue); | |
3886 | assert(data); | |
3887 | ||
3e2d435b | 3888 | /* Empty assignment resets the list */ |
3af00fb8 | 3889 | if (isempty(rvalue)) { |
3e2d435b | 3890 | exit_status_set_free(status_set); |
3af00fb8 LP |
3891 | return 0; |
3892 | } | |
3893 | ||
a2a5291b | 3894 | FOREACH_WORD(word, l, rvalue, state) { |
3af00fb8 LP |
3895 | _cleanup_free_ char *temp; |
3896 | int val; | |
61593865 | 3897 | Set **set; |
3af00fb8 | 3898 | |
a2a5291b | 3899 | temp = strndup(word, l); |
3af00fb8 LP |
3900 | if (!temp) |
3901 | return log_oom(); | |
3902 | ||
3903 | r = safe_atoi(temp, &val); | |
3904 | if (r < 0) { | |
29a3db75 | 3905 | val = signal_from_string(temp); |
3af00fb8 | 3906 | |
1e2fd62d | 3907 | if (val <= 0) { |
12ca818f | 3908 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse value, ignoring: %s", word); |
61593865 | 3909 | continue; |
3af00fb8 | 3910 | } |
61593865 | 3911 | set = &status_set->signal; |
3af00fb8 | 3912 | } else { |
1e2fd62d | 3913 | if (val < 0 || val > 255) { |
12ca818f | 3914 | log_syntax(unit, LOG_ERR, filename, line, 0, "Value %d is outside range 0-255, ignoring", val); |
1e2fd62d | 3915 | continue; |
3af00fb8 | 3916 | } |
61593865 | 3917 | set = &status_set->status; |
3af00fb8 | 3918 | } |
1e2fd62d | 3919 | |
61593865 | 3920 | r = set_ensure_allocated(set, NULL); |
1e2fd62d ZJS |
3921 | if (r < 0) |
3922 | return log_oom(); | |
3923 | ||
61593865 | 3924 | r = set_put(*set, INT_TO_PTR(val)); |
063c4b1a YW |
3925 | if (r < 0) |
3926 | return log_oom(); | |
3af00fb8 | 3927 | } |
b2fadec6 | 3928 | if (!isempty(state)) |
12ca818f | 3929 | log_syntax(unit, LOG_ERR, filename, line, 0, "Trailing garbage, ignoring."); |
3af00fb8 LP |
3930 | |
3931 | return 0; | |
3932 | } | |
3933 | ||
94828d2d LP |
3934 | int config_parse_namespace_path_strv( |
3935 | const char *unit, | |
3936 | const char *filename, | |
3937 | unsigned line, | |
3938 | const char *section, | |
3939 | unsigned section_line, | |
3940 | const char *lvalue, | |
3941 | int ltype, | |
3942 | const char *rvalue, | |
3943 | void *data, | |
3944 | void *userdata) { | |
3945 | ||
7b07e993 | 3946 | Unit *u = userdata; |
a2a5291b | 3947 | char*** sv = data; |
063c4b1a | 3948 | const char *p = rvalue; |
94828d2d LP |
3949 | int r; |
3950 | ||
3951 | assert(filename); | |
3952 | assert(lvalue); | |
3953 | assert(rvalue); | |
3954 | assert(data); | |
3955 | ||
3956 | if (isempty(rvalue)) { | |
3957 | /* Empty assignment resets the list */ | |
6796073e | 3958 | *sv = strv_free(*sv); |
94828d2d LP |
3959 | return 0; |
3960 | } | |
3961 | ||
727f76d7 | 3962 | for (;;) { |
7b07e993 | 3963 | _cleanup_free_ char *word = NULL, *resolved = NULL, *joined = NULL; |
20b7a007 LP |
3964 | const char *w; |
3965 | bool ignore_enoent = false, shall_prefix = false; | |
94828d2d | 3966 | |
063c4b1a | 3967 | r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES); |
0293a7a8 EV |
3968 | if (r == 0) |
3969 | break; | |
3970 | if (r == -ENOMEM) | |
3971 | return log_oom(); | |
727f76d7 | 3972 | if (r < 0) { |
7b07e993 | 3973 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to extract first word, ignoring: %s", rvalue); |
727f76d7 EV |
3974 | return 0; |
3975 | } | |
94828d2d | 3976 | |
20b7a007 LP |
3977 | w = word; |
3978 | if (startswith(w, "-")) { | |
3979 | ignore_enoent = true; | |
3980 | w++; | |
3981 | } | |
3982 | if (startswith(w, "+")) { | |
3983 | shall_prefix = true; | |
3984 | w++; | |
3985 | } | |
7b07e993 | 3986 | |
20b7a007 | 3987 | r = unit_full_printf(u, w, &resolved); |
7b07e993 | 3988 | if (r < 0) { |
063c4b1a | 3989 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s: %m", w); |
94828d2d LP |
3990 | continue; |
3991 | } | |
3992 | ||
2f4d31c1 YW |
3993 | r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
3994 | if (r < 0) | |
7b07e993 | 3995 | continue; |
94828d2d | 3996 | |
20b7a007 LP |
3997 | joined = strjoin(ignore_enoent ? "-" : "", |
3998 | shall_prefix ? "+" : "", | |
3999 | resolved); | |
7b07e993 LP |
4000 | |
4001 | r = strv_push(sv, joined); | |
94828d2d LP |
4002 | if (r < 0) |
4003 | return log_oom(); | |
4004 | ||
7b07e993 | 4005 | joined = NULL; |
94828d2d LP |
4006 | } |
4007 | ||
4008 | return 0; | |
4009 | } | |
4010 | ||
2abd4e38 YW |
4011 | int config_parse_temporary_filesystems( |
4012 | const char *unit, | |
4013 | const char *filename, | |
4014 | unsigned line, | |
4015 | const char *section, | |
4016 | unsigned section_line, | |
4017 | const char *lvalue, | |
4018 | int ltype, | |
4019 | const char *rvalue, | |
4020 | void *data, | |
4021 | void *userdata) { | |
4022 | ||
4023 | Unit *u = userdata; | |
4024 | ExecContext *c = data; | |
063c4b1a | 4025 | const char *p = rvalue; |
2abd4e38 YW |
4026 | int r; |
4027 | ||
4028 | assert(filename); | |
4029 | assert(lvalue); | |
4030 | assert(rvalue); | |
4031 | assert(data); | |
4032 | ||
4033 | if (isempty(rvalue)) { | |
4034 | /* Empty assignment resets the list */ | |
4035 | temporary_filesystem_free_many(c->temporary_filesystems, c->n_temporary_filesystems); | |
4036 | c->temporary_filesystems = NULL; | |
4037 | c->n_temporary_filesystems = 0; | |
4038 | return 0; | |
4039 | } | |
4040 | ||
2abd4e38 YW |
4041 | for (;;) { |
4042 | _cleanup_free_ char *word = NULL, *path = NULL, *resolved = NULL; | |
4043 | const char *w; | |
4044 | ||
063c4b1a | 4045 | r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES); |
2abd4e38 | 4046 | if (r == 0) |
063c4b1a | 4047 | return 0; |
2abd4e38 YW |
4048 | if (r == -ENOMEM) |
4049 | return log_oom(); | |
4050 | if (r < 0) { | |
4051 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to extract first word, ignoring: %s", rvalue); | |
4052 | return 0; | |
4053 | } | |
4054 | ||
4055 | w = word; | |
4056 | r = extract_first_word(&w, &path, ":", EXTRACT_DONT_COALESCE_SEPARATORS); | |
063c4b1a YW |
4057 | if (r == -ENOMEM) |
4058 | return log_oom(); | |
4059 | if (r < 0) { | |
4060 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to extract first word, ignoring: %s", word); | |
4061 | continue; | |
4062 | } | |
4063 | if (r == 0) { | |
4064 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid syntax, ignoring: %s", word); | |
4065 | continue; | |
4066 | } | |
2abd4e38 YW |
4067 | |
4068 | r = unit_full_printf(u, path, &resolved); | |
4069 | if (r < 0) { | |
063c4b1a | 4070 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", path); |
2abd4e38 YW |
4071 | continue; |
4072 | } | |
4073 | ||
2f4d31c1 YW |
4074 | r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
4075 | if (r < 0) | |
2abd4e38 | 4076 | continue; |
2abd4e38 | 4077 | |
a26fec24 | 4078 | r = temporary_filesystem_add(&c->temporary_filesystems, &c->n_temporary_filesystems, resolved, w); |
6302d1ea | 4079 | if (r < 0) |
2abd4e38 | 4080 | return log_oom(); |
2abd4e38 | 4081 | } |
2abd4e38 YW |
4082 | } |
4083 | ||
d2d6c096 LP |
4084 | int config_parse_bind_paths( |
4085 | const char *unit, | |
4086 | const char *filename, | |
4087 | unsigned line, | |
4088 | const char *section, | |
4089 | unsigned section_line, | |
4090 | const char *lvalue, | |
4091 | int ltype, | |
4092 | const char *rvalue, | |
4093 | void *data, | |
4094 | void *userdata) { | |
4095 | ||
4096 | ExecContext *c = data; | |
42d43f21 | 4097 | Unit *u = userdata; |
d2d6c096 LP |
4098 | const char *p; |
4099 | int r; | |
4100 | ||
4101 | assert(filename); | |
4102 | assert(lvalue); | |
4103 | assert(rvalue); | |
4104 | assert(data); | |
4105 | ||
4106 | if (isempty(rvalue)) { | |
4107 | /* Empty assignment resets the list */ | |
4108 | bind_mount_free_many(c->bind_mounts, c->n_bind_mounts); | |
4109 | c->bind_mounts = NULL; | |
4110 | c->n_bind_mounts = 0; | |
4111 | return 0; | |
4112 | } | |
4113 | ||
4114 | p = rvalue; | |
4115 | for (;;) { | |
4116 | _cleanup_free_ char *source = NULL, *destination = NULL; | |
42d43f21 | 4117 | _cleanup_free_ char *sresolved = NULL, *dresolved = NULL; |
d2d6c096 LP |
4118 | char *s = NULL, *d = NULL; |
4119 | bool rbind = true, ignore_enoent = false; | |
4120 | ||
4121 | r = extract_first_word(&p, &source, ":" WHITESPACE, EXTRACT_QUOTES|EXTRACT_DONT_COALESCE_SEPARATORS); | |
4122 | if (r == 0) | |
4123 | break; | |
4124 | if (r == -ENOMEM) | |
4125 | return log_oom(); | |
4126 | if (r < 0) { | |
2f4d31c1 | 4127 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse %s, ignoring: %s", lvalue, rvalue); |
d2d6c096 LP |
4128 | return 0; |
4129 | } | |
4130 | ||
42d43f21 DC |
4131 | r = unit_full_printf(u, source, &sresolved); |
4132 | if (r < 0) { | |
4133 | log_syntax(unit, LOG_ERR, filename, line, r, | |
063c4b1a | 4134 | "Failed to resolved unit specifiers in \"%s\", ignoring: %m", source); |
2f4d31c1 | 4135 | continue; |
42d43f21 DC |
4136 | } |
4137 | ||
4138 | s = sresolved; | |
d2d6c096 LP |
4139 | if (s[0] == '-') { |
4140 | ignore_enoent = true; | |
4141 | s++; | |
4142 | } | |
4143 | ||
2f4d31c1 YW |
4144 | r = path_simplify_and_warn(s, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
4145 | if (r < 0) | |
4146 | continue; | |
d2d6c096 LP |
4147 | |
4148 | /* Optionally, the destination is specified. */ | |
4149 | if (p && p[-1] == ':') { | |
4150 | r = extract_first_word(&p, &destination, ":" WHITESPACE, EXTRACT_QUOTES|EXTRACT_DONT_COALESCE_SEPARATORS); | |
4151 | if (r == -ENOMEM) | |
4152 | return log_oom(); | |
4153 | if (r < 0) { | |
2f4d31c1 | 4154 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse %s, ignoring: %s", lvalue, rvalue); |
d2d6c096 LP |
4155 | return 0; |
4156 | } | |
4157 | if (r == 0) { | |
2f4d31c1 YW |
4158 | log_syntax(unit, LOG_ERR, filename, line, 0, "Missing argument after ':', ignoring: %s", s); |
4159 | continue; | |
d2d6c096 LP |
4160 | } |
4161 | ||
42d43f21 DC |
4162 | r = unit_full_printf(u, destination, &dresolved); |
4163 | if (r < 0) { | |
4164 | log_syntax(unit, LOG_ERR, filename, line, r, | |
4165 | "Failed to resolved specifiers in \"%s\", ignoring: %m", destination); | |
2f4d31c1 | 4166 | continue; |
42d43f21 DC |
4167 | } |
4168 | ||
2f4d31c1 YW |
4169 | r = path_simplify_and_warn(dresolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
4170 | if (r < 0) | |
4171 | continue; | |
d2d6c096 | 4172 | |
2f4d31c1 | 4173 | d = dresolved; |
d2d6c096 LP |
4174 | |
4175 | /* Optionally, there's also a short option string specified */ | |
4176 | if (p && p[-1] == ':') { | |
4177 | _cleanup_free_ char *options = NULL; | |
4178 | ||
4179 | r = extract_first_word(&p, &options, NULL, EXTRACT_QUOTES); | |
4180 | if (r == -ENOMEM) | |
4181 | return log_oom(); | |
4182 | if (r < 0) { | |
4183 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse %s: %s", lvalue, rvalue); | |
4184 | return 0; | |
4185 | } | |
4186 | ||
4187 | if (isempty(options) || streq(options, "rbind")) | |
4188 | rbind = true; | |
4189 | else if (streq(options, "norbind")) | |
4190 | rbind = false; | |
4191 | else { | |
4192 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid option string, ignoring setting: %s", options); | |
2f4d31c1 | 4193 | continue; |
d2d6c096 LP |
4194 | } |
4195 | } | |
4196 | } else | |
4197 | d = s; | |
4198 | ||
4199 | r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts, | |
4200 | &(BindMount) { | |
4201 | .source = s, | |
4202 | .destination = d, | |
4203 | .read_only = !!strstr(lvalue, "ReadOnly"), | |
4204 | .recursive = rbind, | |
4205 | .ignore_enoent = ignore_enoent, | |
4206 | }); | |
4207 | if (r < 0) | |
4208 | return log_oom(); | |
4209 | } | |
4210 | ||
4211 | return 0; | |
4212 | } | |
4213 | ||
eae51da3 LP |
4214 | int config_parse_job_timeout_sec( |
4215 | const char* unit, | |
4216 | const char *filename, | |
4217 | unsigned line, | |
4218 | const char *section, | |
4219 | unsigned section_line, | |
4220 | const char *lvalue, | |
4221 | int ltype, | |
4222 | const char *rvalue, | |
4223 | void *data, | |
4224 | void *userdata) { | |
4225 | ||
4226 | Unit *u = data; | |
4227 | usec_t usec; | |
4228 | int r; | |
4229 | ||
4230 | assert(filename); | |
4231 | assert(lvalue); | |
4232 | assert(rvalue); | |
4233 | assert(u); | |
4234 | ||
4235 | r = parse_sec_fix_0(rvalue, &usec); | |
4236 | if (r < 0) { | |
4237 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue); | |
4238 | return 0; | |
4239 | } | |
4240 | ||
4241 | /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old | |
c05f3c8f | 4242 | * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should |
eae51da3 LP |
4243 | * count. */ |
4244 | ||
4245 | if (!u->job_running_timeout_set) | |
4246 | u->job_running_timeout = usec; | |
4247 | ||
4248 | u->job_timeout = usec; | |
4249 | ||
4250 | return 0; | |
4251 | } | |
4252 | ||
4253 | int config_parse_job_running_timeout_sec( | |
4254 | const char* unit, | |
4255 | const char *filename, | |
4256 | unsigned line, | |
4257 | const char *section, | |
4258 | unsigned section_line, | |
4259 | const char *lvalue, | |
4260 | int ltype, | |
4261 | const char *rvalue, | |
4262 | void *data, | |
4263 | void *userdata) { | |
4264 | ||
4265 | Unit *u = data; | |
4266 | usec_t usec; | |
4267 | int r; | |
4268 | ||
4269 | assert(filename); | |
4270 | assert(lvalue); | |
4271 | assert(rvalue); | |
4272 | assert(u); | |
4273 | ||
4274 | r = parse_sec_fix_0(rvalue, &usec); | |
4275 | if (r < 0) { | |
4276 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue); | |
4277 | return 0; | |
4278 | } | |
4279 | ||
4280 | u->job_running_timeout = usec; | |
4281 | u->job_running_timeout_set = true; | |
4282 | ||
4283 | return 0; | |
4284 | } | |
4285 | ||
54fcb619 ZJS |
4286 | int config_parse_emergency_action( |
4287 | const char* unit, | |
4288 | const char *filename, | |
4289 | unsigned line, | |
4290 | const char *section, | |
4291 | unsigned section_line, | |
4292 | const char *lvalue, | |
4293 | int ltype, | |
4294 | const char *rvalue, | |
4295 | void *data, | |
4296 | void *userdata) { | |
4297 | ||
4298 | Manager *m = NULL; | |
4299 | EmergencyAction *x = data; | |
4300 | int r; | |
4301 | ||
4302 | assert(filename); | |
4303 | assert(lvalue); | |
4304 | assert(rvalue); | |
4305 | assert(data); | |
4306 | ||
4307 | if (unit) | |
4308 | m = ((Unit*) userdata)->manager; | |
4309 | else | |
4310 | m = data; | |
4311 | ||
4312 | r = parse_emergency_action(rvalue, MANAGER_IS_SYSTEM(m), x); | |
4313 | if (r < 0) { | |
469f76f1 ZJS |
4314 | if (r == -EOPNOTSUPP && MANAGER_IS_USER(m)) { |
4315 | /* Compat mode: remove for systemd 241. */ | |
4316 | ||
4317 | log_syntax(unit, LOG_INFO, filename, line, r, | |
4318 | "%s= in user mode specified as \"%s\", using \"exit-force\" instead.", | |
4319 | lvalue, rvalue); | |
4320 | *x = EMERGENCY_ACTION_EXIT_FORCE; | |
4321 | return 0; | |
4322 | } | |
4323 | ||
54fcb619 ZJS |
4324 | if (r == -EOPNOTSUPP) |
4325 | log_syntax(unit, LOG_ERR, filename, line, r, | |
4326 | "%s= specified as %s mode action, ignoring: %s", | |
4327 | lvalue, MANAGER_IS_SYSTEM(m) ? "user" : "system", rvalue); | |
4328 | else | |
4329 | log_syntax(unit, LOG_ERR, filename, line, r, | |
4330 | "Failed to parse %s=, ignoring: %s", lvalue, rvalue); | |
4331 | return 0; | |
4332 | } | |
4333 | ||
4334 | return 0; | |
4335 | } | |
4336 | ||
a9353a5c LP |
4337 | int config_parse_pid_file( |
4338 | const char *unit, | |
4339 | const char *filename, | |
4340 | unsigned line, | |
4341 | const char *section, | |
4342 | unsigned section_line, | |
4343 | const char *lvalue, | |
4344 | int ltype, | |
4345 | const char *rvalue, | |
4346 | void *data, | |
4347 | void *userdata) { | |
4348 | ||
4349 | _cleanup_free_ char *k = NULL, *n = NULL; | |
4350 | Unit *u = userdata; | |
4351 | char **s = data; | |
a9353a5c LP |
4352 | int r; |
4353 | ||
4354 | assert(filename); | |
4355 | assert(lvalue); | |
4356 | assert(rvalue); | |
4357 | assert(u); | |
4358 | ||
b8055c05 YW |
4359 | if (isempty(rvalue)) { |
4360 | /* An empty assignment removes already set value. */ | |
4361 | *s = mfree(*s); | |
4362 | return 0; | |
4363 | } | |
4364 | ||
a9353a5c LP |
4365 | r = unit_full_printf(u, rvalue, &k); |
4366 | if (r < 0) { | |
4367 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); | |
4368 | return 0; | |
4369 | } | |
4370 | ||
4371 | /* If this is a relative path make it absolute by prefixing the /run */ | |
4372 | n = path_make_absolute(k, u->manager->prefix[EXEC_DIRECTORY_RUNTIME]); | |
4373 | if (!n) | |
4374 | return log_oom(); | |
4375 | ||
4376 | /* Check that the result is a sensible path */ | |
4377 | r = path_simplify_and_warn(n, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); | |
4378 | if (r < 0) | |
4379 | return r; | |
4380 | ||
4a66b5c9 LP |
4381 | r = patch_var_run(unit, filename, line, lvalue, &n); |
4382 | if (r < 0) | |
4383 | return r; | |
a9353a5c | 4384 | |
4a66b5c9 | 4385 | free_and_replace(*s, n); |
a9353a5c LP |
4386 | return 0; |
4387 | } | |
4388 | ||
7af67e9a LP |
4389 | int config_parse_exit_status( |
4390 | const char *unit, | |
4391 | const char *filename, | |
4392 | unsigned line, | |
4393 | const char *section, | |
4394 | unsigned section_line, | |
4395 | const char *lvalue, | |
4396 | int ltype, | |
4397 | const char *rvalue, | |
4398 | void *data, | |
4399 | void *userdata) { | |
4400 | ||
4401 | int *exit_status = data, r; | |
4402 | uint8_t u; | |
4403 | ||
4404 | assert(filename); | |
4405 | assert(lvalue); | |
4406 | assert(rvalue); | |
4407 | assert(exit_status); | |
4408 | ||
4409 | if (isempty(rvalue)) { | |
4410 | *exit_status = -1; | |
4411 | return 0; | |
4412 | } | |
4413 | ||
4414 | r = safe_atou8(rvalue, &u); | |
4415 | if (r < 0) { | |
4416 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse exit status '%s', ignoring: %m", rvalue); | |
4417 | return 0; | |
4418 | } | |
4419 | ||
4420 | *exit_status = u; | |
4421 | return 0; | |
4422 | } | |
4423 | ||
c72703e2 CD |
4424 | int config_parse_disable_controllers( |
4425 | const char *unit, | |
4426 | const char *filename, | |
4427 | unsigned line, | |
4428 | const char *section, | |
4429 | unsigned section_line, | |
4430 | const char *lvalue, | |
4431 | int ltype, | |
4432 | const char *rvalue, | |
4433 | void *data, | |
4434 | void *userdata) { | |
4435 | ||
4436 | int r; | |
4437 | CGroupContext *c = data; | |
4438 | CGroupMask disabled_mask; | |
4439 | ||
4440 | /* 1. If empty, make all controllers eligible for use again. | |
4441 | * 2. If non-empty, merge all listed controllers, space separated. */ | |
4442 | ||
4443 | if (isempty(rvalue)) { | |
4444 | c->disable_controllers = 0; | |
4445 | return 0; | |
4446 | } | |
4447 | ||
4448 | r = cg_mask_from_string(rvalue, &disabled_mask); | |
4449 | if (r < 0 || disabled_mask <= 0) { | |
4450 | log_syntax(unit, LOG_ERR, filename, line, r, "Invalid cgroup string: %s, ignoring", rvalue); | |
4451 | return 0; | |
4452 | } | |
4453 | ||
4454 | c->disable_controllers |= disabled_mask; | |
4455 | ||
4456 | return 0; | |
4457 | } | |
4458 | ||
071830ff | 4459 | #define FOLLOW_MAX 8 |
87f0e418 | 4460 | |
9e2f7c11 | 4461 | static int open_follow(char **filename, FILE **_f, Set *names, char **_final) { |
a837f088 | 4462 | char *id = NULL; |
0301abf4 | 4463 | unsigned c = 0; |
87f0e418 LP |
4464 | int fd, r; |
4465 | FILE *f; | |
87f0e418 LP |
4466 | |
4467 | assert(filename); | |
4468 | assert(*filename); | |
4469 | assert(_f); | |
4470 | assert(names); | |
4471 | ||
0301abf4 LP |
4472 | /* This will update the filename pointer if the loaded file is |
4473 | * reached by a symlink. The old string will be freed. */ | |
87f0e418 | 4474 | |
0301abf4 | 4475 | for (;;) { |
2c7108c4 | 4476 | char *target, *name; |
87f0e418 | 4477 | |
0301abf4 LP |
4478 | if (c++ >= FOLLOW_MAX) |
4479 | return -ELOOP; | |
4480 | ||
858d36c1 | 4481 | path_simplify(*filename, false); |
b08d03ff | 4482 | |
87f0e418 | 4483 | /* Add the file name we are currently looking at to |
8f05424d LP |
4484 | * the names of this unit, but only if it is a valid |
4485 | * unit name. */ | |
2b6bf07d | 4486 | name = basename(*filename); |
7410616c | 4487 | if (unit_name_is_valid(name, UNIT_NAME_ANY)) { |
8f05424d | 4488 | |
15e11d81 LP |
4489 | id = set_get(names, name); |
4490 | if (!id) { | |
4491 | id = strdup(name); | |
4492 | if (!id) | |
8f05424d | 4493 | return -ENOMEM; |
87f0e418 | 4494 | |
ef42202a ZJS |
4495 | r = set_consume(names, id); |
4496 | if (r < 0) | |
8f05424d | 4497 | return r; |
87f0e418 | 4498 | } |
87f0e418 LP |
4499 | } |
4500 | ||
0301abf4 | 4501 | /* Try to open the file name, but don't if its a symlink */ |
9946996c LP |
4502 | fd = open(*filename, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW); |
4503 | if (fd >= 0) | |
87f0e418 LP |
4504 | break; |
4505 | ||
0301abf4 LP |
4506 | if (errno != ELOOP) |
4507 | return -errno; | |
4508 | ||
87f0e418 | 4509 | /* Hmm, so this is a symlink. Let's read the name, and follow it manually */ |
9946996c LP |
4510 | r = readlink_and_make_absolute(*filename, &target); |
4511 | if (r < 0) | |
0301abf4 | 4512 | return r; |
87f0e418 | 4513 | |
17ee3d72 | 4514 | free_and_replace(*filename, target); |
87f0e418 LP |
4515 | } |
4516 | ||
e92aaed3 | 4517 | f = fdopen(fd, "r"); |
9946996c | 4518 | if (!f) { |
03e334a1 | 4519 | safe_close(fd); |
d4ad27a1 | 4520 | return -errno; |
87f0e418 LP |
4521 | } |
4522 | ||
4523 | *_f = f; | |
9e2f7c11 | 4524 | *_final = id; |
a837f088 | 4525 | |
0301abf4 | 4526 | return 0; |
87f0e418 LP |
4527 | } |
4528 | ||
23a177ef LP |
4529 | static int merge_by_names(Unit **u, Set *names, const char *id) { |
4530 | char *k; | |
4531 | int r; | |
4532 | ||
4533 | assert(u); | |
4534 | assert(*u); | |
4535 | assert(names); | |
4536 | ||
4537 | /* Let's try to add in all symlink names we found */ | |
4538 | while ((k = set_steal_first(names))) { | |
4539 | ||
4540 | /* First try to merge in the other name into our | |
4541 | * unit */ | |
9946996c LP |
4542 | r = unit_merge_by_name(*u, k); |
4543 | if (r < 0) { | |
23a177ef LP |
4544 | Unit *other; |
4545 | ||
4546 | /* Hmm, we couldn't merge the other unit into | |
4547 | * ours? Then let's try it the other way | |
4548 | * round */ | |
4549 | ||
7aad67e7 MS |
4550 | /* If the symlink name we are looking at is unit template, then |
4551 | we must search for instance of this template */ | |
9d3e3406 | 4552 | if (unit_name_is_valid(k, UNIT_NAME_TEMPLATE) && (*u)->instance) { |
7aad67e7 MS |
4553 | _cleanup_free_ char *instance = NULL; |
4554 | ||
4555 | r = unit_name_replace_instance(k, (*u)->instance, &instance); | |
4556 | if (r < 0) | |
4557 | return r; | |
4558 | ||
4559 | other = manager_get_unit((*u)->manager, instance); | |
4560 | } else | |
4561 | other = manager_get_unit((*u)->manager, k); | |
4562 | ||
23a177ef LP |
4563 | free(k); |
4564 | ||
9946996c LP |
4565 | if (other) { |
4566 | r = unit_merge(other, *u); | |
4567 | if (r >= 0) { | |
23a177ef LP |
4568 | *u = other; |
4569 | return merge_by_names(u, names, NULL); | |
4570 | } | |
9946996c | 4571 | } |
23a177ef LP |
4572 | |
4573 | return r; | |
4574 | } | |
4575 | ||
4576 | if (id == k) | |
4577 | unit_choose_id(*u, id); | |
4578 | ||
4579 | free(k); | |
4580 | } | |
4581 | ||
4582 | return 0; | |
4583 | } | |
4584 | ||
e537352b | 4585 | static int load_from_path(Unit *u, const char *path) { |
e48614c4 ZJS |
4586 | _cleanup_set_free_free_ Set *symlink_names = NULL; |
4587 | _cleanup_fclose_ FILE *f = NULL; | |
4588 | _cleanup_free_ char *filename = NULL; | |
4589 | char *id = NULL; | |
23a177ef | 4590 | Unit *merged; |
45fb0699 | 4591 | struct stat st; |
a837f088 | 4592 | int r; |
23a177ef LP |
4593 | |
4594 | assert(u); | |
e537352b | 4595 | assert(path); |
3efd4195 | 4596 | |
d5099efc | 4597 | symlink_names = set_new(&string_hash_ops); |
f975e971 | 4598 | if (!symlink_names) |
87f0e418 | 4599 | return -ENOMEM; |
3efd4195 | 4600 | |
036643a2 LP |
4601 | if (path_is_absolute(path)) { |
4602 | ||
9946996c | 4603 | filename = strdup(path); |
e48614c4 ZJS |
4604 | if (!filename) |
4605 | return -ENOMEM; | |
036643a2 | 4606 | |
9946996c LP |
4607 | r = open_follow(&filename, &f, symlink_names, &id); |
4608 | if (r < 0) { | |
97b11eed | 4609 | filename = mfree(filename); |
036643a2 | 4610 | if (r != -ENOENT) |
e48614c4 | 4611 | return r; |
036643a2 LP |
4612 | } |
4613 | ||
4614 | } else { | |
4615 | char **p; | |
4616 | ||
a3c4eb07 | 4617 | STRV_FOREACH(p, u->manager->lookup_paths.search_path) { |
036643a2 LP |
4618 | |
4619 | /* Instead of opening the path right away, we manually | |
4620 | * follow all symlinks and add their name to our unit | |
4621 | * name set while doing so */ | |
9946996c | 4622 | filename = path_make_absolute(path, *p); |
e48614c4 ZJS |
4623 | if (!filename) |
4624 | return -ENOMEM; | |
036643a2 | 4625 | |
ac155bb8 MS |
4626 | if (u->manager->unit_path_cache && |
4627 | !set_get(u->manager->unit_path_cache, filename)) | |
fe51822e LP |
4628 | r = -ENOENT; |
4629 | else | |
4630 | r = open_follow(&filename, &f, symlink_names, &id); | |
a837f088 LP |
4631 | if (r >= 0) |
4632 | break; | |
a1feacf7 ZJS |
4633 | |
4634 | /* ENOENT means that the file is missing or is a dangling symlink. | |
4635 | * ENOTDIR means that one of paths we expect to be is a directory | |
4636 | * is not a directory, we should just ignore that. | |
4637 | * EACCES means that the directory or file permissions are wrong. | |
4638 | */ | |
4639 | if (r == -EACCES) | |
4640 | log_debug_errno(r, "Cannot access \"%s\": %m", filename); | |
4641 | else if (!IN_SET(r, -ENOENT, -ENOTDIR)) | |
a837f088 | 4642 | return r; |
fe51822e | 4643 | |
baa162ce | 4644 | filename = mfree(filename); |
a837f088 LP |
4645 | /* Empty the symlink names for the next run */ |
4646 | set_clear_free(symlink_names); | |
036643a2 LP |
4647 | } |
4648 | } | |
034c6ed7 | 4649 | |
e48614c4 | 4650 | if (!filename) |
8f05424d | 4651 | /* Hmm, no suitable file found? */ |
e48614c4 | 4652 | return 0; |
87f0e418 | 4653 | |
8a993b61 | 4654 | if (!unit_type_may_alias(u->type) && set_size(symlink_names) > 1) { |
a837f088 LP |
4655 | log_unit_warning(u, "Unit type of %s does not support alias names, refusing loading via symlink.", u->id); |
4656 | return -ELOOP; | |
4657 | } | |
4658 | ||
23a177ef | 4659 | merged = u; |
9946996c LP |
4660 | r = merge_by_names(&merged, symlink_names, id); |
4661 | if (r < 0) | |
e48614c4 | 4662 | return r; |
87f0e418 | 4663 | |
23a177ef | 4664 | if (merged != u) { |
ac155bb8 | 4665 | u->load_state = UNIT_MERGED; |
e48614c4 | 4666 | return 0; |
034c6ed7 LP |
4667 | } |
4668 | ||
e48614c4 ZJS |
4669 | if (fstat(fileno(f), &st) < 0) |
4670 | return -errno; | |
45fb0699 | 4671 | |
3a8db9fe | 4672 | if (null_or_empty(&st)) { |
ac155bb8 | 4673 | u->load_state = UNIT_MASKED; |
3a8db9fe ZJS |
4674 | u->fragment_mtime = 0; |
4675 | } else { | |
c2756a68 | 4676 | u->load_state = UNIT_LOADED; |
3a8db9fe | 4677 | u->fragment_mtime = timespec_load(&st.st_mtim); |
c2756a68 | 4678 | |
00dc5d76 | 4679 | /* Now, parse the file contents */ |
36f822c4 ZJS |
4680 | r = config_parse(u->id, filename, f, |
4681 | UNIT_VTABLE(u)->sections, | |
4682 | config_item_perf_lookup, load_fragment_gperf_lookup, | |
bcde742e | 4683 | CONFIG_PARSE_ALLOW_INCLUDE, u); |
f975e971 | 4684 | if (r < 0) |
e48614c4 | 4685 | return r; |
00dc5d76 | 4686 | } |
b08d03ff | 4687 | |
1cc6c93a | 4688 | free_and_replace(u->fragment_path, filename); |
87f0e418 | 4689 | |
1b64d026 LP |
4690 | if (u->source_path) { |
4691 | if (stat(u->source_path, &st) >= 0) | |
4692 | u->source_mtime = timespec_load(&st.st_mtim); | |
4693 | else | |
4694 | u->source_mtime = 0; | |
4695 | } | |
4696 | ||
e48614c4 | 4697 | return 0; |
0301abf4 LP |
4698 | } |
4699 | ||
e537352b | 4700 | int unit_load_fragment(Unit *u) { |
23a177ef | 4701 | int r; |
294d81f1 LP |
4702 | Iterator i; |
4703 | const char *t; | |
0301abf4 LP |
4704 | |
4705 | assert(u); | |
ac155bb8 MS |
4706 | assert(u->load_state == UNIT_STUB); |
4707 | assert(u->id); | |
23a177ef | 4708 | |
3f5e8115 LP |
4709 | if (u->transient) { |
4710 | u->load_state = UNIT_LOADED; | |
4711 | return 0; | |
4712 | } | |
4713 | ||
294d81f1 LP |
4714 | /* First, try to find the unit under its id. We always look |
4715 | * for unit files in the default directories, to make it easy | |
4716 | * to override things by placing things in /etc/systemd/system */ | |
9946996c LP |
4717 | r = load_from_path(u, u->id); |
4718 | if (r < 0) | |
294d81f1 LP |
4719 | return r; |
4720 | ||
4721 | /* Try to find an alias we can load this with */ | |
abc08d4d | 4722 | if (u->load_state == UNIT_STUB) { |
ac155bb8 | 4723 | SET_FOREACH(t, u->names, i) { |
294d81f1 | 4724 | |
ac155bb8 | 4725 | if (t == u->id) |
294d81f1 LP |
4726 | continue; |
4727 | ||
9946996c LP |
4728 | r = load_from_path(u, t); |
4729 | if (r < 0) | |
294d81f1 LP |
4730 | return r; |
4731 | ||
ac155bb8 | 4732 | if (u->load_state != UNIT_STUB) |
294d81f1 LP |
4733 | break; |
4734 | } | |
abc08d4d | 4735 | } |
23a177ef | 4736 | |
294d81f1 | 4737 | /* And now, try looking for it under the suggested (originally linked) path */ |
ac155bb8 | 4738 | if (u->load_state == UNIT_STUB && u->fragment_path) { |
6ccb1b44 | 4739 | |
9946996c LP |
4740 | r = load_from_path(u, u->fragment_path); |
4741 | if (r < 0) | |
23a177ef | 4742 | return r; |
0301abf4 | 4743 | |
ece174c5 | 4744 | if (u->load_state == UNIT_STUB) |
6ccb1b44 LP |
4745 | /* Hmm, this didn't work? Then let's get rid |
4746 | * of the fragment path stored for us, so that | |
4747 | * we don't point to an invalid location. */ | |
a1e58e8e | 4748 | u->fragment_path = mfree(u->fragment_path); |
6ccb1b44 LP |
4749 | } |
4750 | ||
294d81f1 | 4751 | /* Look for a template */ |
ac155bb8 | 4752 | if (u->load_state == UNIT_STUB && u->instance) { |
7410616c | 4753 | _cleanup_free_ char *k = NULL; |
294d81f1 | 4754 | |
7410616c LP |
4755 | r = unit_name_template(u->id, &k); |
4756 | if (r < 0) | |
4757 | return r; | |
294d81f1 LP |
4758 | |
4759 | r = load_from_path(u, k); | |
bb28e684 ZJS |
4760 | if (r < 0) { |
4761 | if (r == -ENOEXEC) | |
4762 | log_unit_notice(u, "Unit configuration has fatal error, unit will not be started."); | |
9e2f7c11 | 4763 | return r; |
bb28e684 | 4764 | } |
890f434c | 4765 | |
abc08d4d | 4766 | if (u->load_state == UNIT_STUB) { |
ac155bb8 | 4767 | SET_FOREACH(t, u->names, i) { |
bc9fd78c | 4768 | _cleanup_free_ char *z = NULL; |
87f0e418 | 4769 | |
ac155bb8 | 4770 | if (t == u->id) |
23a177ef | 4771 | continue; |
071830ff | 4772 | |
7410616c LP |
4773 | r = unit_name_template(t, &z); |
4774 | if (r < 0) | |
4775 | return r; | |
294d81f1 | 4776 | |
bc9fd78c | 4777 | r = load_from_path(u, z); |
294d81f1 | 4778 | if (r < 0) |
23a177ef | 4779 | return r; |
890f434c | 4780 | |
ac155bb8 | 4781 | if (u->load_state != UNIT_STUB) |
23a177ef LP |
4782 | break; |
4783 | } | |
abc08d4d | 4784 | } |
071830ff LP |
4785 | } |
4786 | ||
23a177ef | 4787 | return 0; |
3efd4195 | 4788 | } |
e537352b LP |
4789 | |
4790 | void unit_dump_config_items(FILE *f) { | |
f975e971 LP |
4791 | static const struct { |
4792 | const ConfigParserCallback callback; | |
4793 | const char *rvalue; | |
4794 | } table[] = { | |
17df7223 | 4795 | { config_parse_warn_compat, "NOTSUPPORTED" }, |
f975e971 LP |
4796 | { config_parse_int, "INTEGER" }, |
4797 | { config_parse_unsigned, "UNSIGNED" }, | |
5556b5fe | 4798 | { config_parse_iec_size, "SIZE" }, |
59f448cf | 4799 | { config_parse_iec_uint64, "SIZE" }, |
5556b5fe | 4800 | { config_parse_si_size, "SIZE" }, |
f975e971 LP |
4801 | { config_parse_bool, "BOOLEAN" }, |
4802 | { config_parse_string, "STRING" }, | |
4803 | { config_parse_path, "PATH" }, | |
4804 | { config_parse_unit_path_printf, "PATH" }, | |
4805 | { config_parse_strv, "STRING [...]" }, | |
4806 | { config_parse_exec_nice, "NICE" }, | |
4807 | { config_parse_exec_oom_score_adjust, "OOMSCOREADJUST" }, | |
4808 | { config_parse_exec_io_class, "IOCLASS" }, | |
4809 | { config_parse_exec_io_priority, "IOPRIORITY" }, | |
4810 | { config_parse_exec_cpu_sched_policy, "CPUSCHEDPOLICY" }, | |
4811 | { config_parse_exec_cpu_sched_prio, "CPUSCHEDPRIO" }, | |
4812 | { config_parse_exec_cpu_affinity, "CPUAFFINITY" }, | |
4813 | { config_parse_mode, "MODE" }, | |
4814 | { config_parse_unit_env_file, "FILE" }, | |
52c239d7 LB |
4815 | { config_parse_exec_output, "OUTPUT" }, |
4816 | { config_parse_exec_input, "INPUT" }, | |
ca37242e LP |
4817 | { config_parse_log_facility, "FACILITY" }, |
4818 | { config_parse_log_level, "LEVEL" }, | |
f975e971 | 4819 | { config_parse_exec_secure_bits, "SECUREBITS" }, |
a103496c | 4820 | { config_parse_capability_set, "BOUNDINGSET" }, |
4f424df7 | 4821 | { config_parse_rlimit, "LIMIT" }, |
f975e971 | 4822 | { config_parse_unit_deps, "UNIT [...]" }, |
f975e971 LP |
4823 | { config_parse_exec, "PATH [ARGUMENT [...]]" }, |
4824 | { config_parse_service_type, "SERVICETYPE" }, | |
4825 | { config_parse_service_restart, "SERVICERESTART" }, | |
f975e971 | 4826 | { config_parse_kill_mode, "KILLMODE" }, |
f757855e | 4827 | { config_parse_signal, "SIGNAL" }, |
f975e971 LP |
4828 | { config_parse_socket_listen, "SOCKET [...]" }, |
4829 | { config_parse_socket_bind, "SOCKETBIND" }, | |
4830 | { config_parse_socket_bindtodevice, "NETWORKINTERFACE" }, | |
7f602784 | 4831 | { config_parse_sec, "SECONDS" }, |
d88a251b | 4832 | { config_parse_nsec, "NANOSECONDS" }, |
94828d2d | 4833 | { config_parse_namespace_path_strv, "PATH [...]" }, |
d2d6c096 | 4834 | { config_parse_bind_paths, "PATH[:PATH[:OPTIONS]] [...]" }, |
7c8fa05c | 4835 | { config_parse_unit_requires_mounts_for, "PATH [...]" }, |
f975e971 LP |
4836 | { config_parse_exec_mount_flags, "MOUNTFLAG [...]" }, |
4837 | { config_parse_unit_string_printf, "STRING" }, | |
3ecaa09b | 4838 | { config_parse_trigger_unit, "UNIT" }, |
f975e971 | 4839 | { config_parse_timer, "TIMER" }, |
f975e971 | 4840 | { config_parse_path_spec, "PATH" }, |
f975e971 LP |
4841 | { config_parse_notify_access, "ACCESS" }, |
4842 | { config_parse_ip_tos, "TOS" }, | |
4843 | { config_parse_unit_condition_path, "CONDITION" }, | |
4844 | { config_parse_unit_condition_string, "CONDITION" }, | |
4845 | { config_parse_unit_condition_null, "CONDITION" }, | |
a016b922 | 4846 | { config_parse_unit_slice, "SLICE" }, |
7f0386f6 LP |
4847 | { config_parse_documentation, "URL" }, |
4848 | { config_parse_service_timeout, "SECONDS" }, | |
87a47f99 | 4849 | { config_parse_emergency_action, "ACTION" }, |
7f0386f6 LP |
4850 | { config_parse_set_status, "STATUS" }, |
4851 | { config_parse_service_sockets, "SOCKETS" }, | |
7f0386f6 | 4852 | { config_parse_environ, "ENVIRON" }, |
349cc4a5 | 4853 | #if HAVE_SECCOMP |
17df7223 | 4854 | { config_parse_syscall_filter, "SYSCALLS" }, |
6a6751fe | 4855 | { config_parse_syscall_archs, "ARCHS" }, |
17df7223 | 4856 | { config_parse_syscall_errno, "ERRNO" }, |
4298d0b5 | 4857 | { config_parse_address_families, "FAMILIES" }, |
add00535 | 4858 | { config_parse_restrict_namespaces, "NAMESPACES" }, |
c0467cf3 | 4859 | #endif |
7f0386f6 | 4860 | { config_parse_cpu_shares, "SHARES" }, |
984faf29 | 4861 | { config_parse_cg_weight, "WEIGHT" }, |
7f0386f6 LP |
4862 | { config_parse_memory_limit, "LIMIT" }, |
4863 | { config_parse_device_allow, "DEVICE" }, | |
4864 | { config_parse_device_policy, "POLICY" }, | |
13c31542 | 4865 | { config_parse_io_limit, "LIMIT" }, |
13c31542 | 4866 | { config_parse_io_device_weight, "DEVICEWEIGHT" }, |
6ae4283c | 4867 | { config_parse_io_device_latency, "DEVICELATENCY" }, |
7f0386f6 LP |
4868 | { config_parse_blockio_bandwidth, "BANDWIDTH" }, |
4869 | { config_parse_blockio_weight, "WEIGHT" }, | |
4870 | { config_parse_blockio_device_weight, "DEVICEWEIGHT" }, | |
4871 | { config_parse_long, "LONG" }, | |
4872 | { config_parse_socket_service, "SERVICE" }, | |
349cc4a5 | 4873 | #if HAVE_SELINUX |
6a6751fe LP |
4874 | { config_parse_exec_selinux_context, "LABEL" }, |
4875 | #endif | |
4876 | { config_parse_job_mode, "MODE" }, | |
4877 | { config_parse_job_mode_isolate, "BOOLEAN" }, | |
4298d0b5 | 4878 | { config_parse_personality, "PERSONALITY" }, |
f975e971 LP |
4879 | }; |
4880 | ||
4881 | const char *prev = NULL; | |
4882 | const char *i; | |
4883 | ||
4884 | assert(f); | |
e537352b | 4885 | |
f975e971 LP |
4886 | NULSTR_FOREACH(i, load_fragment_gperf_nulstr) { |
4887 | const char *rvalue = "OTHER", *lvalue; | |
313b7856 | 4888 | const ConfigPerfItem *p; |
f975e971 LP |
4889 | size_t prefix_len; |
4890 | const char *dot; | |
313b7856 | 4891 | unsigned j; |
f975e971 LP |
4892 | |
4893 | assert_se(p = load_fragment_gperf_lookup(i, strlen(i))); | |
4894 | ||
313b7856 LP |
4895 | /* Hide legacy settings */ |
4896 | if (p->parse == config_parse_warn_compat && | |
4897 | p->ltype == DISABLED_LEGACY) | |
4898 | continue; | |
4899 | ||
4900 | for (j = 0; j < ELEMENTSOF(table); j++) | |
4901 | if (p->parse == table[j].callback) { | |
4902 | rvalue = table[j].rvalue; | |
4903 | break; | |
4904 | } | |
4905 | ||
f975e971 LP |
4906 | dot = strchr(i, '.'); |
4907 | lvalue = dot ? dot + 1 : i; | |
4908 | prefix_len = dot-i; | |
4909 | ||
4910 | if (dot) | |
641906e9 | 4911 | if (!prev || !strneq(prev, i, prefix_len+1)) { |
f975e971 LP |
4912 | if (prev) |
4913 | fputc('\n', f); | |
4914 | ||
4915 | fprintf(f, "[%.*s]\n", (int) prefix_len, i); | |
4916 | } | |
4917 | ||
f975e971 LP |
4918 | fprintf(f, "%s=%s\n", lvalue, rvalue); |
4919 | prev = i; | |
4920 | } | |
e537352b | 4921 | } |