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