• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 14630481637

23 Apr 2025 07:04PM UTC coverage: 72.178% (-0.002%) from 72.18%
14630481637

push

github

DaanDeMeyer
mkosi: Run clangd within the tools tree instead of the build container

Running within the build sandbox has a number of disadvantages:
- We have a separate clangd cache for each distribution/release combo
- It requires to build the full image before clangd can be used
- It breaks every time the image becomes out of date and requires a
  rebuild
- We can't look at system headers as we don't have the knowledge to map
  them from inside the build sandbox to the corresponding path on the host

Instead, let's have mkosi.clangd run clangd within the tools tree. We
already require building systemd for both the host and the target anyway,
and all the dependencies to build systemd are installed in the tools tree
already for that, as well as clangd since it's installed together with the
other clang tooling we install in the tools tree. Unlike the previous approach,
this approach only requires the mkosi tools tree to be built upfront, which has
a much higher chance of not invalidating its cache. We can also trivially map
system header lookups from within the sandbox to the path within mkosi.tools
on the host so that starts working as well.

297054 of 411557 relevant lines covered (72.18%)

686269.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.62
/src/core/execute-serialize.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include "af-list.h"
4
#include "capability-util.h"
5
#include "cgroup.h"
6
#include "cgroup-setup.h"
7
#include "dynamic-user.h"
8
#include "escape.h"
9
#include "exec-credential.h"
10
#include "execute-serialize.h"
11
#include "hexdecoct.h"
12
#include "fd-util.h"
13
#include "fileio.h"
14
#include "in-addr-prefix-util.h"
15
#include "parse-helpers.h"
16
#include "parse-util.h"
17
#include "percent-util.h"
18
#include "process-util.h"
19
#include "rlimit-util.h"
20
#include "serialize.h"
21
#include "string-util.h"
22
#include "strv.h"
23

24
static int exec_cgroup_context_serialize(const CGroupContext *c, FILE *f) {
2,199✔
25
        _cleanup_free_ char *disable_controllers_str = NULL, *delegate_controllers_str = NULL,
×
26
                            *cpuset_cpus = NULL, *cpuset_mems = NULL, *startup_cpuset_cpus = NULL,
×
27
                            *startup_cpuset_mems = NULL;
2,199✔
28
        char *iface;
2,199✔
29
        struct in_addr_prefix *iaai;
2,199✔
30
        int r;
2,199✔
31

32
        assert(f);
2,199✔
33

34
        if (!c)
2,199✔
35
                return 0;
36

37
        r = serialize_bool_elide(f, "exec-cgroup-context-cpu-accounting", c->cpu_accounting);
2,199✔
38
        if (r < 0)
2,199✔
39
                return r;
40

41
        r = serialize_bool_elide(f, "exec-cgroup-context-io-accounting", c->io_accounting);
2,199✔
42
        if (r < 0)
×
43
                return r;
44

45
        r = serialize_bool_elide(f, "exec-cgroup-context-memory-accounting", c->memory_accounting);
2,199✔
46
        if (r < 0)
2,151✔
47
                return r;
48

49
        r = serialize_bool_elide(f, "exec-cgroup-context-tasks-accounting", c->tasks_accounting);
2,199✔
50
        if (r < 0)
2,199✔
51
                return r;
52

53
        r = serialize_bool_elide(f, "exec-cgroup-context-ip-accounting", c->ip_accounting);
2,199✔
54
        if (r < 0)
×
55
                return r;
56

57
        r = serialize_bool_elide(f, "exec-cgroup-context-memory-oom-group", c->memory_oom_group);
2,199✔
58
        if (r < 0)
×
59
                return r;
60

61
        if (c->cpu_weight != CGROUP_WEIGHT_INVALID) {
2,199✔
62
                r = serialize_item_format(f, "exec-cgroup-context-cpu-weight", "%" PRIu64, c->cpu_weight);
×
63
                if (r < 0)
×
64
                        return r;
65
        }
66

67
        if (c->startup_cpu_weight != CGROUP_WEIGHT_INVALID) {
2,199✔
68
                r = serialize_item_format(f, "exec-cgroup-context-startup-cpu-weight", "%" PRIu64, c->startup_cpu_weight);
×
69
                if (r < 0)
×
70
                        return r;
71
        }
72

73
        if (c->cpu_quota_per_sec_usec != USEC_INFINITY) {
2,199✔
74
                r = serialize_usec(f, "exec-cgroup-context-cpu-quota-per-sec-usec", c->cpu_quota_per_sec_usec);
×
75
                if (r < 0)
×
76
                        return r;
77
        }
78

79
        if (c->cpu_quota_period_usec != USEC_INFINITY) {
2,199✔
80
                r = serialize_usec(f, "exec-cgroup-context-cpu-quota-period-usec", c->cpu_quota_period_usec);
×
81
                if (r < 0)
×
82
                        return r;
83
        }
84

85
        cpuset_cpus = cpu_set_to_range_string(&c->cpuset_cpus);
2,199✔
86
        if (!cpuset_cpus)
2,199✔
87
                return log_oom_debug();
×
88

89
        r = serialize_item(f, "exec-cgroup-context-allowed-cpus", cpuset_cpus);
2,199✔
90
        if (r < 0)
2,199✔
91
                return r;
92

93
        startup_cpuset_cpus = cpu_set_to_range_string(&c->startup_cpuset_cpus);
2,199✔
94
        if (!startup_cpuset_cpus)
2,199✔
95
                return log_oom_debug();
×
96

97
        r = serialize_item(f, "exec-cgroup-context-startup-allowed-cpus", startup_cpuset_cpus);
2,199✔
98
        if (r < 0)
2,199✔
99
                return r;
100

101
        cpuset_mems = cpu_set_to_range_string(&c->cpuset_mems);
2,199✔
102
        if (!cpuset_mems)
2,199✔
103
                return log_oom_debug();
×
104

105
        r = serialize_item(f, "exec-cgroup-context-allowed-memory-nodes", cpuset_mems);
2,199✔
106
        if (r < 0)
2,199✔
107
                return r;
108

109
        startup_cpuset_mems = cpu_set_to_range_string(&c->startup_cpuset_mems);
2,199✔
110
        if (!startup_cpuset_mems)
2,199✔
111
                return log_oom_debug();
×
112

113
        r = serialize_item(f, "exec-cgroup-context-startup-allowed-memory-nodes", startup_cpuset_mems);
2,199✔
114
        if (r < 0)
2,199✔
115
                return r;
116

117
        if (c->io_weight != CGROUP_WEIGHT_INVALID) {
2,199✔
118
                r = serialize_item_format(f, "exec-cgroup-context-io-weight", "%" PRIu64, c->io_weight);
×
119
                if (r < 0)
×
120
                        return r;
121
        }
122

123
        if (c->startup_io_weight != CGROUP_WEIGHT_INVALID) {
2,199✔
124
                r = serialize_item_format(f, "exec-cgroup-context-startup-io-weight", "%" PRIu64, c->startup_io_weight);
×
125
                if (r < 0)
×
126
                        return r;
127
        }
128

129
        if (c->default_memory_min > 0) {
2,199✔
130
                r = serialize_item_format(f, "exec-cgroup-context-default-memory-min", "%" PRIu64, c->default_memory_min);
×
131
                if (r < 0)
×
132
                        return r;
133
        }
134

135
        if (c->default_memory_low > 0) {
2,199✔
136
                r = serialize_item_format(f, "exec-cgroup-context-default-memory-low", "%" PRIu64, c->default_memory_low);
×
137
                if (r < 0)
×
138
                        return r;
139
        }
140

141
        if (c->memory_min > 0) {
2,199✔
142
                r = serialize_item_format(f, "exec-cgroup-context-memory-min", "%" PRIu64, c->memory_min);
×
143
                if (r < 0)
×
144
                        return r;
145
        }
146

147
        if (c->memory_low > 0) {
2,199✔
148
                r = serialize_item_format(f, "exec-cgroup-context-memory-low", "%" PRIu64, c->memory_low);
×
149
                if (r < 0)
×
150
                        return r;
151
        }
152

153
        if (c->startup_memory_low > 0) {
2,199✔
154
                r = serialize_item_format(f, "exec-cgroup-context-startup-memory-low", "%" PRIu64, c->startup_memory_low);
×
155
                if (r < 0)
×
156
                        return r;
157
        }
158

159
        if (c->memory_high != CGROUP_LIMIT_MAX) {
2,199✔
160
                r = serialize_item_format(f, "exec-cgroup-context-memory-high", "%" PRIu64, c->memory_high);
2✔
161
                if (r < 0)
2✔
162
                        return r;
163
        }
164

165
        if (c->startup_memory_high != CGROUP_LIMIT_MAX) {
2,199✔
166
                r = serialize_item_format(f, "exec-cgroup-context-startup-memory-high", "%" PRIu64, c->startup_memory_high);
×
167
                if (r < 0)
×
168
                        return r;
169
        }
170

171
        if (c->memory_max != CGROUP_LIMIT_MAX) {
2,199✔
172
                r = serialize_item_format(f, "exec-cgroup-context-memory-max", "%" PRIu64, c->memory_max);
×
173
                if (r < 0)
×
174
                        return r;
175
        }
176

177
        if (c->startup_memory_max != CGROUP_LIMIT_MAX) {
2,199✔
178
                r = serialize_item_format(f, "exec-cgroup-context-startup-memory-max", "%" PRIu64, c->startup_memory_max);
×
179
                if (r < 0)
×
180
                        return r;
181
        }
182

183
        if (c->memory_swap_max != CGROUP_LIMIT_MAX) {
2,199✔
184
                r = serialize_item_format(f, "exec-cgroup-context-memory-swap-max", "%" PRIu64, c->memory_swap_max);
×
185
                if (r < 0)
×
186
                        return r;
187
        }
188

189
        if (c->startup_memory_swap_max != CGROUP_LIMIT_MAX) {
2,199✔
190
                r = serialize_item_format(f, "exec-cgroup-context-startup-memory-swap-max", "%" PRIu64, c->startup_memory_swap_max);
×
191
                if (r < 0)
×
192
                        return r;
193
        }
194

195
        if (c->memory_zswap_max != CGROUP_LIMIT_MAX) {
2,199✔
196
                r = serialize_item_format(f, "exec-cgroup-context-memory-zswap-max", "%" PRIu64, c->memory_zswap_max);
×
197
                if (r < 0)
×
198
                        return r;
199
        }
200

201
        if (c->startup_memory_zswap_max != CGROUP_LIMIT_MAX) {
2,199✔
202
                r = serialize_item_format(f, "exec-cgroup-context-startup-memory-zswap-max", "%" PRIu64, c->startup_memory_zswap_max);
×
203
                if (r < 0)
×
204
                        return r;
205
        }
206

207
        r = serialize_bool(f, "exec-cgroup-context-memory-zswap-writeback", c->memory_zswap_writeback);
2,199✔
208
        if (r < 0)
2,199✔
209
                return r;
210

211
        if (c->tasks_max.value != UINT64_MAX) {
2,199✔
212
                r = serialize_item_format(f, "exec-cgroup-context-tasks-max-value", "%" PRIu64, c->tasks_max.value);
2,152✔
213
                if (r < 0)
2,152✔
214
                        return r;
215
        }
216

217
        if (c->tasks_max.scale > 0) {
2,199✔
218
                r = serialize_item_format(f, "exec-cgroup-context-tasks-max-scale", "%" PRIu64, c->tasks_max.scale);
2,152✔
219
                if (r < 0)
2,152✔
220
                        return r;
221
        }
222

223
        r = serialize_bool_elide(f, "exec-cgroup-context-default-memory-min-set", c->default_memory_min_set);
2,199✔
224
        if (r < 0)
×
225
                return r;
226

227
        r = serialize_bool_elide(f, "exec-cgroup-context-default-memory-low-set", c->default_memory_low_set);
2,199✔
228
        if (r < 0)
×
229
                return r;
230

231
        r = serialize_bool_elide(f, "exec-cgroup-context-default-startup-memory-low-set", c->default_startup_memory_low_set);
2,199✔
232
        if (r < 0)
×
233
                return r;
234

235
        r = serialize_bool_elide(f, "exec-cgroup-context-memory-min-set", c->memory_min_set);
2,199✔
236
        if (r < 0)
×
237
                return r;
238

239
        r = serialize_bool_elide(f, "exec-cgroup-context-memory-low-set", c->memory_low_set);
2,199✔
240
        if (r < 0)
×
241
                return r;
242

243
        r = serialize_bool_elide(f, "exec-cgroup-context-startup-memory-low-set", c->startup_memory_low_set);
2,199✔
244
        if (r < 0)
×
245
                return r;
246

247
        r = serialize_bool_elide(f, "exec-cgroup-context-startup-memory-high-set", c->startup_memory_high_set);
2,199✔
248
        if (r < 0)
×
249
                return r;
250

251
        r = serialize_bool_elide(f, "exec-cgroup-context-startup-memory-max-set", c->startup_memory_max_set);
2,199✔
252
        if (r < 0)
×
253
                return r;
254

255
        r = serialize_bool_elide(f, "exec-cgroup-context-startup-memory-swap-max-set", c->startup_memory_swap_max_set);
2,199✔
256
        if (r < 0)
×
257
                return r;
258

259
        r = serialize_bool_elide(f, "exec-cgroup-context-startup-memory-zswap-max-set", c->startup_memory_zswap_max_set);
2,199✔
260
        if (r < 0)
×
261
                return r;
262

263
        r = serialize_item(f, "exec-cgroup-context-device-policy", cgroup_device_policy_to_string(c->device_policy));
2,199✔
264
        if (r < 0)
2,199✔
265
                return r;
266

267
        r = cg_mask_to_string(c->disable_controllers, &disable_controllers_str);
2,199✔
268
        if (r < 0)
2,199✔
269
                return r;
270

271
        r = serialize_item(f, "exec-cgroup-context-disable-controllers", disable_controllers_str);
2,199✔
272
        if (r < 0)
2,199✔
273
                return r;
274

275
        r = cg_mask_to_string(c->delegate_controllers, &delegate_controllers_str);
2,199✔
276
        if (r < 0)
2,199✔
277
                return r;
278

279
        r = serialize_item(f, "exec-cgroup-context-delegate-controllers", delegate_controllers_str);
2,199✔
280
        if (r < 0)
2,199✔
281
                return r;
282

283
        r = serialize_bool_elide(f, "exec-cgroup-context-delegate", c->delegate);
2,199✔
284
        if (r < 0)
49✔
285
                return r;
286

287
        r = serialize_item(f, "exec-cgroup-context-managed-oom-swap", managed_oom_mode_to_string(c->moom_swap));
2,199✔
288
        if (r < 0)
2,199✔
289
                return r;
290

291
        r = serialize_item(f, "exec-cgroup-context-managed-oom-memory-pressure", managed_oom_mode_to_string(c->moom_mem_pressure));
2,199✔
292
        if (r < 0)
2,199✔
293
                return r;
294

295
        r = serialize_item_format(f, "exec-cgroup-context-managed-oom-memory-pressure-limit", "%" PRIu32, c->moom_mem_pressure_limit);
2,199✔
296
        if (r < 0)
2,199✔
297
                return r;
298

299
        r = serialize_usec(f, "exec-cgroup-context-managed-oom-memory-pressure-duration-usec", c->moom_mem_pressure_duration_usec);
2,199✔
300
        if (r < 0)
2,199✔
301
                return r;
302

303
        r = serialize_item(f, "exec-cgroup-context-managed-oom-preference", managed_oom_preference_to_string(c->moom_preference));
2,199✔
304
        if (r < 0)
2,199✔
305
                return r;
306

307
        r = serialize_item(f, "exec-cgroup-context-memory-pressure-watch", cgroup_pressure_watch_to_string(c->memory_pressure_watch));
2,199✔
308
        if (r < 0)
2,199✔
309
                return r;
310

311
        r = serialize_item(f, "exec-cgroup-context-delegate-subgroup", c->delegate_subgroup);
2,199✔
312
        if (r < 0)
2,199✔
313
                return r;
314

315
        if (c->memory_pressure_threshold_usec != USEC_INFINITY) {
2,199✔
316
                r = serialize_usec(f, "exec-cgroup-context-memory-pressure-threshold-usec", c->memory_pressure_threshold_usec);
2,199✔
317
                if (r < 0)
2,199✔
318
                        return r;
319
        }
320

321
        LIST_FOREACH(device_allow, a, c->device_allow) {
2,689✔
322
                r = serialize_item_format(f, "exec-cgroup-context-device-allow", "%s %s",
490✔
323
                                          a->path,
324
                                          cgroup_device_permissions_to_string(a->permissions));
325
                if (r < 0)
490✔
326
                        return r;
327
        }
328

329
        LIST_FOREACH(device_weights, iw, c->io_device_weights) {
2,199✔
330
                r = serialize_item_format(f, "exec-cgroup-context-io-device-weight", "%s %" PRIu64,
×
331
                                          iw->path,
332
                                          iw->weight);
333
                if (r < 0)
×
334
                        return r;
335
        }
336

337
        LIST_FOREACH(device_latencies, l, c->io_device_latencies) {
2,199✔
338
                r = serialize_item_format(f, "exec-cgroup-context-io-device-latency-target-usec", "%s " USEC_FMT,
×
339
                                          l->path,
340
                                          l->target_usec);
341
                if (r < 0)
×
342
                        return r;
343
        }
344

345
        LIST_FOREACH(device_limits, il, c->io_device_limits)
2,199✔
346
                for (CGroupIOLimitType type = 0; type < _CGROUP_IO_LIMIT_TYPE_MAX; type++) {
×
347
                        _cleanup_free_ char *key = NULL;
×
348

349
                        if (il->limits[type] == cgroup_io_limit_defaults[type])
×
350
                                continue;
×
351

352
                        key = strjoin("exec-cgroup-context-io-device-limit-", cgroup_io_limit_type_to_string(type));
×
353
                        if (!key)
×
354
                                return -ENOMEM;
355

356
                        r = serialize_item_format(f, key, "%s %" PRIu64, il->path, il->limits[type]);
×
357
                        if (r < 0)
×
358
                                return r;
359
                }
360

361
        SET_FOREACH(iaai, c->ip_address_allow) {
2,199✔
362
                r = serialize_item(f,
×
363
                                   "exec-cgroup-context-ip-address-allow",
364
                                   IN_ADDR_PREFIX_TO_STRING(iaai->family, &iaai->address, iaai->prefixlen));
×
365
                if (r < 0)
×
366
                        return r;
×
367
        }
368
        SET_FOREACH(iaai, c->ip_address_deny) {
2,481✔
369
                r = serialize_item(f,
282✔
370
                                   "exec-cgroup-context-ip-address-deny",
371
                                   IN_ADDR_PREFIX_TO_STRING(iaai->family, &iaai->address, iaai->prefixlen));
282✔
372
                if (r < 0)
282✔
373
                        return r;
×
374
        }
375

376
        r = serialize_bool_elide(f, "exec-cgroup-context-ip-address-allow-reduced", c->ip_address_allow_reduced);
2,199✔
377
        if (r < 0)
589✔
378
                return r;
379

380
        r = serialize_bool_elide(f, "exec-cgroup-context-ip-address-deny-reduced", c->ip_address_deny_reduced);
2,199✔
381
        if (r < 0)
589✔
382
                return r;
383

384
        r = serialize_strv(f, "exec-cgroup-context-ip-ingress-filter-path", c->ip_filters_ingress);
2,199✔
385
        if (r < 0)
2,199✔
386
                return r;
387

388
        r = serialize_strv(f, "exec-cgroup-context-ip-egress-filter-path", c->ip_filters_egress);
2,199✔
389
        if (r < 0)
2,199✔
390
                return r;
391

392
        LIST_FOREACH(programs, p, c->bpf_foreign_programs) {
2,199✔
393
                r = serialize_item_format(f, "exec-cgroup-context-bpf-program", "%" PRIu32 " %s",
×
394
                                          p->attach_type,
395
                                          p->bpffs_path);
396
                if (r < 0)
×
397
                        return r;
398
        }
399

400
        LIST_FOREACH(socket_bind_items, bi, c->socket_bind_allow) {
2,199✔
401
                fprintf(f, "exec-cgroup-context-socket-bind-allow=");
×
402
                cgroup_context_dump_socket_bind_item(bi, f);
×
403
                fputc('\n', f);
×
404
        }
405

406
        LIST_FOREACH(socket_bind_items, bi, c->socket_bind_deny) {
2,199✔
407
                fprintf(f, "exec-cgroup-context-socket-bind-deny=");
×
408
                cgroup_context_dump_socket_bind_item(bi, f);
×
409
                fputc('\n', f);
×
410
        }
411

412
        SET_FOREACH(iface, c->restrict_network_interfaces) {
2,199✔
413
                r = serialize_item(f, "exec-cgroup-context-restrict-network-interfaces", iface);
×
414
                if (r < 0)
×
415
                        return r;
×
416
        }
417

418
        r = serialize_bool_elide(
4,398✔
419
                        f,
420
                        "exec-cgroup-context-restrict-network-interfaces-is-allow-list",
421
                        c->restrict_network_interfaces_is_allow_list);
2,199✔
422
        if (r < 0)
×
423
                return r;
424

425
        fputc('\n', f); /* End marker */
2,199✔
426

427
        return 0;
428
}
429

430
static int exec_cgroup_context_deserialize(CGroupContext *c, FILE *f) {
11,500✔
431
        int r;
11,500✔
432

433
        assert(f);
11,500✔
434

435
        if (!c)
11,500✔
436
                return 0;
437

438
        for (;;) {
438,666✔
439
                _cleanup_free_ char *l = NULL;
213,583✔
440
                const char *val;
225,083✔
441

442
                r = deserialize_read_line(f, &l);
225,083✔
443
                if (r < 0)
225,083✔
444
                        return r;
445
                if (r == 0) /* eof or end marker */
225,083✔
446
                        break;
447

448
                if ((val = startswith(l, "exec-cgroup-context-cpu-accounting="))) {
213,583✔
449
                        r = parse_boolean(val);
11,500✔
450
                        if (r < 0)
11,500✔
451
                                return r;
452
                        c->cpu_accounting = r;
11,500✔
453
                } else if ((val = startswith(l, "exec-cgroup-context-io-accounting="))) {
202,083✔
454
                        r = parse_boolean(val);
2✔
455
                        if (r < 0)
2✔
456
                                return r;
457
                        c->io_accounting = r;
2✔
458
                } else if ((val = startswith(l, "exec-cgroup-context-memory-accounting="))) {
202,081✔
459
                        r = parse_boolean(val);
11,276✔
460
                        if (r < 0)
11,276✔
461
                                return r;
462
                        c->memory_accounting = r;
11,276✔
463
                } else if ((val = startswith(l, "exec-cgroup-context-tasks-accounting="))) {
190,805✔
464
                        r = parse_boolean(val);
11,500✔
465
                        if (r < 0)
11,500✔
466
                                return r;
467
                        c->tasks_accounting = r;
11,500✔
468
                } else if ((val = startswith(l, "exec-cgroup-context-ip-accounting="))) {
179,305✔
469
                        r = parse_boolean(val);
×
470
                        if (r < 0)
×
471
                                return r;
472
                        c->ip_accounting = r;
×
473
                } else if ((val = startswith(l, "exec-cgroup-context-memory-oom-group="))) {
179,305✔
474
                        r = parse_boolean(val);
×
475
                        if (r < 0)
×
476
                                return r;
477
                        c->memory_oom_group = r;
×
478
                } else if ((val = startswith(l, "exec-cgroup-context-cpu-weight="))) {
179,305✔
479
                        r = safe_atou64(val, &c->cpu_weight);
1✔
480
                        if (r < 0)
1✔
481
                                return r;
482
                } else if ((val = startswith(l, "exec-cgroup-context-startup-cpu-weight="))) {
179,304✔
483
                        r = safe_atou64(val, &c->startup_cpu_weight);
×
484
                        if (r < 0)
×
485
                                return r;
486
                } else if ((val = startswith(l, "exec-cgroup-context-cpu-quota-per-sec-usec="))) {
179,304✔
487
                        r = deserialize_usec(val, &c->cpu_quota_per_sec_usec);
×
488
                        if (r < 0)
×
489
                                return r;
490
                } else if ((val = startswith(l, "exec-cgroup-context-cpu-quota-period-usec="))) {
179,304✔
491
                        r = deserialize_usec(val, &c->cpu_quota_period_usec);
×
492
                        if (r < 0)
×
493
                                return r;
494
                } else if ((val = startswith(l, "exec-cgroup-context-allowed-cpus="))) {
179,304✔
495
                        if (c->cpuset_cpus.set)
11,500✔
496
                                return -EINVAL; /* duplicated */
497

498
                        r = parse_cpu_set_full(
11,500✔
499
                                        val,
500
                                        &c->cpuset_cpus,
501
                                        /* warn= */ false,
502
                                        /* unit= */ NULL,
503
                                        /* filename= */ NULL,
504
                                        /* line= */ 0,
505
                                        /* lvalue= */ NULL);
506
                        if (r < 0)
11,500✔
507
                                return r;
508
                } else if ((val = startswith(l, "exec-cgroup-context-startup-allowed-cpus="))) {
167,804✔
509
                        if (c->startup_cpuset_cpus.set)
11,500✔
510
                                return -EINVAL; /* duplicated */
511

512
                        r = parse_cpu_set_full(
11,500✔
513
                                        val,
514
                                        &c->startup_cpuset_cpus,
515
                                        /* warn= */ false,
516
                                        /* unit= */ NULL,
517
                                        /* filename= */ NULL,
518
                                        /* line= */ 0,
519
                                        /* lvalue= */ NULL);
520
                        if (r < 0)
11,500✔
521
                                return r;
522
                } else if ((val = startswith(l, "exec-cgroup-context-allowed-memory-nodes="))) {
156,304✔
523
                        if (c->cpuset_mems.set)
11,500✔
524
                                return -EINVAL; /* duplicated */
525

526
                        r = parse_cpu_set_full(
11,500✔
527
                                        val,
528
                                        &c->cpuset_mems,
529
                                        /* warn= */ false,
530
                                        /* unit= */ NULL,
531
                                        /* filename= */ NULL,
532
                                        /* line= */ 0,
533
                                        /* lvalue= */ NULL);
534
                        if (r < 0)
11,500✔
535
                                return r;
536
                } else if ((val = startswith(l, "exec-cgroup-context-startup-allowed-memory-nodes="))) {
144,804✔
537
                        if (c->startup_cpuset_mems.set)
11,500✔
538
                                return -EINVAL; /* duplicated */
539

540
                        r = parse_cpu_set_full(
11,500✔
541
                                        val,
542
                                        &c->startup_cpuset_mems,
543
                                        /* warn= */ false,
544
                                        /* unit= */ NULL,
545
                                        /* filename= */ NULL,
546
                                        /* line= */ 0,
547
                                        /* lvalue= */ NULL);
548
                        if (r < 0)
11,500✔
549
                                return r;
550
                } else if ((val = startswith(l, "exec-cgroup-context-io-weight="))) {
133,304✔
551
                        r = safe_atou64(val, &c->io_weight);
×
552
                        if (r < 0)
×
553
                                return r;
554
                } else if ((val = startswith(l, "exec-cgroup-context-startup-io-weight="))) {
133,304✔
555
                        r = safe_atou64(val, &c->startup_io_weight);
×
556
                        if (r < 0)
×
557
                                return r;
558
                } else if ((val = startswith(l, "exec-cgroup-context-default-memory-min="))) {
133,304✔
559
                        r = safe_atou64(val, &c->default_memory_min);
×
560
                        if (r < 0)
×
561
                                return r;
562
                } else if ((val = startswith(l, "exec-cgroup-context-default-memory-low="))) {
133,304✔
563
                        r = safe_atou64(val, &c->default_memory_low);
×
564
                        if (r < 0)
×
565
                                return r;
566
                } else if ((val = startswith(l, "exec-cgroup-context-memory-min="))) {
133,304✔
567
                        r = safe_atou64(val, &c->memory_min);
1✔
568
                        if (r < 0)
1✔
569
                                return r;
570
                } else if ((val = startswith(l, "exec-cgroup-context-memory-low="))) {
133,303✔
571
                        r = safe_atou64(val, &c->memory_low);
1✔
572
                        if (r < 0)
1✔
573
                                return r;
574
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-low="))) {
133,302✔
575
                        r = safe_atou64(val, &c->startup_memory_low);
×
576
                        if (r < 0)
×
577
                                return r;
578
                } else if ((val = startswith(l, "exec-cgroup-context-memory-high="))) {
133,302✔
579
                        r = safe_atou64(val, &c->memory_high);
10✔
580
                        if (r < 0)
10✔
581
                                return r;
582
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-high="))) {
133,292✔
583
                        r = safe_atou64(val, &c->startup_memory_high);
×
584
                        if (r < 0)
×
585
                                return r;
586
                } else if ((val = startswith(l, "exec-cgroup-context-memory-max="))) {
133,292✔
587
                        r = safe_atou64(val, &c->memory_max);
2✔
588
                        if (r < 0)
2✔
589
                                return r;
590
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-max="))) {
133,290✔
591
                        r = safe_atou64(val, &c->startup_memory_max);
×
592
                        if (r < 0)
×
593
                                return r;
594
                } else if ((val = startswith(l, "exec-cgroup-context-memory-swap-max="))) {
133,290✔
595
                        r = safe_atou64(val, &c->memory_swap_max);
1✔
596
                        if (r < 0)
1✔
597
                                return r;
598
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-swap-max="))) {
133,289✔
599
                        r = safe_atou64(val, &c->startup_memory_swap_max);
×
600
                        if (r < 0)
×
601
                                return r;
602
                } else if ((val = startswith(l, "exec-cgroup-context-memory-zswap-max="))) {
133,289✔
603
                        r = safe_atou64(val, &c->memory_zswap_max);
1✔
604
                        if (r < 0)
1✔
605
                                return r;
606
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-zswap-max="))) {
133,288✔
607
                        r = safe_atou64(val, &c->startup_memory_zswap_max);
×
608
                        if (r < 0)
×
609
                                return r;
610
                } else if ((val = startswith(l, "exec-cgroup-context-memory-zswap-writeback="))) {
133,288✔
611
                        r = parse_boolean(val);
11,500✔
612
                        if (r < 0)
11,500✔
613
                                return r;
614
                        c->memory_zswap_writeback = r;
11,500✔
615
                } else if ((val = startswith(l, "exec-cgroup-context-tasks-max-value="))) {
121,788✔
616
                        r = safe_atou64(val, &c->tasks_max.value);
11,213✔
617
                        if (r < 0)
11,213✔
618
                                return r;
619
                } else if ((val = startswith(l, "exec-cgroup-context-tasks-max-scale="))) {
110,575✔
620
                        r = safe_atou64(val, &c->tasks_max.scale);
11,178✔
621
                        if (r < 0)
11,178✔
622
                                return r;
623
                } else if ((val = startswith(l, "exec-cgroup-context-default-memory-min-set="))) {
99,397✔
624
                        r = parse_boolean(val);
×
625
                        if (r < 0)
×
626
                                return r;
627
                        c->default_memory_min_set = r;
×
628
                } else if ((val = startswith(l, "exec-cgroup-context-default-memory-low-set="))) {
99,397✔
629
                        r = parse_boolean(val);
×
630
                        if (r < 0)
×
631
                                return r;
632
                        c->default_memory_low_set = r;
×
633
                } else if ((val = startswith(l, "exec-cgroup-context-default-startup-memory-low-set="))) {
99,397✔
634
                        r = parse_boolean(val);
×
635
                        if (r < 0)
×
636
                                return r;
637
                        c->default_startup_memory_low_set = r;
×
638
                } else if ((val = startswith(l, "exec-cgroup-context-memory-min-set="))) {
99,397✔
639
                        r = parse_boolean(val);
1✔
640
                        if (r < 0)
1✔
641
                                return r;
642
                        c->memory_min_set = r;
1✔
643
                } else if ((val = startswith(l, "exec-cgroup-context-memory-low-set="))) {
99,396✔
644
                        r = parse_boolean(val);
1✔
645
                        if (r < 0)
1✔
646
                                return r;
647
                        c->memory_low_set = r;
1✔
648
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-low-set="))) {
99,395✔
649
                        r = parse_boolean(val);
×
650
                        if (r < 0)
×
651
                                return r;
652
                        c->startup_memory_low_set = r;
×
653
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-high-set="))) {
99,395✔
654
                        r = parse_boolean(val);
×
655
                        if (r < 0)
×
656
                                return r;
657
                        c->startup_memory_high_set = r;
×
658
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-max-set="))) {
99,395✔
659
                        r = parse_boolean(val);
×
660
                        if (r < 0)
×
661
                                return r;
662
                        c->startup_memory_max_set = r;
×
663
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-swap-max-set="))) {
99,395✔
664
                        r = parse_boolean(val);
×
665
                        if (r < 0)
×
666
                                return r;
667
                        c->startup_memory_swap_max_set = r;
×
668
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-zswap-max-set="))) {
99,395✔
669
                        r = parse_boolean(val);
×
670
                        if (r < 0)
×
671
                                return r;
672
                        c->startup_memory_zswap_max_set = r;
×
673
                } else if ((val = startswith(l, "exec-cgroup-context-device-policy="))) {
99,395✔
674
                        c->device_policy = cgroup_device_policy_from_string(val);
11,500✔
675
                        if (c->device_policy < 0)
11,500✔
676
                                return -EINVAL;
677
                } else if ((val = startswith(l, "exec-cgroup-context-disable-controllers="))) {
87,895✔
678
                        r = cg_mask_from_string(val, &c->disable_controllers);
×
679
                        if (r < 0)
×
680
                                return r;
681
                } else if ((val = startswith(l, "exec-cgroup-context-delegate-controllers="))) {
87,895✔
682
                        r = cg_mask_from_string(val, &c->delegate_controllers);
660✔
683
                        if (r < 0)
660✔
684
                                return r;
685
                } else if ((val = startswith(l, "exec-cgroup-context-delegate="))) {
87,235✔
686
                        r = parse_boolean(val);
664✔
687
                        if (r < 0)
664✔
688
                                return r;
689
                        c->delegate = r;
664✔
690
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-swap="))) {
86,571✔
691
                        c->moom_swap = managed_oom_mode_from_string(val);
11,500✔
692
                        if (c->moom_swap < 0)
11,500✔
693
                                return -EINVAL;
694
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-memory-pressure="))) {
75,071✔
695
                        c->moom_mem_pressure = managed_oom_mode_from_string(val);
11,500✔
696
                        if (c->moom_mem_pressure < 0)
11,500✔
697
                                return -EINVAL;
698
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-memory-pressure-limit="))) {
63,571✔
699
                        r = safe_atou32(val, &c->moom_mem_pressure_limit);
11,500✔
700
                        if (r < 0)
11,500✔
701
                                return r;
702
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-preference="))) {
52,071✔
703
                        c->moom_preference = managed_oom_preference_from_string(val);
11,500✔
704
                        if (c->moom_preference < 0)
11,500✔
705
                                return -EINVAL;
706
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-memory-pressure-duration-usec="))) {
40,571✔
707
                        r = deserialize_usec(val, &c->moom_mem_pressure_duration_usec);
1✔
708
                        if (r < 0)
1✔
709
                                return r;
710
                } else if ((val = startswith(l, "exec-cgroup-context-memory-pressure-watch="))) {
40,570✔
711
                        c->memory_pressure_watch = cgroup_pressure_watch_from_string(val);
11,500✔
712
                        if (c->memory_pressure_watch < 0)
11,500✔
713
                                return -EINVAL;
714
                } else if ((val = startswith(l, "exec-cgroup-context-delegate-subgroup="))) {
29,070✔
715
                        r = free_and_strdup(&c->delegate_subgroup, val);
324✔
716
                        if (r < 0)
324✔
717
                                return r;
718
                } else if ((val = startswith(l, "exec-cgroup-context-memory-pressure-threshold-usec="))) {
28,746✔
719
                        r = deserialize_usec(val, &c->memory_pressure_threshold_usec);
11,500✔
720
                        if (r < 0)
11,500✔
721
                                return r;
722
                } else if ((val = startswith(l, "exec-cgroup-context-device-allow="))) {
17,246✔
723
                        _cleanup_free_ char *path = NULL, *rwm = NULL;
4,360✔
724
                        CGroupDevicePermissions p;
4,360✔
725

726
                        r = extract_many_words(&val, " ", 0, &path, &rwm);
4,360✔
727
                        if (r < 0)
4,360✔
728
                                return r;
729
                        if (r == 0)
4,360✔
730
                                return -EINVAL;
731

732
                        p = isempty(rwm) ? 0 : cgroup_device_permissions_from_string(rwm);
8,720✔
733
                        if (p < 0)
4,360✔
734
                                return p;
735

736
                        r = cgroup_context_add_or_update_device_allow(c, path, p);
4,360✔
737
                        if (r < 0)
4,360✔
738
                                return r;
739
                } else if ((val = startswith(l, "exec-cgroup-context-io-device-weight="))) {
12,886✔
740
                        _cleanup_free_ char *path = NULL, *weight = NULL;
×
741
                        CGroupIODeviceWeight *a = NULL;
×
742

743
                        r = extract_many_words(&val, " ", 0, &path, &weight);
×
744
                        if (r < 0)
×
745
                                return r;
746
                        if (r != 2)
×
747
                                return -EINVAL;
748

749
                        LIST_FOREACH(device_weights, b, c->io_device_weights)
×
750
                                if (path_equal(b->path, path)) {
×
751
                                        a = b;
752
                                        break;
753
                                }
754

755
                        if (!a) {
×
756
                                a = new0(CGroupIODeviceWeight, 1);
×
757
                                if (!a)
×
758
                                        return log_oom_debug();
×
759

760
                                a->path = TAKE_PTR(path);
×
761

762
                                LIST_PREPEND(device_weights, c->io_device_weights, a);
×
763
                        }
764

765
                        r = safe_atou64(weight, &a->weight);
×
766
                        if (r < 0)
×
767
                                return r;
768
                } else if ((val = startswith(l, "exec-cgroup-context-io-device-latency-target-usec="))) {
12,886✔
769
                        _cleanup_free_ char *path = NULL, *target = NULL;
×
770
                        CGroupIODeviceLatency *a = NULL;
×
771

772
                        r = extract_many_words(&val, " ", 0, &path, &target);
×
773
                        if (r < 0)
×
774
                                return r;
775
                        if (r != 2)
×
776
                                return -EINVAL;
777

778
                        LIST_FOREACH(device_latencies, b, c->io_device_latencies)
×
779
                                if (path_equal(b->path, path)) {
×
780
                                        a = b;
781
                                        break;
782
                                }
783

784
                        if (!a) {
×
785
                                a = new0(CGroupIODeviceLatency, 1);
×
786
                                if (!a)
×
787
                                        return log_oom_debug();
×
788

789
                                a->path = TAKE_PTR(path);
×
790

791
                                LIST_PREPEND(device_latencies, c->io_device_latencies, a);
×
792
                        }
793

794
                        r = deserialize_usec(target, &a->target_usec);
×
795
                        if (r < 0)
×
796
                                return r;
797
                } else if ((val = startswith(l, "exec-cgroup-context-io-device-limit-"))) {
12,886✔
798
                        _cleanup_free_ char *type = NULL, *path = NULL, *limits = NULL;
×
799
                        CGroupIODeviceLimit *limit = NULL;
×
800
                        CGroupIOLimitType t;
×
801

802
                        r = extract_many_words(&val, "= ", 0, &type, &path, &limits);
×
803
                        if (r < 0)
×
804
                                return r;
805
                        if (r != 3)
×
806
                                return -EINVAL;
807

808
                        t = cgroup_io_limit_type_from_string(type);
×
809
                        if (t < 0)
×
810
                                return t;
811

812
                        LIST_FOREACH(device_limits, i, c->io_device_limits)
×
813
                                if (path_equal(path, i->path)) {
×
814
                                        limit = i;
815
                                        break;
816
                                }
817

818
                        if (!limit) {
×
819
                                limit = new0(CGroupIODeviceLimit, 1);
×
820
                                if (!limit)
×
821
                                        return log_oom_debug();
×
822

823
                                limit->path = TAKE_PTR(path);
×
824
                                for (CGroupIOLimitType i = 0; i < _CGROUP_IO_LIMIT_TYPE_MAX; i++)
×
825
                                        limit->limits[i] = cgroup_io_limit_defaults[i];
×
826

827
                                LIST_PREPEND(device_limits, c->io_device_limits, limit);
×
828
                        }
829

830
                        r = safe_atou64(limits, &limit->limits[t]);
×
831
                        if (r < 0)
×
832
                                return r;
833
                } else if ((val = startswith(l, "exec-cgroup-context-ip-address-allow="))) {
12,886✔
834
                        struct in_addr_prefix a;
×
835

836
                        r = in_addr_prefix_from_string_auto(val, &a.family, &a.address, &a.prefixlen);
×
837
                        if (r < 0)
×
838
                                return r;
×
839

840
                        r = in_addr_prefix_add(&c->ip_address_allow, &a);
×
841
                        if (r < 0)
×
842
                                return r;
843
                } else if ((val = startswith(l, "exec-cgroup-context-ip-address-deny="))) {
12,886✔
844
                        struct in_addr_prefix a;
1,610✔
845

846
                        r = in_addr_prefix_from_string_auto(val, &a.family, &a.address, &a.prefixlen);
1,610✔
847
                        if (r < 0)
1,610✔
848
                                return r;
×
849

850
                        r = in_addr_prefix_add(&c->ip_address_deny, &a);
1,610✔
851
                        if (r < 0)
1,610✔
852
                                return r;
853
                } else if ((val = startswith(l, "exec-cgroup-context-ip-address-allow-reduced="))) {
11,276✔
854
                        r = parse_boolean(val);
5,626✔
855
                        if (r < 0)
5,626✔
856
                                return r;
857
                        c->ip_address_allow_reduced = r;
5,626✔
858
                } else if ((val = startswith(l, "exec-cgroup-context-ip-address-deny-reduced="))) {
5,650✔
859
                        r = parse_boolean(val);
5,626✔
860
                        if (r < 0)
5,626✔
861
                                return r;
862
                        c->ip_address_deny_reduced = r;
5,626✔
863
                } else if ((val = startswith(l, "exec-cgroup-context-ip-ingress-filter-path="))) {
24✔
864
                        r = deserialize_strv(val, &c->ip_filters_ingress);
×
865
                        if (r < 0)
×
866
                                return r;
867
                } else if ((val = startswith(l, "exec-cgroup-context-ip-egress-filter-path="))) {
24✔
868
                        r = deserialize_strv(val, &c->ip_filters_egress);
×
869
                        if (r < 0)
×
870
                                return r;
871
                } else if ((val = startswith(l, "exec-cgroup-context-bpf-program="))) {
24✔
872
                        _cleanup_free_ char *type = NULL, *path = NULL;
×
873
                        uint32_t t;
×
874

875
                        r = extract_many_words(&val, " ", 0, &type, &path);
×
876
                        if (r < 0)
×
877
                                return r;
878
                        if (r != 2)
×
879
                                return -EINVAL;
880

881
                        r = safe_atou32(type, &t);
×
882
                        if (r < 0)
×
883
                                return r;
884

885
                        r = cgroup_context_add_bpf_foreign_program(c, t, path);
×
886
                        if (r < 0)
×
887
                                return r;
888
                } else if ((val = startswith(l, "exec-cgroup-context-socket-bind-allow="))) {
24✔
889
                        CGroupSocketBindItem *item;
×
890
                        uint16_t nr_ports, port_min;
×
891
                        int af, ip_protocol;
×
892

893
                        r = parse_socket_bind_item(val, &af, &ip_protocol, &nr_ports, &port_min);
×
894
                        if (r < 0)
×
895
                                return r;
×
896

897
                        item = new(CGroupSocketBindItem, 1);
×
898
                        if (!item)
×
899
                                return log_oom_debug();
×
900
                        *item = (CGroupSocketBindItem) {
×
901
                                .address_family = af,
902
                                .ip_protocol = ip_protocol,
903
                                .nr_ports = nr_ports,
904
                                .port_min = port_min,
905
                        };
906

907
                        LIST_PREPEND(socket_bind_items, c->socket_bind_allow, item);
×
908
                } else if ((val = startswith(l, "exec-cgroup-context-socket-bind-deny="))) {
24✔
909
                        CGroupSocketBindItem *item;
×
910
                        uint16_t nr_ports, port_min;
×
911
                        int af, ip_protocol;
×
912

913
                        r = parse_socket_bind_item(val, &af, &ip_protocol, &nr_ports, &port_min);
×
914
                        if (r < 0)
×
915
                                return r;
×
916

917
                        item = new(CGroupSocketBindItem, 1);
×
918
                        if (!item)
×
919
                                return log_oom_debug();
×
920
                        *item = (CGroupSocketBindItem) {
×
921
                                .address_family = af,
922
                                .ip_protocol = ip_protocol,
923
                                .nr_ports = nr_ports,
924
                                .port_min = port_min,
925
                        };
926

927
                        LIST_PREPEND(socket_bind_items, c->socket_bind_deny, item);
×
928
                } else if ((val = startswith(l, "exec-cgroup-context-restrict-network-interfaces="))) {
24✔
929
                        r = set_put_strdup(&c->restrict_network_interfaces, val);
15✔
930
                        if (r < 0)
15✔
931
                                return r;
932
                } else if ((val = startswith(l, "exec-cgroup-context-restrict-network-interfaces-is-allow-list="))) {
9✔
933
                        r = parse_boolean(val);
9✔
934
                        if (r < 0)
9✔
935
                                return r;
936
                        c->restrict_network_interfaces_is_allow_list = r;
9✔
937
                } else
938
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
213,583✔
939
        }
940

941
        return 0;
11,500✔
942
}
943

944
static int exec_runtime_serialize(const ExecRuntime *rt, FILE *f, FDSet *fds) {
2,199✔
945
        int r;
2,199✔
946

947
        assert(f);
2,199✔
948
        assert(fds);
2,199✔
949

950
        if (!rt) {
2,199✔
951
                fputc('\n', f); /* End marker */
2,129✔
952
                return 0;
2,129✔
953
        }
954

955
        if (rt->shared) {
70✔
956
                r = serialize_item(f, "exec-runtime-id", rt->shared->id);
69✔
957
                if (r < 0)
69✔
958
                        return r;
959

960
                r = serialize_item(f, "exec-runtime-tmp-dir", rt->shared->tmp_dir);
69✔
961
                if (r < 0)
69✔
962
                        return r;
963

964
                r = serialize_item(f, "exec-runtime-var-tmp-dir", rt->shared->var_tmp_dir);
69✔
965
                if (r < 0)
69✔
966
                        return r;
967

968
                if (rt->shared->netns_storage_socket[0] >= 0 && rt->shared->netns_storage_socket[1] >= 0) {
69✔
969
                        r = serialize_fd_many(f, fds, "exec-runtime-netns-storage-socket", rt->shared->netns_storage_socket, 2);
7✔
970
                        if (r < 0)
7✔
971
                                return r;
972
                }
973

974
                if (rt->shared->ipcns_storage_socket[0] >= 0 && rt->shared->ipcns_storage_socket[1] >= 0) {
69✔
975
                        r = serialize_fd_many(f, fds, "exec-runtime-ipcns-storage-socket", rt->shared->ipcns_storage_socket, 2);
2✔
976
                        if (r < 0)
2✔
977
                                return r;
978
                }
979
        }
980

981
        if (rt->dynamic_creds) {
70✔
982
                r = dynamic_user_serialize_one(rt->dynamic_creds->user, "exec-runtime-dynamic-creds-user", f, fds);
1✔
983
                if (r < 0)
1✔
984
                        return r;
985
        }
986

987
        if (rt->dynamic_creds && rt->dynamic_creds->group && rt->dynamic_creds->group == rt->dynamic_creds->user) {
70✔
988
                r = serialize_bool(f, "exec-runtime-dynamic-creds-group-copy", true);
1✔
989
                if (r < 0)
1✔
990
                        return r;
991
        } else if (rt->dynamic_creds) {
69✔
992
                r = dynamic_user_serialize_one(rt->dynamic_creds->group, "exec-runtime-dynamic-creds-group", f, fds);
×
993
                if (r < 0)
×
994
                        return r;
995
        }
996

997
        r = serialize_item(f, "exec-runtime-ephemeral-copy", rt->ephemeral_copy);
70✔
998
        if (r < 0)
70✔
999
                return r;
1000

1001
        if (rt->ephemeral_storage_socket[0] >= 0 && rt->ephemeral_storage_socket[1] >= 0) {
70✔
1002
                r = serialize_fd_many(f, fds, "exec-runtime-ephemeral-storage-socket", rt->ephemeral_storage_socket, 2);
×
1003
                if (r < 0)
×
1004
                        return r;
1005
        }
1006

1007
        fputc('\n', f); /* End marker */
70✔
1008

1009
        return 0;
70✔
1010
}
1011

1012
static int exec_runtime_deserialize(ExecRuntime *rt, FILE *f, FDSet *fds) {
11,500✔
1013
        int r;
11,500✔
1014

1015
        assert(rt);
11,500✔
1016
        assert(rt->shared);
11,500✔
1017
        assert(rt->dynamic_creds);
11,500✔
1018
        assert(f);
11,500✔
1019
        assert(fds);
11,500✔
1020

1021
        for (;;) {
12,695✔
1022
                _cleanup_free_ char *l = NULL;
1,195✔
1023
                const char *val;
12,695✔
1024

1025
                r = deserialize_read_line(f, &l);
12,695✔
1026
                if (r < 0)
12,695✔
1027
                        return r;
1028
                if (r == 0) /* eof or end marker */
12,695✔
1029
                        break;
1030

1031
                if ((val = startswith(l, "exec-runtime-id="))) {
1,195✔
1032
                        r = free_and_strdup(&rt->shared->id, val);
348✔
1033
                        if (r < 0)
348✔
1034
                                return r;
1035
                } else if ((val = startswith(l, "exec-runtime-tmp-dir="))) {
847✔
1036
                        r = free_and_strdup(&rt->shared->tmp_dir, val);
330✔
1037
                        if (r < 0)
330✔
1038
                                return r;
1039
                } else if ((val = startswith(l, "exec-runtime-var-tmp-dir="))) {
517✔
1040
                        r = free_and_strdup(&rt->shared->var_tmp_dir, val);
330✔
1041
                        if (r < 0)
330✔
1042
                                return r;
1043
                } else if ((val = startswith(l, "exec-runtime-netns-storage-socket="))) {
187✔
1044

1045
                        r = deserialize_fd_many(fds, val, 2, rt->shared->netns_storage_socket);
59✔
1046
                        if (r < 0)
59✔
1047
                                continue;
×
1048

1049
                } else if ((val = startswith(l, "exec-runtime-ipcns-storage-socket="))) {
128✔
1050

1051
                        r = deserialize_fd_many(fds, val, 2, rt->shared->ipcns_storage_socket);
4✔
1052
                        if (r < 0)
4✔
1053
                                continue;
×
1054

1055
                } else if ((val = startswith(l, "exec-runtime-dynamic-creds-user=")))
124✔
1056
                        dynamic_user_deserialize_one(/* m= */ NULL, val, fds, &rt->dynamic_creds->user);
62✔
1057
                else if ((val = startswith(l, "exec-runtime-dynamic-creds-group=")))
62✔
1058
                        dynamic_user_deserialize_one(/* m= */ NULL, val, fds, &rt->dynamic_creds->group);
×
1059
                else if ((val = startswith(l, "exec-runtime-dynamic-creds-group-copy="))) {
62✔
1060
                        r = parse_boolean(val);
62✔
1061
                        if (r < 0)
62✔
1062
                                return r;
1063
                        if (!r)
62✔
1064
                                continue; /* Nothing to do */
×
1065

1066
                        if (!rt->dynamic_creds->user)
62✔
1067
                                return -EINVAL;
1068

1069
                        rt->dynamic_creds->group = dynamic_user_ref(rt->dynamic_creds->user);
62✔
1070
                } else if ((val = startswith(l, "exec-runtime-ephemeral-copy="))) {
×
1071
                        r = free_and_strdup(&rt->ephemeral_copy, val);
×
1072
                        if (r < 0)
×
1073
                                return r;
1074
                } else if ((val = startswith(l, "exec-runtime-ephemeral-storage-socket="))) {
×
1075

1076
                        r = deserialize_fd_many(fds, val, 2, rt->ephemeral_storage_socket);
×
1077
                        if (r < 0)
×
1078
                                continue;
×
1079
                } else
1080
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
1,195✔
1081
        }
1082

1083
        return 0;
11,500✔
1084
}
1085

1086
static bool exec_parameters_is_idle_pipe_set(const ExecParameters *p) {
2,199✔
1087
        assert(p);
2,199✔
1088

1089
        return p->idle_pipe &&
2,227✔
1090
                p->idle_pipe[0] >= 0 &&
28✔
1091
                p->idle_pipe[1] >= 0 &&
26✔
1092
                p->idle_pipe[2] >= 0 &&
2,225✔
1093
                p->idle_pipe[3] >= 0;
26✔
1094
}
1095

1096
static int exec_parameters_serialize(const ExecParameters *p, const ExecContext *c, FILE *f, FDSet *fds) {
2,199✔
1097
        int r;
2,199✔
1098

1099
        assert(f);
2,199✔
1100
        assert(fds);
2,199✔
1101

1102
        if (!p)
2,199✔
1103
                return 0;
1104

1105
        r = serialize_item(f, "exec-parameters-runtime-scope", runtime_scope_to_string(p->runtime_scope));
2,199✔
1106
        if (r < 0)
2,199✔
1107
                return r;
1108

1109
        r = serialize_strv(f, "exec-parameters-environment", p->environment);
2,199✔
1110
        if (r < 0)
2,199✔
1111
                return r;
1112

1113
        if (p->fds) {
2,199✔
1114
                if (p->n_socket_fds > 0) {
364✔
1115
                        r = serialize_item_format(f, "exec-parameters-n-socket-fds", "%zu", p->n_socket_fds);
363✔
1116
                        if (r < 0)
363✔
1117
                                return r;
1118
                }
1119

1120
                if (p->n_storage_fds > 0) {
364✔
1121
                        r = serialize_item_format(f, "exec-parameters-n-storage-fds", "%zu", p->n_storage_fds);
4✔
1122
                        if (r < 0)
4✔
1123
                                return r;
1124
                }
1125

1126
                if (p->n_extra_fds > 0) {
364✔
1127
                        r = serialize_item_format(f, "exec-parameters-n-extra-fds", "%zu", p->n_extra_fds);
1✔
1128
                        if (r < 0)
1✔
1129
                                return r;
1130
                }
1131

1132
                r = serialize_fd_many(f, fds, "exec-parameters-fds", p->fds, p->n_socket_fds + p->n_storage_fds + p->n_extra_fds);
364✔
1133
                if (r < 0)
364✔
1134
                        return r;
1135
        }
1136

1137
        r = serialize_strv(f, "exec-parameters-fd-names", p->fd_names);
2,199✔
1138
        if (r < 0)
2,199✔
1139
                return r;
1140

1141
        if (p->flags != 0) {
2,199✔
1142
                r = serialize_item_format(f, "exec-parameters-flags", "%u", (unsigned) p->flags);
2,199✔
1143
                if (r < 0)
2,199✔
1144
                        return r;
1145
        }
1146

1147
        r = serialize_bool_elide(f, "exec-parameters-selinux-context-net", p->selinux_context_net);
2,199✔
1148
        if (r < 0)
×
1149
                return r;
1150

1151
        if (p->cgroup_supported != 0) {
2,199✔
1152
                r = serialize_item_format(f, "exec-parameters-cgroup-supported", "%u", (unsigned) p->cgroup_supported);
2,199✔
1153
                if (r < 0)
2,199✔
1154
                        return r;
1155
        }
1156

1157
        r = serialize_item(f, "exec-parameters-cgroup-path", p->cgroup_path);
2,199✔
1158
        if (r < 0)
2,199✔
1159
                return r;
1160

1161
        r = serialize_item_format(f, "exec-parameters-cgroup-id", "%" PRIu64, p->cgroup_id);
2,199✔
1162
        if (r < 0)
2,199✔
1163
                return r;
1164

1165
        for (ExecDirectoryType dt = 0; dt < _EXEC_DIRECTORY_TYPE_MAX; dt++) {
13,194✔
1166
                _cleanup_free_ char *key = NULL;
10,995✔
1167

1168
                key = strjoin("exec-parameters-prefix-directories-", exec_directory_type_to_string(dt));
10,995✔
1169
                if (!key)
10,995✔
1170
                        return log_oom_debug();
×
1171

1172
                /* Always serialize, even an empty prefix, as this is a fixed array and we always expect
1173
                 * to have all elements (unless fuzzing is happening, hence the NULL check). */
1174
                r = serialize_item(f, key, strempty(p->prefix ? p->prefix[dt] : NULL));
10,995✔
1175
                if (r < 0)
10,995✔
1176
                        return r;
1177
        }
1178

1179
        r = serialize_item(f, "exec-parameters-received-credentials-directory", p->received_credentials_directory);
2,199✔
1180
        if (r < 0)
2,199✔
1181
                return r;
1182

1183
        r = serialize_item(f, "exec-parameters-received-encrypted-credentials-directory", p->received_encrypted_credentials_directory);
2,199✔
1184
        if (r < 0)
2,199✔
1185
                return r;
1186

1187
        r = serialize_item(f, "exec-parameters-confirm-spawn", p->confirm_spawn);
2,199✔
1188
        if (r < 0)
2,199✔
1189
                return r;
1190

1191
        r = serialize_bool_elide(f, "exec-parameters-shall-confirm-spawn", p->shall_confirm_spawn);
2,199✔
1192
        if (r < 0)
×
1193
                return r;
1194

1195
        if (p->watchdog_usec > 0) {
2,199✔
1196
                r = serialize_usec(f, "exec-parameters-watchdog-usec", p->watchdog_usec);
235✔
1197
                if (r < 0)
235✔
1198
                        return r;
1199
        }
1200

1201
        if (exec_parameters_is_idle_pipe_set(p)) {
2,199✔
1202
                r = serialize_fd_many(f, fds, "exec-parameters-idle-pipe", p->idle_pipe, 4);
26✔
1203
                if (r < 0)
26✔
1204
                        return r;
1205
        }
1206

1207
        r = serialize_fd(f, fds, "exec-parameters-stdin-fd", p->stdin_fd);
2,199✔
1208
        if (r < 0)
2,199✔
1209
                return r;
1210

1211
        r = serialize_fd(f, fds, "exec-parameters-stdout-fd", p->stdout_fd);
2,199✔
1212
        if (r < 0)
2,199✔
1213
                return r;
1214

1215
        r = serialize_fd(f, fds, "exec-parameters-stderr-fd", p->stderr_fd);
2,199✔
1216
        if (r < 0)
2,199✔
1217
                return r;
1218

1219
        r = serialize_fd(f, fds, "exec-parameters-exec-fd", p->exec_fd);
2,199✔
1220
        if (r < 0)
2,199✔
1221
                return r;
1222

1223
        r = serialize_fd(f, fds, "exec-parameters-handoff-timestamp-fd", p->handoff_timestamp_fd);
2,199✔
1224
        if (r < 0)
2,199✔
1225
                return r;
1226

1227
        r = serialize_fd(f, fds, "exec-parameters-pidref-transport-fd", p->pidref_transport_fd);
2,199✔
1228
        if (r < 0)
2,199✔
1229
                return r;
1230

1231
        if (c && exec_context_restrict_filesystems_set(c)) {
2,199✔
1232
                r = serialize_fd(f, fds, "exec-parameters-bpf-outer-map-fd", p->bpf_restrict_fs_map_fd);
×
1233
                if (r < 0)
×
1234
                        return r;
1235
        }
1236

1237
        r = serialize_item(f, "exec-parameters-notify-socket", p->notify_socket);
2,199✔
1238
        if (r < 0)
2,199✔
1239
                return r;
1240

1241
        LIST_FOREACH(open_files, file, p->open_files) {
2,199✔
1242
                _cleanup_free_ char *ofs = NULL;
×
1243

1244
                r = open_file_to_string(file, &ofs);
×
1245
                if (r < 0)
×
1246
                        return r;
1247

1248
                r = serialize_item(f, "exec-parameters-open-file", ofs);
×
1249
                if (r < 0)
×
1250
                        return r;
1251
        }
1252

1253
        r = serialize_item(f, "exec-parameters-fallback-smack-process-label", p->fallback_smack_process_label);
2,199✔
1254
        if (r < 0)
2,199✔
1255
                return r;
1256

1257
        r = serialize_fd(f, fds, "exec-parameters-user-lookup-fd", p->user_lookup_fd);
2,199✔
1258
        if (r < 0)
2,199✔
1259
                return r;
1260

1261
        r = serialize_strv(f, "exec-parameters-files-env", p->files_env);
2,199✔
1262
        if (r < 0)
2,199✔
1263
                return r;
1264

1265
        r = serialize_item(f, "exec-parameters-unit-id", p->unit_id);
2,199✔
1266
        if (r < 0)
2,199✔
1267
                return r;
1268

1269
        r = serialize_item(f, "exec-parameters-invocation-id-string", p->invocation_id_string);
2,199✔
1270
        if (r < 0)
2,199✔
1271
                return r;
1272

1273
        r = serialize_bool_elide(f, "exec-parameters-debug-invocation", p->debug_invocation);
2,199✔
1274
        if (r < 0)
×
1275
                return r;
1276

1277
        fputc('\n', f); /* End marker */
2,199✔
1278

1279
        return 0;
2,199✔
1280
}
1281

1282
static int exec_parameters_deserialize(ExecParameters *p, FILE *f, FDSet *fds) {
11,500✔
1283
        int r, nr_open;
11,500✔
1284

1285
        assert(p);
11,500✔
1286
        assert(f);
11,500✔
1287
        assert(fds);
11,500✔
1288

1289
        nr_open = read_nr_open();
11,500✔
1290
        if (nr_open < 3)
11,500✔
1291
                nr_open = HIGH_RLIMIT_NOFILE;
×
1292
        assert(nr_open > 0); /* For compilers/static analyzers */
11,500✔
1293

1294
        for (;;) {
256,120✔
1295
                _cleanup_free_ char *l = NULL;
244,620✔
1296
                const char *val;
256,120✔
1297

1298
                r = deserialize_read_line(f, &l);
256,120✔
1299
                if (r < 0)
256,120✔
1300
                        return r;
1301
                if (r == 0) /* eof or end marker */
256,120✔
1302
                        break;
1303

1304
                if ((val = startswith(l, "exec-parameters-runtime-scope="))) {
244,620✔
1305
                        p->runtime_scope = runtime_scope_from_string(val);
11,500✔
1306
                        if (p->runtime_scope < 0)
11,500✔
1307
                                return p->runtime_scope;
1308
                } else if ((val = startswith(l, "exec-parameters-environment="))) {
233,120✔
1309
                        r = deserialize_strv(val, &p->environment);
48,261✔
1310
                        if (r < 0)
48,261✔
1311
                                return r;
1312
                } else if ((val = startswith(l, "exec-parameters-n-socket-fds="))) {
184,859✔
1313
                        if (p->fds)
1,919✔
1314
                                return -EINVAL; /* Already received */
1315

1316
                        r = safe_atozu(val, &p->n_socket_fds);
1,919✔
1317
                        if (r < 0)
1,919✔
1318
                                return r;
1319

1320
                        if (p->n_socket_fds > (size_t) nr_open)
1,919✔
1321
                                return -EINVAL; /* too many, someone is playing games with us */
1322
                } else if ((val = startswith(l, "exec-parameters-n-storage-fds="))) {
182,940✔
1323
                        if (p->fds)
137✔
1324
                                return -EINVAL; /* Already received */
1325

1326
                        r = safe_atozu(val, &p->n_storage_fds);
137✔
1327
                        if (r < 0)
137✔
1328
                                return r;
1329

1330
                        if (p->n_storage_fds > (size_t) nr_open)
137✔
1331
                                return -EINVAL; /* too many, someone is playing games with us */
1332
                } else if ((val = startswith(l, "exec-parameters-n-extra-fds="))) {
182,803✔
1333
                        if (p->fds)
2✔
1334
                                return -EINVAL; /* Already received */
1335

1336
                        r = safe_atozu(val, &p->n_extra_fds);
2✔
1337
                        if (r < 0)
2✔
1338
                                return r;
1339

1340
                        if (p->n_extra_fds > (size_t) nr_open)
2✔
1341
                                return -EINVAL; /* too many, someone is playing games with us */
1342
                } else if ((val = startswith(l, "exec-parameters-fds="))) {
182,801✔
1343
                        if (p->n_socket_fds + p->n_storage_fds + p->n_extra_fds == 0)
1,930✔
1344
                                return log_warning_errno(
×
1345
                                                SYNTHETIC_ERRNO(EINVAL),
1346
                                                "Got exec-parameters-fds= without "
1347
                                                "prior exec-parameters-n-socket-fds= or exec-parameters-n-storage-fds= or exec-parameters-n-extra-fds=");
1348
                        if (p->n_socket_fds + p->n_storage_fds + p->n_extra_fds > (size_t) nr_open)
1,930✔
1349
                                return -EINVAL; /* too many, someone is playing games with us */
1350

1351
                        if (p->fds)
1,930✔
1352
                                return -EINVAL; /* duplicated */
1353

1354
                        p->fds = new(int, p->n_socket_fds + p->n_storage_fds + p->n_extra_fds);
1,930✔
1355
                        if (!p->fds)
1,930✔
1356
                                return log_oom_debug();
×
1357

1358
                        /* Ensure we don't leave any FD uninitialized on error, it makes the fuzzer sad */
1359
                        FOREACH_ARRAY(i, p->fds, p->n_socket_fds + p->n_storage_fds + p->n_extra_fds)
5,220✔
1360
                                *i = -EBADF;
3,290✔
1361

1362
                        r = deserialize_fd_many(fds, val, p->n_socket_fds + p->n_storage_fds + p->n_extra_fds, p->fds);
1,930✔
1363
                        if (r < 0)
1,930✔
1364
                                continue;
×
1365

1366
                } else if ((val = startswith(l, "exec-parameters-fd-names="))) {
180,871✔
1367
                        r = deserialize_strv(val, &p->fd_names);
3,290✔
1368
                        if (r < 0)
3,290✔
1369
                                return r;
1370
                } else if ((val = startswith(l, "exec-parameters-flags="))) {
177,581✔
1371
                        unsigned flags;
11,500✔
1372

1373
                        r = safe_atou(val, &flags);
11,500✔
1374
                        if (r < 0)
11,500✔
1375
                                return r;
×
1376
                        p->flags = flags;
11,500✔
1377
                } else if ((val = startswith(l, "exec-parameters-selinux-context-net="))) {
166,081✔
1378
                        r = parse_boolean(val);
×
1379
                        if (r < 0)
×
1380
                                return r;
1381

1382
                        p->selinux_context_net = r;
×
1383
                } else if ((val = startswith(l, "exec-parameters-cgroup-supported="))) {
166,081✔
1384
                        unsigned cgroup_supported;
11,500✔
1385

1386
                        r = safe_atou(val, &cgroup_supported);
11,500✔
1387
                        if (r < 0)
11,500✔
1388
                                return r;
×
1389
                        p->cgroup_supported = cgroup_supported;
11,500✔
1390
                } else if ((val = startswith(l, "exec-parameters-cgroup-path="))) {
154,581✔
1391
                        r = free_and_strdup(&p->cgroup_path, val);
11,500✔
1392
                        if (r < 0)
11,500✔
1393
                                return r;
1394
                } else if ((val = startswith(l, "exec-parameters-cgroup-id="))) {
143,081✔
1395
                        r = safe_atou64(val, &p->cgroup_id);
11,500✔
1396
                        if (r < 0)
11,500✔
1397
                                return r;
1398
                } else if ((val = startswith(l, "exec-parameters-prefix-directories-"))) {
131,581✔
1399
                        _cleanup_free_ char *type = NULL, *prefix = NULL;
57,500✔
1400
                        ExecDirectoryType dt;
57,500✔
1401

1402
                        r = extract_many_words(&val, "= ", 0, &type, &prefix);
57,500✔
1403
                        if (r < 0)
57,500✔
1404
                                return r;
1405
                        if (r == 0)
57,500✔
1406
                                return -EINVAL;
1407

1408
                        dt = exec_directory_type_from_string(type);
57,500✔
1409
                        if (dt < 0)
57,500✔
1410
                                return -EINVAL;
1411

1412
                        if (!p->prefix) {
57,500✔
1413
                                p->prefix = new0(char*, _EXEC_DIRECTORY_TYPE_MAX+1);
11,500✔
1414
                                if (!p->prefix)
11,500✔
1415
                                        return log_oom_debug();
×
1416
                        }
1417

1418
                        if (isempty(prefix))
57,500✔
1419
                                p->prefix[dt] = mfree(p->prefix[dt]);
×
1420
                        else
1421
                                free_and_replace(p->prefix[dt], prefix);
57,500✔
1422
                } else if ((val = startswith(l, "exec-parameters-received-credentials-directory="))) {
74,081✔
1423
                        r = free_and_strdup(&p->received_credentials_directory, val);
10,712✔
1424
                        if (r < 0)
10,712✔
1425
                                return r;
1426
                } else if ((val = startswith(l, "exec-parameters-received-encrypted-credentials-directory="))) {
63,369✔
1427
                        r = free_and_strdup(&p->received_encrypted_credentials_directory, val);
×
1428
                        if (r < 0)
×
1429
                                return r;
1430
                } else if ((val = startswith(l, "exec-parameters-confirm-spawn="))) {
63,369✔
1431
                        r = free_and_strdup(&p->confirm_spawn, val);
×
1432
                        if (r < 0)
×
1433
                                return r;
1434
                } else if ((val = startswith(l, "exec-parameters-shall-confirm-spawn="))) {
63,369✔
1435
                        r = parse_boolean(val);
×
1436
                        if (r < 0)
×
1437
                                return r;
1438

1439
                        p->shall_confirm_spawn = r;
×
1440
                } else if ((val = startswith(l, "exec-parameters-watchdog-usec="))) {
63,369✔
1441
                        r = deserialize_usec(val, &p->watchdog_usec);
2,210✔
1442
                        if (r < 0)
2,210✔
1443
                                return r;
1444
                } else if ((val = startswith(l, "exec-parameters-idle-pipe="))) {
61,159✔
1445
                        if (p->idle_pipe)
150✔
1446
                                return -EINVAL; /* duplicated */
1447

1448
                        p->idle_pipe = new(int, 4);
150✔
1449
                        if (!p->idle_pipe)
150✔
1450
                                return log_oom_debug();
×
1451

1452
                        p->idle_pipe[0] = p->idle_pipe[1] = p->idle_pipe[2] = p->idle_pipe[3] = -EBADF;
150✔
1453

1454
                        r = deserialize_fd_many(fds, val, 4, p->idle_pipe);
150✔
1455
                        if (r < 0)
150✔
1456
                                continue;
×
1457

1458
                } else if ((val = startswith(l, "exec-parameters-stdin-fd="))) {
61,009✔
1459
                        int fd;
525✔
1460

1461
                        fd = deserialize_fd(fds, val);
525✔
1462
                        if (fd < 0)
525✔
1463
                                continue;
×
1464

1465
                        close_and_replace(p->stdin_fd, fd);
525✔
1466

1467
                } else if ((val = startswith(l, "exec-parameters-stdout-fd="))) {
60,484✔
1468
                        int fd;
525✔
1469

1470
                        fd = deserialize_fd(fds, val);
525✔
1471
                        if (fd < 0)
525✔
1472
                                continue;
×
1473

1474
                        close_and_replace(p->stdout_fd, fd);
525✔
1475

1476
                } else if ((val = startswith(l, "exec-parameters-stderr-fd="))) {
59,959✔
1477
                        int fd;
525✔
1478

1479
                        fd = deserialize_fd(fds, val);
525✔
1480
                        if (fd < 0)
525✔
1481
                                continue;
×
1482

1483
                        close_and_replace(p->stderr_fd, fd);
525✔
1484
                } else if ((val = startswith(l, "exec-parameters-exec-fd="))) {
59,434✔
1485
                        int fd;
381✔
1486

1487
                        fd = deserialize_fd(fds, val);
381✔
1488
                        if (fd < 0)
381✔
1489
                                continue;
×
1490

1491
                        close_and_replace(p->exec_fd, fd);
381✔
1492
                } else if ((val = startswith(l, "exec-parameters-handoff-timestamp-fd="))) {
59,053✔
1493
                        int fd;
11,500✔
1494

1495
                        fd = deserialize_fd(fds, val);
11,500✔
1496
                        if (fd < 0)
11,500✔
1497
                                continue;
×
1498

1499
                        close_and_replace(p->handoff_timestamp_fd, fd);
11,500✔
1500
                } else if ((val = startswith(l, "exec-parameters-pidref-transport-fd="))) {
47,553✔
1501
                        int fd;
10,449✔
1502

1503
                        fd = deserialize_fd(fds, val);
10,449✔
1504
                        if (fd < 0)
10,449✔
1505
                                continue;
×
1506

1507
                        close_and_replace(p->pidref_transport_fd, fd);
10,449✔
1508
                } else if ((val = startswith(l, "exec-parameters-bpf-outer-map-fd="))) {
37,104✔
1509
                        int fd;
×
1510

1511
                        fd = deserialize_fd(fds, val);
×
1512
                        if (fd < 0)
×
1513
                                continue;
×
1514

1515
                        close_and_replace(p->bpf_restrict_fs_map_fd, fd);
×
1516
                } else if ((val = startswith(l, "exec-parameters-notify-socket="))) {
37,104✔
1517
                        r = free_and_strdup(&p->notify_socket, val);
2,595✔
1518
                        if (r < 0)
2,595✔
1519
                                return r;
1520
                } else if ((val = startswith(l, "exec-parameters-open-file="))) {
34,509✔
1521
                        OpenFile *of;
5✔
1522

1523
                        r = open_file_parse(val, &of);
5✔
1524
                        if (r < 0)
5✔
1525
                                return r;
×
1526

1527
                        LIST_APPEND(open_files, p->open_files, of);
5✔
1528
                } else if ((val = startswith(l, "exec-parameters-fallback-smack-process-label="))) {
34,504✔
1529
                        r = free_and_strdup(&p->fallback_smack_process_label, val);
×
1530
                        if (r < 0)
×
1531
                                return r;
1532
                } else if ((val = startswith(l, "exec-parameters-user-lookup-fd="))) {
34,504✔
1533
                        int fd;
11,500✔
1534

1535
                        fd = deserialize_fd(fds, val);
11,500✔
1536
                        if (fd < 0)
11,500✔
1537
                                continue;
×
1538

1539
                        close_and_replace(p->user_lookup_fd, fd);
11,500✔
1540
                } else if ((val = startswith(l, "exec-parameters-files-env="))) {
23,004✔
1541
                        r = deserialize_strv(val, &p->files_env);
2✔
1542
                        if (r < 0)
2✔
1543
                                return r;
1544
                } else if ((val = startswith(l, "exec-parameters-unit-id="))) {
23,002✔
1545
                        r = free_and_strdup(&p->unit_id, val);
11,500✔
1546
                        if (r < 0)
11,500✔
1547
                                return r;
1548
                } else if ((val = startswith(l, "exec-parameters-invocation-id-string="))) {
11,502✔
1549
                        if (strlen(val) > SD_ID128_STRING_MAX - 1)
11,500✔
1550
                                return -EINVAL;
1551

1552
                        r = sd_id128_from_string(val, &p->invocation_id);
11,500✔
1553
                        if (r < 0)
11,500✔
1554
                                return r;
1555

1556
                        sd_id128_to_string(p->invocation_id, p->invocation_id_string);
11,500✔
1557
                } else if ((val = startswith(l, "exec-parameters-debug-invocation="))) {
2✔
1558
                        r = parse_boolean(val);
2✔
1559
                        if (r < 0)
2✔
1560
                                return r;
1561

1562
                        p->debug_invocation = r;
2✔
1563
                } else
1564
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
244,620✔
1565
        }
1566

1567
        /* Bail out if we got exec-parameters-n-{socket/storage}-fds= but no corresponding
1568
         * exec-parameters-fds= */
1569
        if (p->n_socket_fds + p->n_storage_fds > 0 && !p->fds)
11,500✔
1570
                return -EINVAL;
×
1571

1572
        return 0;
1573
}
1574

1575
static int serialize_std_out_err(const ExecContext *c, FILE *f, int fileno) {
4,398✔
1576
        char *key, *value;
4,398✔
1577
        const char *type;
4,398✔
1578

1579
        assert(c);
4,398✔
1580
        assert(f);
4,398✔
1581
        assert(IN_SET(fileno, STDOUT_FILENO, STDERR_FILENO));
4,398✔
1582

1583
        type = fileno == STDOUT_FILENO ? "output" : "error";
4,398✔
1584

1585
        switch (fileno == STDOUT_FILENO ? c->std_output : c->std_error) {
4,398✔
1586
        case EXEC_OUTPUT_NAMED_FD:
×
1587
                key = strjoina("exec-context-std-", type, "-fd-name");
×
1588
                value = c->stdio_fdname[fileno];
×
1589

1590
                break;
×
1591

1592
        case EXEC_OUTPUT_FILE:
2✔
1593
                key = strjoina("exec-context-std-", type, "-file");
14✔
1594
                value = c->stdio_file[fileno];
2✔
1595

1596
                break;
2✔
1597

1598
        case EXEC_OUTPUT_FILE_APPEND:
×
1599
                key = strjoina("exec-context-std-", type, "-file-append");
×
1600
                value = c->stdio_file[fileno];
×
1601

1602
                break;
×
1603

1604
        case EXEC_OUTPUT_FILE_TRUNCATE:
×
1605
                key = strjoina("exec-context-std-", type, "-file-truncate");
×
1606
                value = c->stdio_file[fileno];
×
1607

1608
                break;
×
1609

1610
        default:
1611
                return 0;
1612
        }
1613

1614
        return serialize_item(f, key, value);
2✔
1615
}
1616

1617
static int exec_context_serialize(const ExecContext *c, FILE *f) {
2,199✔
1618
        int r;
2,199✔
1619

1620
        assert(f);
2,199✔
1621

1622
        if (!c)
2,199✔
1623
                return 0;
2,199✔
1624

1625
        r = serialize_strv(f, "exec-context-environment", c->environment);
2,199✔
1626
        if (r < 0)
2,199✔
1627
                return r;
1628

1629
        r = serialize_strv(f, "exec-context-environment-files", c->environment_files);
2,199✔
1630
        if (r < 0)
2,199✔
1631
                return r;
1632

1633
        r = serialize_strv(f, "exec-context-pass-environment", c->pass_environment);
2,199✔
1634
        if (r < 0)
2,199✔
1635
                return r;
1636

1637
        r = serialize_strv(f, "exec-context-unset-environment", c->unset_environment);
2,199✔
1638
        if (r < 0)
2,199✔
1639
                return r;
1640

1641
        r = serialize_item_escaped(f, "exec-context-working-directory", c->working_directory);
2,199✔
1642
        if (r < 0)
2,199✔
1643
                return r;
1644

1645
        r = serialize_bool_elide(f, "exec-context-working-directory-missing-ok", c->working_directory_missing_ok);
2,199✔
1646
        if (r < 0)
789✔
1647
                return r;
1648

1649
        r = serialize_bool_elide(f, "exec-context-working-directory-home", c->working_directory_home);
2,199✔
1650
        if (r < 0)
×
1651
                return r;
1652

1653
        r = serialize_item_escaped(f, "exec-context-root-directory", c->root_directory);
2,199✔
1654
        if (r < 0)
2,199✔
1655
                return r;
1656

1657
        r = serialize_item_escaped(f, "exec-context-root-image", c->root_image);
2,199✔
1658
        if (r < 0)
2,199✔
1659
                return r;
1660

1661
        if (c->root_image_options) {
2,199✔
1662
                _cleanup_free_ char *options = NULL;
×
1663

1664
                LIST_FOREACH(mount_options, o, c->root_image_options) {
×
1665
                        if (isempty(o->options))
×
1666
                                continue;
×
1667

1668
                        _cleanup_free_ char *escaped = NULL;
×
1669
                        escaped = shell_escape(o->options, ":");
×
1670
                        if (!escaped)
×
1671
                                return log_oom_debug();
×
1672

1673
                        if (!strextend(&options,
×
1674
                                        " ",
1675
                                        partition_designator_to_string(o->partition_designator),
1676
                                               ":",
1677
                                               escaped))
1678
                                        return log_oom_debug();
×
1679
                }
1680

1681
                r = serialize_item(f, "exec-context-root-image-options", options);
×
1682
                if (r < 0)
×
1683
                        return r;
1684
        }
1685

1686
        r = serialize_item(f, "exec-context-root-verity", c->root_verity);
2,199✔
1687
        if (r < 0)
2,199✔
1688
                return r;
1689

1690
        r = serialize_item(f, "exec-context-root-hash-path", c->root_hash_path);
2,199✔
1691
        if (r < 0)
2,199✔
1692
                return r;
1693

1694
        r = serialize_item(f, "exec-context-root-hash-sig-path", c->root_hash_sig_path);
2,199✔
1695
        if (r < 0)
2,199✔
1696
                return r;
1697

1698
        r = serialize_item_hexmem(f, "exec-context-root-hash", c->root_hash, c->root_hash_size);
2,199✔
1699
        if (r < 0)
2,199✔
1700
                return r;
1701

1702
        r = serialize_item_base64mem(f, "exec-context-root-hash-sig", c->root_hash_sig, c->root_hash_sig_size);
2,199✔
1703
        if (r < 0)
2,199✔
1704
                return r;
1705

1706
        r = serialize_bool_elide(f, "exec-context-root-ephemeral", c->root_ephemeral);
2,199✔
1707
        if (r < 0)
×
1708
                return r;
1709

1710
        r = serialize_item_format(f, "exec-context-umask", "%04o", c->umask);
2,199✔
1711
        if (r < 0)
2,199✔
1712
                return r;
1713

1714
        r = serialize_bool_elide(f, "exec-context-non-blocking", c->non_blocking);
2,199✔
1715
        if (r < 0)
×
1716
                return r;
1717

1718
        r = serialize_item_tristate(f, "exec-context-private-mounts", c->private_mounts);
2,199✔
1719
        if (r < 0)
25✔
1720
                return r;
1721

1722
        r = serialize_item_tristate(f, "exec-context-mount-api-vfs", c->mount_apivfs);
2,199✔
1723
        if (r < 0)
2✔
1724
                return r;
1725

1726
        r = serialize_item_tristate(f, "exec-context-bind-log-sockets", c->bind_log_sockets);
2,199✔
1727
        if (r < 0)
×
1728
                return r;
1729

1730
        r = serialize_item_tristate(f, "exec-context-memory-ksm", c->memory_ksm);
2,199✔
1731
        if (r < 0)
×
1732
                return r;
1733

1734
        r = serialize_item(f, "exec-context-private-tmp", private_tmp_to_string(c->private_tmp));
2,199✔
1735
        if (r < 0)
2,199✔
1736
                return r;
1737

1738
        r = serialize_bool_elide(f, "exec-context-private-devices", c->private_devices);
2,199✔
1739
        if (r < 0)
152✔
1740
                return r;
1741

1742
        r = serialize_bool_elide(f, "exec-context-protect-kernel-tunables", c->protect_kernel_tunables);
2,199✔
1743
        if (r < 0)
53✔
1744
                return r;
1745

1746
        r = serialize_bool_elide(f, "exec-context-protect-kernel-modules", c->protect_kernel_modules);
2,199✔
1747
        if (r < 0)
167✔
1748
                return r;
1749

1750
        r = serialize_bool_elide(f, "exec-context-protect-kernel-logs", c->protect_kernel_logs);
2,199✔
1751
        if (r < 0)
166✔
1752
                return r;
1753

1754
        r = serialize_bool_elide(f, "exec-context-protect-clock", c->protect_clock);
2,199✔
1755
        if (r < 0)
118✔
1756
                return r;
1757

1758
        r = serialize_item(f, "exec-context-protect-control-groups", protect_control_groups_to_string(c->protect_control_groups));
2,199✔
1759
        if (r < 0)
2,199✔
1760
                return r;
1761

1762
        r = serialize_bool_elide(f, "exec-context-private-network", c->private_network);
2,199✔
1763
        if (r < 0)
7✔
1764
                return r;
1765

1766
        r = serialize_item(f, "exec-context-private-users", private_users_to_string(c->private_users));
2,199✔
1767
        if (r < 0)
2,199✔
1768
                return r;
1769

1770
        r = serialize_bool_elide(f, "exec-context-private-ipc", c->private_ipc);
2,199✔
1771
        if (r < 0)
2✔
1772
                return r;
1773

1774
        r = serialize_item(f, "exec-context-private-pids", private_pids_to_string(c->private_pids));
2,199✔
1775
        if (r < 0)
2,199✔
1776
                return r;
1777

1778
        r = serialize_bool_elide(f, "exec-context-remove-ipc", c->remove_ipc);
2,199✔
1779
        if (r < 0)
2✔
1780
                return r;
1781

1782
        r = serialize_item(f, "exec-context-protect-home", protect_home_to_string(c->protect_home));
2,199✔
1783
        if (r < 0)
2,199✔
1784
                return r;
1785

1786
        r = serialize_item(f, "exec-context-protect-system", protect_system_to_string(c->protect_system));
2,199✔
1787
        if (r < 0)
2,199✔
1788
                return r;
1789

1790
        r = serialize_bool_elide(f, "exec-context-same-pgrp", c->same_pgrp);
2,199✔
1791
        if (r < 0)
172✔
1792
                return r;
1793

1794
        r = serialize_bool(f, "exec-context-ignore-sigpipe", c->ignore_sigpipe);
2,199✔
1795
        if (r < 0)
2,199✔
1796
                return r;
1797

1798
        r = serialize_bool_elide(f, "exec-context-memory-deny-write-execute", c->memory_deny_write_execute);
2,199✔
1799
        if (r < 0)
238✔
1800
                return r;
1801

1802
        r = serialize_bool_elide(f, "exec-context-restrict-realtime", c->restrict_realtime);
2,199✔
1803
        if (r < 0)
238✔
1804
                return r;
1805

1806
        r = serialize_bool_elide(f, "exec-context-restrict-suid-sgid", c->restrict_suid_sgid);
2,199✔
1807
        if (r < 0)
215✔
1808
                return r;
1809

1810
        r = serialize_item(f, "exec-context-keyring-mode", exec_keyring_mode_to_string(c->keyring_mode));
2,199✔
1811
        if (r < 0)
2,199✔
1812
                return r;
1813

1814
        r = serialize_item(f, "exec-context-protect-hostname", protect_hostname_to_string(c->protect_hostname));
2,199✔
1815
        if (r < 0)
2,199✔
1816
                return r;
1817

1818
        r = serialize_item(f, "exec-context-private-hostname", c->private_hostname);
2,199✔
1819
        if (r < 0)
2,199✔
1820
                return r;
1821

1822
        r = serialize_item(f, "exec-context-protect-proc", protect_proc_to_string(c->protect_proc));
2,199✔
1823
        if (r < 0)
2,199✔
1824
                return r;
1825

1826
        r = serialize_item(f, "exec-context-proc-subset", proc_subset_to_string(c->proc_subset));
2,199✔
1827
        if (r < 0)
2,199✔
1828
                return r;
1829

1830
        r = serialize_item(f, "exec-context-runtime-directory-preserve-mode", exec_preserve_mode_to_string(c->runtime_directory_preserve_mode));
2,199✔
1831
        if (r < 0)
2,199✔
1832
                return r;
1833

1834
        for (ExecDirectoryType dt = 0; dt < _EXEC_DIRECTORY_TYPE_MAX; dt++) {
13,194✔
1835
                _cleanup_free_ char *key = NULL, *value = NULL;
10,995✔
1836

1837
                key = strjoin("exec-context-directories-", exec_directory_type_to_string(dt));
10,995✔
1838
                if (!key)
10,995✔
1839
                        return log_oom_debug();
×
1840

1841
                if (asprintf(&value, "%04o", c->directories[dt].mode) < 0)
10,995✔
1842
                        return log_oom_debug();
×
1843

1844
                FOREACH_ARRAY(i, c->directories[dt].items, c->directories[dt].n_items) {
11,427✔
1845
                        _cleanup_free_ char *path_escaped = NULL;
432✔
1846

1847
                        path_escaped = shell_escape(i->path, ":" WHITESPACE);
432✔
1848
                        if (!path_escaped)
432✔
1849
                                return log_oom_debug();
×
1850

1851
                        if (!strextend(&value, " ", path_escaped))
432✔
1852
                                return log_oom_debug();
×
1853

1854
                        if (!strextend(&value, ":", yes_no(FLAGS_SET(i->flags, EXEC_DIRECTORY_ONLY_CREATE))))
859✔
1855
                                return log_oom_debug();
×
1856

1857
                        if (!strextend(&value, ":", yes_no(FLAGS_SET(i->flags, EXEC_DIRECTORY_READ_ONLY))))
862✔
1858
                                return log_oom_debug();
×
1859

1860
                        STRV_FOREACH(d, i->symlinks) {
438✔
1861
                                _cleanup_free_ char *link_escaped = NULL;
6✔
1862

1863
                                link_escaped = shell_escape(*d, ":" WHITESPACE);
6✔
1864
                                if (!link_escaped)
6✔
1865
                                        return log_oom_debug();
×
1866

1867
                                if (!strextend(&value, ":", link_escaped))
6✔
1868
                                        return log_oom_debug();
×
1869
                        }
1870
                }
1871

1872
                r = serialize_item(f, key, value);
10,995✔
1873
                if (r < 0)
10,995✔
1874
                        return r;
1875
        }
1876

1877
        r = serialize_usec(f, "exec-context-timeout-clean-usec", c->timeout_clean_usec);
2,199✔
1878
        if (r < 0)
2,199✔
1879
                return r;
1880

1881
        if (c->nice_set) {
2,199✔
1882
                r = serialize_item_format(f, "exec-context-nice", "%i", c->nice);
2✔
1883
                if (r < 0)
2✔
1884
                        return r;
1885
        }
1886

1887
        if (c->oom_score_adjust_set) {
2,199✔
1888
                r = serialize_item_format(f, "exec-context-oom-score-adjust", "%i", c->oom_score_adjust);
645✔
1889
                if (r < 0)
645✔
1890
                        return r;
1891
        }
1892

1893
        if (c->coredump_filter_set) {
2,199✔
1894
                r = serialize_item_format(f, "exec-context-coredump-filter", "%"PRIx64, c->coredump_filter);
×
1895
                if (r < 0)
×
1896
                        return r;
1897
        }
1898

1899
        for (unsigned i = 0; i < RLIM_NLIMITS; i++) {
37,383✔
1900
                _cleanup_free_ char *key = NULL, *limit = NULL;
4,391✔
1901

1902
                if (!c->rlimit[i])
35,184✔
1903
                        continue;
30,793✔
1904

1905
                key = strjoin("exec-context-limit-", rlimit_to_string(i));
4,391✔
1906
                if (!key)
4,391✔
1907
                        return log_oom_debug();
×
1908

1909
                r = rlimit_format(c->rlimit[i], &limit);
4,391✔
1910
                if (r < 0)
4,391✔
1911
                        return r;
1912

1913
                r = serialize_item(f, key, limit);
4,391✔
1914
                if (r < 0)
4,391✔
1915
                        return r;
1916
        }
1917

1918
        if (c->ioprio_set) {
2,199✔
1919
                r = serialize_item_format(f, "exec-context-ioprio", "%d", c->ioprio);
5✔
1920
                if (r < 0)
5✔
1921
                        return r;
1922
        }
1923

1924
        if (c->cpu_sched_set) {
2,199✔
1925
                _cleanup_free_ char *policy_str = NULL;
×
1926

1927
                r = sched_policy_to_string_alloc(c->cpu_sched_policy, &policy_str);
×
1928
                if (r < 0)
×
1929
                        return r;
1930

1931
                r = serialize_item(f, "exec-context-cpu-scheduling-policy", policy_str);
×
1932
                if (r < 0)
×
1933
                        return r;
1934

1935
                r = serialize_item_format(f, "exec-context-cpu-scheduling-priority", "%i", c->cpu_sched_priority);
×
1936
                if (r < 0)
×
1937
                        return r;
1938

1939
                r = serialize_bool_elide(f, "exec-context-cpu-scheduling-reset-on-fork", c->cpu_sched_reset_on_fork);
×
1940
                if (r < 0)
×
1941
                        return r;
1942
        }
1943

1944
        if (c->cpu_set.set) {
2,199✔
1945
                _cleanup_free_ char *affinity = NULL;
×
1946

1947
                affinity = cpu_set_to_range_string(&c->cpu_set);
×
1948
                if (!affinity)
×
1949
                        return log_oom_debug();
×
1950

1951
                r = serialize_item(f, "exec-context-cpu-affinity", affinity);
×
1952
                if (r < 0)
×
1953
                        return r;
1954
        }
1955

1956
        if (mpol_is_valid(numa_policy_get_type(&c->numa_policy))) {
2,199✔
1957
                _cleanup_free_ char *nodes = NULL;
×
1958

1959
                nodes = cpu_set_to_range_string(&c->numa_policy.nodes);
×
1960
                if (!nodes)
×
1961
                        return log_oom_debug();
×
1962

1963
                if (nodes) {
×
1964
                        r = serialize_item(f, "exec-context-numa-mask", nodes);
×
1965
                        if (r < 0)
×
1966
                                return r;
1967
                }
1968

1969
                r = serialize_item_format(f, "exec-context-numa-policy", "%d", c->numa_policy.type);
×
1970
                if (r < 0)
×
1971
                        return r;
1972
        }
1973

1974
        r = serialize_bool_elide(f, "exec-context-cpu-affinity-from-numa", c->cpu_affinity_from_numa);
2,199✔
1975
        if (r < 0)
×
1976
                return r;
1977

1978
        if (c->timer_slack_nsec != NSEC_INFINITY) {
2,199✔
1979
                r = serialize_item_format(f, "exec-context-timer-slack-nsec", NSEC_FMT, c->timer_slack_nsec);
×
1980
                if (r < 0)
×
1981
                        return r;
1982
        }
1983

1984
        r = serialize_item(f, "exec-context-std-input", exec_input_to_string(c->std_input));
2,199✔
1985
        if (r < 0)
2,199✔
1986
                return r;
1987

1988
        r = serialize_item(f, "exec-context-std-output", exec_output_to_string(c->std_output));
2,199✔
1989
        if (r < 0)
2,199✔
1990
                return r;
1991

1992
        r = serialize_item(f, "exec-context-std-error", exec_output_to_string(c->std_error));
2,199✔
1993
        if (r < 0)
2,199✔
1994
                return r;
1995

1996
        r = serialize_bool_elide(f, "exec-context-stdio-as-fds", c->stdio_as_fds);
2,199✔
1997
        if (r < 0)
80✔
1998
                return r;
1999

2000
        switch (c->std_input) {
2,199✔
2001
        case EXEC_INPUT_NAMED_FD:
×
2002
                r = serialize_item(f, "exec-context-std-input-fd-name", c->stdio_fdname[STDIN_FILENO]);
×
2003
                if (r < 0)
×
2004
                        return r;
2005
                break;
2006

2007
        case EXEC_INPUT_FILE:
×
2008
                r = serialize_item(f, "exec-context-std-input-file", c->stdio_file[STDIN_FILENO]);
×
2009
                if (r < 0)
×
2010
                        return r;
2011
                break;
2012

2013
        default:
2,199✔
2014
                ;
2,199✔
2015
        }
2016

2017
        r = serialize_std_out_err(c, f, STDOUT_FILENO);
2,199✔
2018
        if (r < 0)
2,199✔
2019
                return r;
2020

2021
        r = serialize_std_out_err(c, f, STDERR_FILENO);
2,199✔
2022
        if (r < 0)
2,199✔
2023
                return r;
2024

2025
        r = serialize_item_base64mem(f, "exec-context-stdin-data", c->stdin_data, c->stdin_data_size);
2,199✔
2026
        if (r < 0)
2,199✔
2027
                return r;
2028

2029
        r = serialize_item(f, "exec-context-tty-path", c->tty_path);
2,199✔
2030
        if (r < 0)
2,199✔
2031
                return r;
2032

2033
        r = serialize_bool_elide(f, "exec-context-tty-reset", c->tty_reset);
2,199✔
2034
        if (r < 0)
24✔
2035
                return r;
2036

2037
        r = serialize_bool_elide(f, "exec-context-tty-vhangup", c->tty_vhangup);
2,199✔
2038
        if (r < 0)
24✔
2039
                return r;
2040

2041
        r = serialize_bool_elide(f, "exec-context-tty-vt-disallocate", c->tty_vt_disallocate);
2,199✔
2042
        if (r < 0)
6✔
2043
                return r;
2044

2045
        r = serialize_item_format(f, "exec-context-tty-rows", "%u", c->tty_rows);
2,199✔
2046
        if (r < 0)
2,199✔
2047
                return r;
2048

2049
        r = serialize_item_format(f, "exec-context-tty-columns", "%u", c->tty_cols);
2,199✔
2050
        if (r < 0)
2,199✔
2051
                return r;
2052

2053
        r = serialize_item_format(f, "exec-context-syslog-priority", "%i", c->syslog_priority);
2,199✔
2054
        if (r < 0)
2,199✔
2055
                return r;
2056

2057
        r = serialize_bool(f, "exec-context-syslog-level-prefix", c->syslog_level_prefix);
2,199✔
2058
        if (r < 0)
2,199✔
2059
                return r;
2060

2061
        r = serialize_item(f, "exec-context-syslog-identifier", c->syslog_identifier);
2,199✔
2062
        if (r < 0)
2,199✔
2063
                return r;
2064

2065
        /* This is also passed to executor as an argument. So, the information should be redundant in general.
2066
         * But, let's keep this as is for consistency with other elements of ExecContext. See exec_spawn(). */
2067
        r = serialize_item_format(f, "exec-context-log-level-max", "%d", c->log_level_max);
2,199✔
2068
        if (r < 0)
2,199✔
2069
                return r;
2070

2071
        if (c->log_ratelimit.interval > 0) {
2,199✔
2072
                r = serialize_usec(f, "exec-context-log-ratelimit-interval-usec", c->log_ratelimit.interval);
×
2073
                if (r < 0)
×
2074
                        return r;
2075
        }
2076

2077
        if (c->log_ratelimit.burst > 0) {
2,199✔
2078
                r = serialize_item_format(f, "exec-context-log-ratelimit-burst", "%u", c->log_ratelimit.burst);
×
2079
                if (r < 0)
×
2080
                        return r;
2081
        }
2082

2083
        r = serialize_string_set(f, "exec-context-log-filter-allowed-patterns", c->log_filter_allowed_patterns);
2,199✔
2084
        if (r < 0)
2,199✔
2085
                return r;
2086

2087
        r = serialize_string_set(f, "exec-context-log-filter-denied-patterns", c->log_filter_denied_patterns);
2,199✔
2088
        if (r < 0)
2,199✔
2089
                return r;
2090

2091
        FOREACH_ARRAY(field, c->log_extra_fields, c->n_log_extra_fields) {
2,199✔
2092
                r = serialize_item(f, "exec-context-log-extra-fields", field->iov_base);
×
2093
                if (r < 0)
×
2094
                        return r;
2095
        }
2096

2097
        r = serialize_item(f, "exec-context-log-namespace", c->log_namespace);
2,199✔
2098
        if (r < 0)
2,199✔
2099
                return r;
2100

2101
        if (c->secure_bits != 0) {
2,199✔
2102
                r = serialize_item_format(f, "exec-context-secure-bits", "%d", c->secure_bits);
×
2103
                if (r < 0)
×
2104
                        return r;
2105
        }
2106

2107
        if (c->capability_bounding_set != CAP_MASK_UNSET) {
2,199✔
2108
                r = serialize_item_format(f, "exec-context-capability-bounding-set", "%" PRIu64, c->capability_bounding_set);
276✔
2109
                if (r < 0)
276✔
2110
                        return r;
2111
        }
2112

2113
        if (c->capability_ambient_set != 0) {
2,199✔
2114
                r = serialize_item_format(f, "exec-context-capability-ambient-set", "%" PRIu64, c->capability_ambient_set);
76✔
2115
                if (r < 0)
76✔
2116
                        return r;
2117
        }
2118

2119
        if (c->user) {
2,199✔
2120
                r = serialize_item(f, "exec-context-user", c->user);
157✔
2121
                if (r < 0)
157✔
2122
                        return r;
2123
        }
2124

2125
        r = serialize_item(f, "exec-context-group", c->group);
2,199✔
2126
        if (r < 0)
2,199✔
2127
                return r;
2128

2129
        r = serialize_bool_elide(f, "exec-context-dynamic-user", c->dynamic_user);
2,199✔
2130
        if (r < 0)
1✔
2131
                return r;
2132

2133
        r = serialize_strv(f, "exec-context-supplementary-groups", c->supplementary_groups);
2,199✔
2134
        if (r < 0)
2,199✔
2135
                return r;
2136

2137
        r = serialize_item_tristate(f, "exec-context-set-login-environment", c->set_login_environment);
2,199✔
2138
        if (r < 0)
×
2139
                return r;
2140

2141
        r = serialize_item(f, "exec-context-pam-name", c->pam_name);
2,199✔
2142
        if (r < 0)
2,199✔
2143
                return r;
2144

2145
        r = serialize_strv(f, "exec-context-read-write-paths", c->read_write_paths);
2,199✔
2146
        if (r < 0)
2,199✔
2147
                return r;
2148

2149
        r = serialize_strv(f, "exec-context-read-only-paths", c->read_only_paths);
2,199✔
2150
        if (r < 0)
2,199✔
2151
                return r;
2152

2153
        r = serialize_strv(f, "exec-context-inaccessible-paths", c->inaccessible_paths);
2,199✔
2154
        if (r < 0)
2,199✔
2155
                return r;
2156

2157
        r = serialize_strv(f, "exec-context-exec-paths", c->exec_paths);
2,199✔
2158
        if (r < 0)
2,199✔
2159
                return r;
2160

2161
        r = serialize_strv(f, "exec-context-no-exec-paths", c->no_exec_paths);
2,199✔
2162
        if (r < 0)
2,199✔
2163
                return r;
2164

2165
        r = serialize_strv(f, "exec-context-exec-search-path", c->exec_search_path);
2,199✔
2166
        if (r < 0)
2,199✔
2167
                return r;
2168

2169
        r = serialize_item_format(f, "exec-context-mount-propagation-flag", "%lu", c->mount_propagation_flag);
2,199✔
2170
        if (r < 0)
2,199✔
2171
                return r;
2172

2173
        FOREACH_ARRAY(mount, c->bind_mounts, c->n_bind_mounts) {
2,214✔
2174
                _cleanup_free_ char *src_escaped = NULL, *dst_escaped = NULL;
15✔
2175

2176
                src_escaped = shell_escape(mount->source, ":" WHITESPACE);
15✔
2177
                if (!src_escaped)
15✔
2178
                        return log_oom_debug();
×
2179

2180
                dst_escaped = shell_escape(mount->destination, ":" WHITESPACE);
15✔
2181
                if (!dst_escaped)
15✔
2182
                        return log_oom_debug();
×
2183

2184
                r = serialize_item_format(f,
15✔
2185
                                          mount->read_only ? "exec-context-bind-read-only-path" : "exec-context-bind-path",
15✔
2186
                                          "%s%s:%s:%s",
2187
                                          mount->ignore_enoent ? "-" : "",
15✔
2188
                                          src_escaped,
2189
                                          dst_escaped,
2190
                                          mount->recursive ? "rbind" : "norbind");
15✔
2191
                if (r < 0)
15✔
2192
                        return r;
2193
        }
2194

2195
        FOREACH_ARRAY(tmpfs, c->temporary_filesystems, c->n_temporary_filesystems) {
2,203✔
2196
                _cleanup_free_ char *escaped = NULL;
4✔
2197

2198
                if (!isempty(tmpfs->options)) {
4✔
2199
                        escaped = shell_escape(tmpfs->options, ":");
×
2200
                        if (!escaped)
×
2201
                                return log_oom_debug();
×
2202
                }
2203

2204
                r = serialize_item_format(f, "exec-context-temporary-filesystems", "%s%s%s",
×
2205
                                          tmpfs->path,
2206
                                          isempty(escaped) ? "" : ":",
4✔
2207
                                          strempty(escaped));
2208
                if (r < 0)
4✔
2209
                        return r;
2210
        }
2211

2212
        r = serialize_item(f, "exec-context-utmp-id", c->utmp_id);
2,199✔
2213
        if (r < 0)
2,199✔
2214
                return r;
2215

2216
        r = serialize_item(f, "exec-context-utmp-mode", exec_utmp_mode_to_string(c->utmp_mode));
2,199✔
2217
        if (r < 0)
2,199✔
2218
                return r;
2219

2220
        r = serialize_bool_elide(f, "exec-context-no-new-privileges", c->no_new_privileges);
2,199✔
2221
        if (r < 0)
225✔
2222
                return r;
2223

2224
        if (c->selinux_context) {
2,199✔
2225
                r = serialize_item_format(f, "exec-context-selinux-context",
×
2226
                                          "%s%s",
2227
                                          c->selinux_context_ignore ? "-" : "",
×
2228
                                          c->selinux_context);
2229
                if (r < 0)
×
2230
                        return r;
2231
        }
2232

2233
        if (c->apparmor_profile) {
2,199✔
2234
                r = serialize_item_format(f, "exec-context-apparmor-profile",
×
2235
                                          "%s%s",
2236
                                          c->apparmor_profile_ignore ? "-" : "",
×
2237
                                          c->apparmor_profile);
2238
                if (r < 0)
×
2239
                        return r;
2240
        }
2241

2242
        if (c->smack_process_label) {
2,199✔
2243
                r = serialize_item_format(f, "exec-context-smack-process-label",
×
2244
                                          "%s%s",
2245
                                          c->smack_process_label_ignore ? "-" : "",
×
2246
                                          c->smack_process_label);
2247
                if (r < 0)
×
2248
                        return r;
2249
        }
2250

2251
        if (c->personality != PERSONALITY_INVALID) {
2,199✔
2252
                r = serialize_item(f, "exec-context-personality", personality_to_string(c->personality));
×
2253
                if (r < 0)
×
2254
                        return r;
2255
        }
2256

2257
        r = serialize_bool_elide(f, "exec-context-lock-personality", c->lock_personality);
2,199✔
2258
        if (r < 0)
239✔
2259
                return r;
2260

2261
#if HAVE_SECCOMP
2262
        if (!hashmap_isempty(c->syscall_filter)) {
2,199✔
2263
                void *errno_num, *id;
238✔
2264
                HASHMAP_FOREACH_KEY(errno_num, id, c->syscall_filter) {
93,082✔
2265
                        r = serialize_item_format(f, "exec-context-syscall-filter", "%d %d", PTR_TO_INT(id) - 1, PTR_TO_INT(errno_num));
92,844✔
2266
                        if (r < 0)
92,844✔
2267
                                return r;
×
2268
                }
2269
        }
2270

2271
        if (!set_isempty(c->syscall_archs)) {
2,199✔
2272
                void *id;
238✔
2273
                SET_FOREACH(id, c->syscall_archs) {
476✔
2274
                        r = serialize_item_format(f, "exec-context-syscall-archs", "%u", PTR_TO_UINT(id) - 1);
238✔
2275
                        if (r < 0)
238✔
2276
                                return r;
×
2277
                }
2278
        }
2279

2280
        if (c->syscall_errno > 0) {
2,199✔
2281
                r = serialize_item_format(f, "exec-context-syscall-errno", "%d", c->syscall_errno);
2,199✔
2282
                if (r < 0)
2,199✔
2283
                        return r;
2284
        }
2285

2286
        r = serialize_bool_elide(f, "exec-context-syscall-allow-list", c->syscall_allow_list);
2,199✔
2287
        if (r < 0)
238✔
2288
                return r;
2289

2290
        if (!hashmap_isempty(c->syscall_log)) {
2,199✔
2291
                void *errno_num, *id;
×
2292
                HASHMAP_FOREACH_KEY(errno_num, id, c->syscall_log) {
×
2293
                        r = serialize_item_format(f, "exec-context-syscall-log", "%d %d", PTR_TO_INT(id) - 1, PTR_TO_INT(errno_num));
×
2294
                        if (r < 0)
×
2295
                                return r;
×
2296
                }
2297
        }
2298

2299
        r = serialize_bool_elide(f, "exec-context-syscall-log-allow-list", c->syscall_log_allow_list);
2,199✔
2300
        if (r < 0)
×
2301
                return r;
2302
#endif
2303

2304
        if (c->restrict_namespaces != NAMESPACE_FLAGS_INITIAL) {
2,199✔
2305
                r = serialize_item_format(f, "exec-context-restrict-namespaces", "%lu", c->restrict_namespaces);
188✔
2306
                if (r < 0)
188✔
2307
                        return r;
2308
        }
2309

2310
        if (c->delegate_namespaces != NAMESPACE_FLAGS_INITIAL) {
2,199✔
2311
                r = serialize_item_format(f, "exec-context-delegate-namespaces", "%lu", c->delegate_namespaces);
9✔
2312
                if (r < 0)
9✔
2313
                        return r;
2314
        }
2315

2316
#if HAVE_LIBBPF
2317
        if (exec_context_restrict_filesystems_set(c)) {
2,199✔
2318
                char *fs;
×
2319
                SET_FOREACH(fs, c->restrict_filesystems) {
×
2320
                        r = serialize_item(f, "exec-context-restrict-filesystems", fs);
×
2321
                        if (r < 0)
×
2322
                                return r;
×
2323
                }
2324
        }
2325

2326
        r = serialize_bool_elide(f, "exec-context-restrict-filesystems-allow-list", c->restrict_filesystems_allow_list);
2,199✔
2327
        if (r < 0)
×
2328
                return r;
2329
#endif
2330

2331
        if (!set_isempty(c->address_families)) {
2,199✔
2332
                void *afp;
238✔
2333

2334
                SET_FOREACH(afp, c->address_families) {
1,134✔
2335
                        int af = PTR_TO_INT(afp);
896✔
2336

2337
                        if (af <= 0 || af >= af_max())
896✔
2338
                                continue;
×
2339

2340
                        r = serialize_item_format(f, "exec-context-address-families", "%d", af);
896✔
2341
                        if (r < 0)
896✔
2342
                                return r;
×
2343
                }
2344
        }
2345

2346
        r = serialize_bool_elide(f, "exec-context-address-families-allow-list", c->address_families_allow_list);
2,199✔
2347
        if (r < 0)
238✔
2348
                return r;
2349

2350
        r = serialize_item(f, "exec-context-network-namespace-path", c->network_namespace_path);
2,199✔
2351
        if (r < 0)
2,199✔
2352
                return r;
2353

2354
        r = serialize_item(f, "exec-context-ipc-namespace-path", c->ipc_namespace_path);
2,199✔
2355
        if (r < 0)
2,199✔
2356
                return r;
2357

2358
        FOREACH_ARRAY(mount, c->mount_images, c->n_mount_images) {
2,199✔
2359
                _cleanup_free_ char *s = NULL, *source_escaped = NULL, *dest_escaped = NULL;
×
2360

2361
                source_escaped = shell_escape(mount->source, WHITESPACE);
×
2362
                if (!source_escaped)
×
2363
                        return log_oom_debug();
×
2364

2365
                dest_escaped = shell_escape(mount->destination, WHITESPACE);
×
2366
                if (!dest_escaped)
×
2367
                        return log_oom_debug();
×
2368

2369
                s = strjoin(mount->ignore_enoent ? "-" : "",
×
2370
                            source_escaped,
2371
                            " ",
2372
                            dest_escaped);
2373
                if (!s)
×
2374
                        return log_oom_debug();
×
2375

2376
                LIST_FOREACH(mount_options, o, mount->mount_options) {
×
2377
                        _cleanup_free_ char *escaped = NULL;
×
2378

2379
                        if (isempty(o->options))
×
2380
                                continue;
×
2381

2382
                        escaped = shell_escape(o->options, ":");
×
2383
                        if (!escaped)
×
2384
                                return log_oom_debug();
×
2385

2386
                        if (!strextend(&s,
×
2387
                                       " ",
2388
                                       partition_designator_to_string(o->partition_designator),
2389
                                       ":",
2390
                                       escaped))
2391
                                return log_oom_debug();
×
2392
                }
2393

2394
                r = serialize_item(f, "exec-context-mount-image", s);
×
2395
                if (r < 0)
×
2396
                        return r;
2397
        }
2398

2399
        FOREACH_ARRAY(mount, c->extension_images, c->n_extension_images) {
2,199✔
2400
                _cleanup_free_ char *s = NULL, *source_escaped = NULL;
×
2401

2402
                source_escaped = shell_escape(mount->source, ":" WHITESPACE);
×
2403
                if (!source_escaped)
×
2404
                        return log_oom_debug();
×
2405

2406
                s = strjoin(mount->ignore_enoent ? "-" : "",
×
2407
                            source_escaped);
2408
                if (!s)
×
2409
                        return log_oom_debug();
×
2410

2411
                LIST_FOREACH(mount_options, o, mount->mount_options) {
×
2412
                        _cleanup_free_ char *escaped = NULL;
×
2413

2414
                        if (isempty(o->options))
×
2415
                                continue;
×
2416

2417
                        escaped = shell_escape(o->options, ":");
×
2418
                        if (!escaped)
×
2419
                                return log_oom_debug();
×
2420

2421
                        if (!strextend(&s,
×
2422
                                       " ",
2423
                                       partition_designator_to_string(o->partition_designator),
2424
                                       ":",
2425
                                       escaped))
2426
                                return log_oom_debug();
×
2427
                }
2428

2429
                r = serialize_item(f, "exec-context-extension-image", s);
×
2430
                if (r < 0)
×
2431
                        return r;
2432
        }
2433

2434
        r = serialize_strv(f, "exec-context-extension-directories", c->extension_directories);
2,199✔
2435
        if (r < 0)
2,199✔
2436
                return r;
2437

2438
        ExecSetCredential *sc;
2,199✔
2439
        HASHMAP_FOREACH(sc, c->set_credentials) {
2,199✔
2440
                _cleanup_free_ char *data = NULL;
×
2441

2442
                if (base64mem(sc->data, sc->size, &data) < 0)
×
2443
                        return log_oom_debug();
×
2444

2445
                r = serialize_item_format(f, "exec-context-set-credentials", "%s %s %s", sc->id, data, yes_no(sc->encrypted));
×
2446
                if (r < 0)
×
2447
                        return r;
2448
        }
2449

2450
        ExecLoadCredential *lc;
2,199✔
2451
        HASHMAP_FOREACH(lc, c->load_credentials) {
2,207✔
2452
                r = serialize_item_format(f, "exec-context-load-credentials", "%s %s %s", lc->id, lc->path, yes_no(lc->encrypted));
15✔
2453
                if (r < 0)
8✔
2454
                        return r;
×
2455
        }
2456

2457
        ExecImportCredential *ic;
2,199✔
2458
        ORDERED_SET_FOREACH(ic, c->import_credentials) {
3,008✔
2459
                r = serialize_item_format(f, "exec-context-import-credentials", "%s%s%s",
1,570✔
2460
                                          ic->glob,
2461
                                          ic->rename ? " " : "",
2462
                                          strempty(ic->rename));
809✔
2463
                if (r < 0)
809✔
2464
                        return r;
×
2465
        }
2466

2467
        r = serialize_image_policy(f, "exec-context-root-image-policy", c->root_image_policy);
2,199✔
2468
        if (r < 0)
2,199✔
2469
                return r;
2470

2471
        r = serialize_image_policy(f, "exec-context-mount-image-policy", c->mount_image_policy);
2,199✔
2472
        if (r < 0)
2,199✔
2473
                return r;
2474

2475
        r = serialize_image_policy(f, "exec-context-extension-image-policy", c->extension_image_policy);
2,199✔
2476
        if (r < 0)
2,199✔
2477
                return r;
2478

2479
        fputc('\n', f); /* End marker */
2,199✔
2480

2481
        return 0;
2482
}
2483

2484
static int exec_context_deserialize(ExecContext *c, FILE *f) {
11,500✔
2485
        int r;
11,500✔
2486

2487
        assert(f);
11,500✔
2488

2489
        if (!c)
11,500✔
2490
                return 0;
2491

2492
        for (;;) {
1,280,445✔
2493
                _cleanup_free_ char *l = NULL;
1,268,945✔
2494
                const char *val;
1,280,445✔
2495

2496
                r = deserialize_read_line(f, &l);
1,280,445✔
2497
                if (r < 0)
1,280,445✔
2498
                        return r;
2499
                if (r == 0) /* eof or end marker */
1,280,445✔
2500
                        break;
2501

2502
                if ((val = startswith(l, "exec-context-environment="))) {
1,268,945✔
2503
                        r = deserialize_strv(val, &c->environment);
3,736✔
2504
                        if (r < 0)
3,736✔
2505
                                return r;
2506
                } else if ((val = startswith(l, "exec-context-environment-files="))) {
1,265,209✔
2507
                        r = deserialize_strv(val, &c->environment_files);
335✔
2508
                        if (r < 0)
335✔
2509
                                return r;
2510
                } else if ((val = startswith(l, "exec-context-pass-environment="))) {
1,264,874✔
2511
                        r = deserialize_strv(val, &c->pass_environment);
432✔
2512
                        if (r < 0)
432✔
2513
                                return r;
2514
                } else if ((val = startswith(l, "exec-context-unset-environment="))) {
1,264,442✔
2515
                        r = deserialize_strv(val, &c->unset_environment);
1,432✔
2516
                        if (r < 0)
1,432✔
2517
                                return r;
2518
                } else if ((val = startswith(l, "exec-context-working-directory="))) {
1,263,010✔
2519
                        ssize_t k;
851✔
2520
                        char *p;
851✔
2521

2522
                        k = cunescape(val, 0, &p);
851✔
2523
                        if (k < 0)
851✔
2524
                                return k;
×
2525
                        free_and_replace(c->working_directory, p);
851✔
2526
                } else if ((val = startswith(l, "exec-context-root-directory="))) {
1,262,159✔
2527
                        ssize_t k;
5✔
2528
                        char *p;
5✔
2529

2530
                        k = cunescape(val, 0, &p);
5✔
2531
                        if (k < 0)
5✔
2532
                                return k;
×
2533
                        free_and_replace(c->root_directory, p);
5✔
2534
                } else if ((val = startswith(l, "exec-context-root-image="))) {
1,262,154✔
2535
                        ssize_t k;
8✔
2536
                        char *p;
8✔
2537

2538
                        k = cunescape(val, 0, &p);
8✔
2539
                        if (k < 0)
8✔
2540
                                return k;
×
2541
                        free_and_replace(c->root_image, p);
8✔
2542
                } else if ((val = startswith(l, "exec-context-root-image-options="))) {
1,262,146✔
2543
                        for (;;) {
×
2544
                                _cleanup_free_ char *word = NULL, *mount_options = NULL, *partition = NULL;
×
2545
                                PartitionDesignator partition_designator;
×
2546
                                MountOptions *o = NULL;
×
2547
                                const char *p;
×
2548

2549
                                r = extract_first_word(&val, &word, NULL, 0);
×
2550
                                if (r < 0)
×
2551
                                        return r;
2552
                                if (r == 0)
×
2553
                                        break;
2554

2555
                                p = word;
×
2556
                                r = extract_many_words(&p, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &partition, &mount_options);
×
2557
                                if (r < 0)
×
2558
                                        return r;
2559
                                if (r == 0)
×
2560
                                        continue;
×
2561

2562
                                partition_designator = partition_designator_from_string(partition);
×
2563
                                if (partition_designator < 0)
×
2564
                                        return -EINVAL;
2565

2566
                                o = new(MountOptions, 1);
×
2567
                                if (!o)
×
2568
                                        return log_oom_debug();
×
2569
                                *o = (MountOptions) {
×
2570
                                        .partition_designator = partition_designator,
2571
                                        .options = TAKE_PTR(mount_options),
×
2572
                                };
2573
                                LIST_APPEND(mount_options, c->root_image_options, o);
×
2574
                        }
2575
                } else if ((val = startswith(l, "exec-context-root-verity="))) {
1,262,146✔
2576
                        r = free_and_strdup(&c->root_verity, val);
×
2577
                        if (r < 0)
×
2578
                                return r;
2579
                } else if ((val = startswith(l, "exec-context-root-hash-path="))) {
1,262,146✔
2580
                        r = free_and_strdup(&c->root_hash_path, val);
×
2581
                        if (r < 0)
×
2582
                                return r;
2583
                } else if ((val = startswith(l, "exec-context-root-hash-sig-path="))) {
1,262,146✔
2584
                        r = free_and_strdup(&c->root_hash_sig_path, val);
×
2585
                        if (r < 0)
×
2586
                                return r;
2587
                } else if ((val = startswith(l, "exec-context-root-hash="))) {
1,262,146✔
2588
                        c->root_hash = mfree(c->root_hash);
4✔
2589
                        r = unhexmem(val, &c->root_hash, &c->root_hash_size);
4✔
2590
                        if (r < 0)
4✔
2591
                                return r;
2592
                } else if ((val = startswith(l, "exec-context-root-hash-sig="))) {
1,262,142✔
2593
                        c->root_hash_sig = mfree(c->root_hash_sig);
×
2594
                        r= unbase64mem(val, &c->root_hash_sig, &c->root_hash_sig_size);
×
2595
                        if (r < 0)
×
2596
                                return r;
2597
                } else if ((val = startswith(l, "exec-context-root-ephemeral="))) {
1,262,142✔
2598
                        r = parse_boolean(val);
×
2599
                        if (r < 0)
×
2600
                                return r;
2601
                        c->root_ephemeral = r;
×
2602
                } else if ((val = startswith(l, "exec-context-umask="))) {
1,262,142✔
2603
                        r = parse_mode(val, &c->umask);
11,500✔
2604
                        if (r < 0)
11,500✔
2605
                                return r;
2606
                } else if ((val = startswith(l, "exec-context-private-non-blocking="))) {
1,250,642✔
2607
                        r = parse_boolean(val);
×
2608
                        if (r < 0)
×
2609
                                return r;
2610
                        c->non_blocking = r;
×
2611
                } else if ((val = startswith(l, "exec-context-private-mounts="))) {
1,250,642✔
2612
                        r = safe_atoi(val, &c->private_mounts);
125✔
2613
                        if (r < 0)
125✔
2614
                                return r;
2615
                } else if ((val = startswith(l, "exec-context-mount-api-vfs="))) {
1,250,517✔
2616
                        r = safe_atoi(val, &c->mount_apivfs);
30✔
2617
                        if (r < 0)
30✔
2618
                                return r;
2619
                } else if ((val = startswith(l, "exec-context-bind-log-sockets="))) {
1,250,487✔
2620
                        r = safe_atoi(val, &c->bind_log_sockets);
×
2621
                        if (r < 0)
×
2622
                                return r;
2623
                } else if ((val = startswith(l, "exec-context-memory-ksm="))) {
1,250,487✔
2624
                        r = safe_atoi(val, &c->memory_ksm);
×
2625
                        if (r < 0)
×
2626
                                return r;
2627
                } else if ((val = startswith(l, "exec-context-private-tmp="))) {
1,250,487✔
2628
                        c->private_tmp = private_tmp_from_string(val);
11,500✔
2629
                        if (c->private_tmp < 0)
11,500✔
2630
                                return c->private_tmp;
2631
                } else if ((val = startswith(l, "exec-context-private-devices="))) {
1,238,987✔
2632
                        r = parse_boolean(val);
840✔
2633
                        if (r < 0)
840✔
2634
                                return r;
2635
                        c->private_devices = r;
840✔
2636
                } else if ((val = startswith(l, "exec-context-protect-kernel-tunables="))) {
1,238,147✔
2637
                        r = parse_boolean(val);
528✔
2638
                        if (r < 0)
528✔
2639
                                return r;
2640
                        c->protect_kernel_tunables = r;
528✔
2641
                } else if ((val = startswith(l, "exec-context-protect-kernel-modules="))) {
1,237,619✔
2642
                        r = parse_boolean(val);
1,710✔
2643
                        if (r < 0)
1,710✔
2644
                                return r;
2645
                        c->protect_kernel_modules = r;
1,710✔
2646
                } else if ((val = startswith(l, "exec-context-protect-kernel-logs="))) {
1,235,909✔
2647
                        r = parse_boolean(val);
1,710✔
2648
                        if (r < 0)
1,710✔
2649
                                return r;
2650
                        c->protect_kernel_logs = r;
1,710✔
2651
                } else if ((val = startswith(l, "exec-context-protect-clock="))) {
1,234,199✔
2652
                        r = parse_boolean(val);
1,548✔
2653
                        if (r < 0)
1,548✔
2654
                                return r;
2655
                        c->protect_clock = r;
1,548✔
2656
                } else if ((val = startswith(l, "exec-context-protect-control-groups="))) {
1,232,651✔
2657
                        r = protect_control_groups_from_string(val);
11,500✔
2658
                        if (r < 0)
11,500✔
2659
                                return r;
2660
                        c->protect_control_groups = r;
11,500✔
2661
                } else if ((val = startswith(l, "exec-context-private-network="))) {
1,221,151✔
2662
                        r = parse_boolean(val);
59✔
2663
                        if (r < 0)
59✔
2664
                                return r;
2665
                        c->private_network = r;
59✔
2666
                } else if ((val = startswith(l, "exec-context-private-users="))) {
1,221,092✔
2667
                        c->private_users = private_users_from_string(val);
11,500✔
2668
                        if (c->private_users < 0)
11,500✔
2669
                                return -EINVAL;
2670
                } else if ((val = startswith(l, "exec-context-private-ipc="))) {
1,209,592✔
2671
                        r = parse_boolean(val);
4✔
2672
                        if (r < 0)
4✔
2673
                                return r;
2674
                        c->private_ipc = r;
4✔
2675
                } else if ((val = startswith(l, "exec-context-private-pids="))) {
1,209,588✔
2676
                        c->private_pids = private_pids_from_string(val);
11,500✔
2677
                        if (c->private_pids < 0)
11,500✔
2678
                                return -EINVAL;
2679
                } else if ((val = startswith(l, "exec-context-remove-ipc="))) {
1,198,088✔
2680
                        r = parse_boolean(val);
70✔
2681
                        if (r < 0)
70✔
2682
                                return r;
2683
                        c->remove_ipc = r;
70✔
2684
                } else if ((val = startswith(l, "exec-context-protect-home="))) {
1,198,018✔
2685
                        c->protect_home = protect_home_from_string(val);
11,500✔
2686
                        if (c->protect_home < 0)
11,500✔
2687
                                return -EINVAL;
2688
                } else if ((val = startswith(l, "exec-context-protect-system="))) {
1,186,518✔
2689
                        c->protect_system = protect_system_from_string(val);
11,500✔
2690
                        if (c->protect_system < 0)
11,500✔
2691
                                return -EINVAL;
2692
                } else if ((val = startswith(l, "exec-context-same-pgrp="))) {
1,175,018✔
2693
                        r = parse_boolean(val);
868✔
2694
                        if (r < 0)
868✔
2695
                                return r;
2696
                        c->same_pgrp = r;
868✔
2697
                } else if ((val = startswith(l, "exec-context-non-blocking="))) {
1,174,150✔
2698
                        r = parse_boolean(val);
×
2699
                        if (r < 0)
×
2700
                                return r;
2701
                        c->non_blocking = r;
×
2702
                } else if ((val = startswith(l, "exec-context-ignore-sigpipe="))) {
1,174,150✔
2703
                        r = parse_boolean(val);
11,500✔
2704
                        if (r < 0)
11,500✔
2705
                                return r;
2706
                        c->ignore_sigpipe = r;
11,500✔
2707
                } else if ((val = startswith(l, "exec-context-memory-deny-write-execute="))) {
1,162,650✔
2708
                        r = parse_boolean(val);
2,199✔
2709
                        if (r < 0)
2,199✔
2710
                                return r;
2711
                        c->memory_deny_write_execute = r;
2,199✔
2712
                } else if ((val = startswith(l, "exec-context-restrict-realtime="))) {
1,160,451✔
2713
                        r = parse_boolean(val);
2,199✔
2714
                        if (r < 0)
2,199✔
2715
                                return r;
2716
                        c->restrict_realtime = r;
2,199✔
2717
                } else if ((val = startswith(l, "exec-context-restrict-suid-sgid="))) {
1,158,252✔
2718
                        r = parse_boolean(val);
2,138✔
2719
                        if (r < 0)
2,138✔
2720
                                return r;
2721
                        c->restrict_suid_sgid = r;
2,138✔
2722
                } else if ((val = startswith(l, "exec-context-keyring-mode="))) {
1,156,114✔
2723
                        c->keyring_mode = exec_keyring_mode_from_string(val);
11,500✔
2724
                        if (c->keyring_mode < 0)
11,500✔
2725
                                return -EINVAL;
2726
                } else if ((val = startswith(l, "exec-context-protect-hostname="))) {
1,144,614✔
2727
                        c->protect_hostname = protect_hostname_from_string(val);
11,500✔
2728
                        if (c->protect_hostname < 0)
11,500✔
2729
                                return -EINVAL;
2730
                } else if ((val = startswith(l, "exec-context-private-hostname="))) {
1,133,114✔
2731
                        r = free_and_strdup(&c->private_hostname, val);
4✔
2732
                        if (r < 0)
4✔
2733
                                return r;
2734
                } else if ((val = startswith(l, "exec-context-protect-proc="))) {
1,133,110✔
2735
                        c->protect_proc = protect_proc_from_string(val);
11,500✔
2736
                        if (c->protect_proc < 0)
11,500✔
2737
                                return -EINVAL;
2738
                } else if ((val = startswith(l, "exec-context-proc-subset="))) {
1,121,610✔
2739
                        c->proc_subset = proc_subset_from_string(val);
11,500✔
2740
                        if (c->proc_subset < 0)
11,500✔
2741
                                return -EINVAL;
2742
                } else if ((val = startswith(l, "exec-context-runtime-directory-preserve-mode="))) {
1,110,110✔
2743
                        c->runtime_directory_preserve_mode = exec_preserve_mode_from_string(val);
11,500✔
2744
                        if (c->runtime_directory_preserve_mode < 0)
11,500✔
2745
                                return -EINVAL;
2746
                } else if ((val = startswith(l, "exec-context-directories-"))) {
1,098,610✔
2747
                        _cleanup_free_ char *type = NULL, *mode = NULL;
×
2748
                        ExecDirectoryType dt;
57,500✔
2749

2750
                        r = extract_many_words(&val, "= ", 0, &type, &mode);
57,500✔
2751
                        if (r < 0)
57,500✔
2752
                                return r;
2753
                        if (r == 0 || !mode)
57,500✔
2754
                                return -EINVAL;
2755

2756
                        dt = exec_directory_type_from_string(type);
57,500✔
2757
                        if (dt < 0)
57,500✔
2758
                                return -EINVAL;
2759

2760
                        r = parse_mode(mode, &c->directories[dt].mode);
57,500✔
2761
                        if (r < 0)
57,500✔
2762
                                return r;
2763

2764
                        for (;;) {
61,194✔
2765
                                _cleanup_free_ char *tuple = NULL, *path = NULL, *only_create = NULL, *read_only = NULL;
61,087✔
2766
                                ExecDirectoryFlags exec_directory_flags = 0;
61,194✔
2767
                                const char *p;
61,194✔
2768

2769
                                /* Use EXTRACT_UNESCAPE_RELAX here, as we unescape the colons in subsequent calls */
2770
                                r = extract_first_word(&val, &tuple, WHITESPACE, EXTRACT_UNESCAPE_SEPARATORS|EXTRACT_UNESCAPE_RELAX);
61,194✔
2771
                                if (r < 0)
61,194✔
2772
                                        return r;
2773
                                if (r == 0)
61,194✔
2774
                                        break;
2775

2776
                                p = tuple;
3,694✔
2777
                                r = extract_many_words(&p, ":", EXTRACT_UNESCAPE_SEPARATORS, &path, &only_create, &read_only);
3,694✔
2778
                                if (r < 0)
3,694✔
2779
                                        return r;
2780
                                if (r < 2)
3,694✔
2781
                                        continue;
×
2782

2783
                                r = parse_boolean(only_create);
3,694✔
2784
                                if (r < 0)
3,694✔
2785
                                        return r;
2786
                                if (r > 0)
3,694✔
2787
                                        exec_directory_flags |= EXEC_DIRECTORY_ONLY_CREATE;
5✔
2788

2789
                                r = parse_boolean(read_only);
3,694✔
2790
                                if (r < 0)
3,694✔
2791
                                        return r;
2792
                                if (r > 0)
3,694✔
2793
                                        exec_directory_flags |= EXEC_DIRECTORY_READ_ONLY;
50✔
2794

2795
                                r = exec_directory_add(&c->directories[dt], path, /* symlink= */ NULL, exec_directory_flags);
3,694✔
2796
                                if (r < 0)
3,694✔
2797
                                        return r;
2798

2799
                                if (isempty(p))
3,694✔
2800
                                        continue;
3,587✔
2801

2802
                                for (;;) {
385✔
2803
                                        _cleanup_free_ char *link = NULL;
246✔
2804

2805
                                        r = extract_first_word(&p, &link, ":", EXTRACT_UNESCAPE_SEPARATORS);
246✔
2806
                                        if (r < 0)
246✔
2807
                                                return r;
2808
                                        if (r == 0)
246✔
2809
                                                break;
2810

2811
                                        r = strv_consume(&c->directories[dt].items[c->directories[dt].n_items - 1].symlinks, TAKE_PTR(link));
139✔
2812
                                        if (r < 0)
139✔
2813
                                                return r;
2814
                                }
2815
                        }
2816
                } else if ((val = startswith(l, "exec-context-timeout-clean-usec="))) {
1,041,110✔
2817
                        r = deserialize_usec(val, &c->timeout_clean_usec);
×
2818
                        if (r < 0)
×
2819
                                return r;
2820
                } else if ((val = startswith(l, "exec-context-nice="))) {
1,041,110✔
2821
                        r = safe_atoi(val, &c->nice);
15✔
2822
                        if (r < 0)
15✔
2823
                                return r;
2824
                        c->nice_set = true;
15✔
2825
                } else if ((val = startswith(l, "exec-context-working-directory-missing-ok="))) {
1,041,095✔
2826
                        r = parse_boolean(val);
793✔
2827
                        if (r < 0)
793✔
2828
                                return r;
2829
                        c->working_directory_missing_ok = r;
793✔
2830
                } else if ((val = startswith(l, "exec-context-working-directory-home="))) {
1,040,302✔
2831
                        r = parse_boolean(val);
141✔
2832
                        if (r < 0)
141✔
2833
                                return r;
2834
                        c->working_directory_home = r;
141✔
2835
                } else if ((val = startswith(l, "exec-context-oom-score-adjust="))) {
1,040,161✔
2836
                        r = safe_atoi(val, &c->oom_score_adjust);
1,297✔
2837
                        if (r < 0)
1,297✔
2838
                                return r;
2839
                        c->oom_score_adjust_set = true;
1,297✔
2840
                } else if ((val = startswith(l, "exec-context-coredump-filter="))) {
1,038,864✔
2841
                        r = safe_atoux64(val, &c->coredump_filter);
2✔
2842
                        if (r < 0)
2✔
2843
                                return r;
2844
                        c->coredump_filter_set = true;
2✔
2845
                } else if ((val = startswith(l, "exec-context-limit-"))) {
1,038,862✔
2846
                        _cleanup_free_ struct rlimit *rlimit = NULL;
×
2847
                        _cleanup_free_ char *limit = NULL;
22,993✔
2848
                        int type;
22,993✔
2849

2850
                        r = extract_first_word(&val, &limit, "=", 0);
22,993✔
2851
                        if (r < 0)
22,993✔
2852
                                return r;
2853
                        if (r == 0 || !val)
22,993✔
2854
                                return -EINVAL;
2855

2856
                        type = rlimit_from_string(limit);
22,993✔
2857
                        if (type < 0)
22,993✔
2858
                                return -EINVAL;
2859

2860
                        if (!c->rlimit[type]) {
22,993✔
2861
                                rlimit = new0(struct rlimit, 1);
22,993✔
2862
                                if (!rlimit)
22,993✔
2863
                                        return log_oom_debug();
×
2864

2865
                                r = rlimit_parse(type, val, rlimit);
22,993✔
2866
                                if (r < 0)
22,993✔
2867
                                        return r;
2868

2869
                                c->rlimit[type] = TAKE_PTR(rlimit);
22,993✔
2870
                        } else {
2871
                                r = rlimit_parse(type, val, c->rlimit[type]);
×
2872
                                if (r < 0)
×
2873
                                        return r;
2874
                        }
2875
                } else if ((val = startswith(l, "exec-context-ioprio="))) {
1,015,869✔
2876
                        r = safe_atoi(val, &c->ioprio);
9✔
2877
                        if (r < 0)
9✔
2878
                                return r;
2879
                        c->ioprio_set = true;
9✔
2880
                } else if ((val = startswith(l, "exec-context-cpu-scheduling-policy="))) {
1,015,860✔
2881
                        c->cpu_sched_policy = sched_policy_from_string(val);
×
2882
                        if (c->cpu_sched_policy < 0)
×
2883
                                return -EINVAL;
2884
                        c->cpu_sched_set = true;
×
2885
                } else if ((val = startswith(l, "exec-context-cpu-scheduling-priority="))) {
1,015,860✔
2886
                        r = safe_atoi(val, &c->cpu_sched_priority);
×
2887
                        if (r < 0)
×
2888
                                return r;
2889
                        c->cpu_sched_set = true;
×
2890
                } else if ((val = startswith(l, "exec-context-cpu-scheduling-reset-on-fork="))) {
1,015,860✔
2891
                        r = parse_boolean(val);
×
2892
                        if (r < 0)
×
2893
                                return r;
2894
                        c->cpu_sched_reset_on_fork = r;
×
2895
                        c->cpu_sched_set = true;
×
2896
                } else if ((val = startswith(l, "exec-context-cpu-affinity="))) {
1,015,860✔
2897
                        if (c->cpu_set.set)
×
2898
                                return -EINVAL; /* duplicated */
2899

2900
                        r = parse_cpu_set(val, &c->cpu_set);
×
2901
                        if (r < 0)
×
2902
                                return r;
2903
                } else if ((val = startswith(l, "exec-context-numa-mask="))) {
1,015,860✔
2904
                        if (c->numa_policy.nodes.set)
19✔
2905
                                return -EINVAL; /* duplicated */
2906

2907
                        r = parse_cpu_set(val, &c->numa_policy.nodes);
19✔
2908
                        if (r < 0)
19✔
2909
                                return r;
2910
                } else if ((val = startswith(l, "exec-context-numa-policy="))) {
1,015,841✔
2911
                        r = safe_atoi(val, &c->numa_policy.type);
19✔
2912
                        if (r < 0)
19✔
2913
                                return r;
2914
                } else if ((val = startswith(l, "exec-context-cpu-affinity-from-numa="))) {
1,015,822✔
2915
                        r = parse_boolean(val);
2✔
2916
                        if (r < 0)
2✔
2917
                                return r;
2918
                        c->cpu_affinity_from_numa = r;
2✔
2919
                } else if ((val = startswith(l, "exec-context-timer-slack-nsec="))) {
1,015,820✔
2920
                        r = deserialize_usec(val, (usec_t *)&c->timer_slack_nsec);
×
2921
                        if (r < 0)
×
2922
                                return r;
2923
                } else if ((val = startswith(l, "exec-context-std-input="))) {
1,015,820✔
2924
                        c->std_input = exec_input_from_string(val);
11,500✔
2925
                        if (c->std_input < 0)
11,500✔
2926
                                return c->std_input;
2927
                } else if ((val = startswith(l, "exec-context-std-output="))) {
1,004,320✔
2928
                        c->std_output = exec_output_from_string(val);
11,500✔
2929
                        if (c->std_output < 0)
11,500✔
2930
                                return c->std_output;
2931
                } else if ((val = startswith(l, "exec-context-std-error="))) {
992,820✔
2932
                        c->std_error = exec_output_from_string(val);
11,500✔
2933
                        if (c->std_error < 0)
11,500✔
2934
                                return c->std_error;
2935
                } else if ((val = startswith(l, "exec-context-stdio-as-fds="))) {
981,320✔
2936
                        r = parse_boolean(val);
525✔
2937
                        if (r < 0)
525✔
2938
                                return r;
2939
                        c->stdio_as_fds = r;
525✔
2940
                } else if ((val = startswith(l, "exec-context-std-input-fd-name="))) {
980,795✔
2941
                        r = free_and_strdup(&c->stdio_fdname[STDIN_FILENO], val);
×
2942
                        if (r < 0)
×
2943
                                return r;
2944
                } else if ((val = startswith(l, "exec-context-std-output-fd-name="))) {
980,795✔
2945
                        r = free_and_strdup(&c->stdio_fdname[STDOUT_FILENO], val);
×
2946
                        if (r < 0)
×
2947
                                return r;
2948
                } else if ((val = startswith(l, "exec-context-std-error-fd-name="))) {
980,795✔
2949
                        r = free_and_strdup(&c->stdio_fdname[STDERR_FILENO], val);
×
2950
                        if (r < 0)
×
2951
                                return r;
2952
                } else if ((val = startswith(l, "exec-context-std-input-file="))) {
980,795✔
2953
                        r = free_and_strdup(&c->stdio_file[STDIN_FILENO], val);
×
2954
                        if (r < 0)
×
2955
                                return r;
2956
                } else if ((val = startswith(l, "exec-context-std-output-file="))) {
980,795✔
2957
                        r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], val);
4✔
2958
                        if (r < 0)
4✔
2959
                                return r;
2960
                } else if ((val = startswith(l, "exec-context-std-output-file-append="))) {
980,791✔
2961
                        r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], val);
1✔
2962
                        if (r < 0)
1✔
2963
                                return r;
2964
                } else if ((val = startswith(l, "exec-context-std-output-file-truncate="))) {
980,790✔
2965
                        r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], val);
2✔
2966
                        if (r < 0)
2✔
2967
                                return r;
2968
                } else if ((val = startswith(l, "exec-context-std-error-file="))) {
980,788✔
2969
                        r = free_and_strdup(&c->stdio_file[STDERR_FILENO], val);
2✔
2970
                        if (r < 0)
2✔
2971
                                return r;
2972
                } else if ((val = startswith(l, "exec-context-std-error-file-append="))) {
980,786✔
2973
                        r = free_and_strdup(&c->stdio_file[STDERR_FILENO], val);
1✔
2974
                        if (r < 0)
1✔
2975
                                return r;
2976
                } else if ((val = startswith(l, "exec-context-std-error-file-truncate="))) {
980,785✔
2977
                        r = free_and_strdup(&c->stdio_file[STDERR_FILENO], val);
1✔
2978
                        if (r < 0)
1✔
2979
                                return r;
2980
                } else if ((val = startswith(l, "exec-context-stdin-data="))) {
980,784✔
2981
                        if (c->stdin_data)
1✔
2982
                                return -EINVAL; /* duplicated */
2983

2984
                        r = unbase64mem(val, &c->stdin_data, &c->stdin_data_size);
1✔
2985
                        if (r < 0)
1✔
2986
                                return r;
2987
                } else if ((val = startswith(l, "exec-context-tty-path="))) {
980,783✔
2988
                        r = free_and_strdup(&c->tty_path, val);
164✔
2989
                        if (r < 0)
164✔
2990
                                return r;
2991
                } else if ((val = startswith(l, "exec-context-tty-reset="))) {
980,619✔
2992
                        r = parse_boolean(val);
153✔
2993
                        if (r < 0)
153✔
2994
                                return r;
2995
                        c->tty_reset = r;
153✔
2996
                } else if ((val = startswith(l, "exec-context-tty-vhangup="))) {
980,466✔
2997
                        r = parse_boolean(val);
148✔
2998
                        if (r < 0)
148✔
2999
                                return r;
3000
                        c->tty_vhangup = r;
148✔
3001
                } else if ((val = startswith(l, "exec-context-tty-vt-disallocate="))) {
980,318✔
3002
                        r = parse_boolean(val);
86✔
3003
                        if (r < 0)
86✔
3004
                                return r;
3005
                        c->tty_vt_disallocate = r;
86✔
3006
                } else if ((val = startswith(l, "exec-context-tty-rows="))) {
980,232✔
3007
                        r = safe_atou(val, &c->tty_rows);
11,500✔
3008
                        if (r < 0)
11,500✔
3009
                                return r;
3010
                } else if ((val = startswith(l, "exec-context-tty-columns="))) {
968,732✔
3011
                        r = safe_atou(val, &c->tty_cols);
11,500✔
3012
                        if (r < 0)
11,500✔
3013
                                return r;
3014
                } else if ((val = startswith(l, "exec-context-syslog-priority="))) {
957,232✔
3015
                        r = safe_atoi(val, &c->syslog_priority);
11,500✔
3016
                        if (r < 0)
11,500✔
3017
                                return r;
3018
                } else if ((val = startswith(l, "exec-context-syslog-level-prefix="))) {
945,732✔
3019
                        r = parse_boolean(val);
11,500✔
3020
                        if (r < 0)
11,500✔
3021
                                return r;
3022
                        c->syslog_level_prefix = r;
11,500✔
3023
                } else if ((val = startswith(l, "exec-context-syslog-identifier="))) {
934,232✔
3024
                        r = free_and_strdup(&c->syslog_identifier, val);
×
3025
                        if (r < 0)
×
3026
                                return r;
3027
                } else if ((val = startswith(l, "exec-context-log-level-max="))) {
934,232✔
3028
                        /* See comment in serialization. */
3029
                        r = safe_atoi(val, &c->log_level_max);
11,500✔
3030
                        if (r < 0)
11,500✔
3031
                                return r;
3032
                } else if ((val = startswith(l, "exec-context-log-ratelimit-interval-usec="))) {
922,732✔
3033
                        r = deserialize_usec(val, &c->log_ratelimit.interval);
×
3034
                        if (r < 0)
×
3035
                                return r;
3036
                } else if ((val = startswith(l, "exec-context-log-ratelimit-burst="))) {
922,732✔
3037
                        r = safe_atou(val, &c->log_ratelimit.burst);
×
3038
                        if (r < 0)
×
3039
                                return r;
3040
                } else if ((val = startswith(l, "exec-context-log-filter-allowed-patterns="))) {
922,732✔
3041
                        r = set_put_strdup(&c->log_filter_allowed_patterns, val);
9✔
3042
                        if (r < 0)
9✔
3043
                                return r;
3044
                } else if ((val = startswith(l, "exec-context-log-filter-denied-patterns="))) {
922,723✔
3045
                        r = set_put_strdup(&c->log_filter_denied_patterns, val);
5✔
3046
                        if (r < 0)
5✔
3047
                                return r;
3048
                } else if ((val = startswith(l, "exec-context-log-extra-fields="))) {
922,718✔
3049
                        if (!GREEDY_REALLOC(c->log_extra_fields, c->n_log_extra_fields + 1))
583✔
3050
                                return log_oom_debug();
×
3051

3052
                        c->log_extra_fields[c->n_log_extra_fields++].iov_base = strdup(val);
583✔
3053
                        if (!c->log_extra_fields[c->n_log_extra_fields-1].iov_base)
583✔
3054
                                return log_oom_debug();
×
3055
                } else if ((val = startswith(l, "exec-context-log-namespace="))) {
922,135✔
3056
                        r = free_and_strdup(&c->log_namespace, val);
2✔
3057
                        if (r < 0)
2✔
3058
                                return r;
3059
                } else if ((val = startswith(l, "exec-context-secure-bits="))) {
922,133✔
3060
                        r = safe_atoi(val, &c->secure_bits);
×
3061
                        if (r < 0)
×
3062
                                return r;
3063
                } else if ((val = startswith(l, "exec-context-capability-bounding-set="))) {
922,133✔
3064
                        r = safe_atou64(val, &c->capability_bounding_set);
2,330✔
3065
                        if (r < 0)
2,330✔
3066
                                return r;
3067
                } else if ((val = startswith(l, "exec-context-capability-ambient-set="))) {
919,803✔
3068
                        r = safe_atou64(val, &c->capability_ambient_set);
1,269✔
3069
                        if (r < 0)
1,269✔
3070
                                return r;
3071
                } else if ((val = startswith(l, "exec-context-user="))) {
918,534✔
3072
                        r = free_and_strdup(&c->user, val);
2,576✔
3073
                        if (r < 0)
2,576✔
3074
                                return r;
3075
                } else if ((val = startswith(l, "exec-context-group="))) {
915,958✔
3076
                        r = free_and_strdup(&c->group, val);
73✔
3077
                        if (r < 0)
73✔
3078
                                return r;
3079
                } else if ((val = startswith(l, "exec-context-dynamic-user="))) {
915,885✔
3080
                        r = parse_boolean(val);
62✔
3081
                        if (r < 0)
62✔
3082
                                return r;
3083
                        c->dynamic_user = r;
62✔
3084
                } else if ((val = startswith(l, "exec-context-supplementary-groups="))) {
915,823✔
3085
                        r = deserialize_strv(val, &c->supplementary_groups);
9✔
3086
                        if (r < 0)
9✔
3087
                                return r;
3088
                } else if ((val = startswith(l, "exec-context-set-login-environment="))) {
915,814✔
3089
                        r = safe_atoi(val, &c->set_login_environment);
×
3090
                        if (r < 0)
×
3091
                                return r;
3092
                } else if ((val = startswith(l, "exec-context-pam-name="))) {
915,814✔
3093
                        r = free_and_strdup(&c->pam_name, val);
434✔
3094
                        if (r < 0)
434✔
3095
                                return r;
3096
                } else if ((val = startswith(l, "exec-context-read-write-paths="))) {
915,380✔
3097
                        r = deserialize_strv(val, &c->read_write_paths);
806✔
3098
                        if (r < 0)
806✔
3099
                                return r;
3100
                } else if ((val = startswith(l, "exec-context-read-only-paths="))) {
914,574✔
3101
                        r = deserialize_strv(val, &c->read_only_paths);
2✔
3102
                        if (r < 0)
2✔
3103
                                return r;
3104
                } else if ((val = startswith(l, "exec-context-inaccessible-paths="))) {
914,572✔
3105
                        r = deserialize_strv(val, &c->inaccessible_paths);
5✔
3106
                        if (r < 0)
5✔
3107
                                return r;
3108
                } else if ((val = startswith(l, "exec-context-exec-paths="))) {
914,567✔
3109
                        r = deserialize_strv(val, &c->exec_paths);
1✔
3110
                        if (r < 0)
1✔
3111
                                return r;
3112
                } else if ((val = startswith(l, "exec-context-no-exec-paths="))) {
914,566✔
3113
                        r = deserialize_strv(val, &c->no_exec_paths);
1✔
3114
                        if (r < 0)
1✔
3115
                                return r;
3116
                } else if ((val = startswith(l, "exec-context-exec-search-path="))) {
914,565✔
3117
                        r = deserialize_strv(val, &c->exec_search_path);
×
3118
                        if (r < 0)
×
3119
                                return r;
3120
                } else if ((val = startswith(l, "exec-context-mount-propagation-flag="))) {
914,565✔
3121
                        r = safe_atolu(val, &c->mount_propagation_flag);
11,500✔
3122
                        if (r < 0)
11,500✔
3123
                                return r;
3124
                } else if ((val = startswith(l, "exec-context-bind-read-only-path="))) {
903,065✔
3125
                        _cleanup_free_ char *source = NULL, *destination = NULL;
7✔
3126
                        bool rbind = true, ignore_enoent = false;
7✔
3127
                        char *s = NULL, *d = NULL;
7✔
3128

3129
                        r = extract_first_word(&val,
7✔
3130
                                               &source,
3131
                                               ":" WHITESPACE,
3132
                                               EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3133
                        if (r < 0)
7✔
3134
                                return r;
3135
                        if (r == 0)
7✔
3136
                                return -EINVAL;
3137

3138
                        s = source;
7✔
3139
                        if (s[0] == '-') {
7✔
3140
                                ignore_enoent = true;
1✔
3141
                                s++;
1✔
3142
                        }
3143

3144
                        if (val && val[-1] == ':') {
7✔
3145
                                r = extract_first_word(&val,
7✔
3146
                                                       &destination,
3147
                                                       ":" WHITESPACE,
3148
                                                       EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3149
                                if (r < 0)
7✔
3150
                                        return r;
3151
                                if (r == 0)
7✔
3152
                                        continue;
×
3153

3154
                                d = destination;
7✔
3155

3156
                                if (val && val[-1] == ':') {
7✔
3157
                                        _cleanup_free_ char *options = NULL;
7✔
3158

3159
                                        r = extract_first_word(&val, &options, NULL, EXTRACT_UNQUOTE);
7✔
3160
                                        if (r < 0)
7✔
3161
                                                return -r;
×
3162

3163
                                        if (isempty(options) || streq(options, "rbind"))
15✔
3164
                                                rbind = true;
3165
                                        else if (streq(options, "norbind"))
1✔
3166
                                                rbind = false;
3167
                                        else
3168
                                                continue;
×
3169
                                }
3170
                        } else
3171
                                d = s;
3172

3173
                        r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts,
14✔
3174
                                        &(BindMount) {
7✔
3175
                                                .source = s,
3176
                                                .destination = d,
3177
                                                .read_only = true,
3178
                                                .recursive = rbind,
3179
                                                .ignore_enoent = ignore_enoent,
3180
                                        });
3181
                        if (r < 0)
7✔
3182
                                return log_oom_debug();
×
3183
                } else if ((val = startswith(l, "exec-context-bind-path="))) {
903,058✔
3184
                        _cleanup_free_ char *source = NULL, *destination = NULL;
16✔
3185
                        bool rbind = true, ignore_enoent = false;
16✔
3186
                        char *s = NULL, *d = NULL;
16✔
3187

3188
                        r = extract_first_word(&val,
16✔
3189
                                               &source,
3190
                                               ":" WHITESPACE,
3191
                                               EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3192
                        if (r < 0)
16✔
3193
                                return r;
3194
                        if (r == 0)
16✔
3195
                                return -EINVAL;
3196

3197
                        s = source;
16✔
3198
                        if (s[0] == '-') {
16✔
3199
                                ignore_enoent = true;
1✔
3200
                                s++;
1✔
3201
                        }
3202

3203
                        if (val && val[-1] == ':') {
16✔
3204
                                r = extract_first_word(&val,
16✔
3205
                                                       &destination,
3206
                                                       ":" WHITESPACE,
3207
                                                       EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3208
                                if (r < 0)
16✔
3209
                                        return r;
3210
                                if (r == 0)
16✔
3211
                                        continue;
×
3212

3213
                                d = destination;
16✔
3214

3215
                                if (val && val[-1] == ':') {
16✔
3216
                                        _cleanup_free_ char *options = NULL;
16✔
3217

3218
                                        r = extract_first_word(&val, &options, NULL, EXTRACT_UNQUOTE);
16✔
3219
                                        if (r < 0)
16✔
3220
                                                return -r;
×
3221

3222
                                        if (isempty(options) || streq(options, "rbind"))
35✔
3223
                                                rbind = true;
3224
                                        else if (streq(options, "norbind"))
3✔
3225
                                                rbind = false;
3226
                                        else
3227
                                                continue;
×
3228
                                }
3229
                        } else
3230
                                d = s;
3231

3232
                        r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts,
32✔
3233
                                        &(BindMount) {
16✔
3234
                                                .source = s,
3235
                                                .destination = d,
3236
                                                .read_only = false,
3237
                                                .recursive = rbind,
3238
                                                .ignore_enoent = ignore_enoent,
3239
                                        });
3240
                        if (r < 0)
16✔
3241
                                return log_oom_debug();
×
3242
                } else if ((val = startswith(l, "exec-context-temporary-filesystems="))) {
903,042✔
3243
                        _cleanup_free_ char *path = NULL, *options = NULL;
61✔
3244

3245
                        r = extract_many_words(&val, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &path, &options);
61✔
3246
                        if (r < 0)
61✔
3247
                                return r;
3248
                        if (r < 1)
61✔
3249
                                continue;
×
3250

3251
                        r = temporary_filesystem_add(&c->temporary_filesystems, &c->n_temporary_filesystems, path, options);
61✔
3252
                        if (r < 0)
61✔
3253
                                return log_oom_debug();
×
3254
                } else if ((val = startswith(l, "exec-context-utmp-id="))) {
902,981✔
3255
                        r = free_and_strdup(&c->utmp_id, val);
155✔
3256
                        if (r < 0)
155✔
3257
                                return r;
3258
                } else if ((val = startswith(l, "exec-context-utmp-mode="))) {
902,826✔
3259
                        c->utmp_mode = exec_utmp_mode_from_string(val);
11,500✔
3260
                        if (c->utmp_mode < 0)
11,500✔
3261
                                return c->utmp_mode;
3262
                } else if ((val = startswith(l, "exec-context-no-new-privileges="))) {
891,326✔
3263
                        r = parse_boolean(val);
2,144✔
3264
                        if (r < 0)
2,144✔
3265
                                return r;
3266
                        c->no_new_privileges = r;
2,144✔
3267
                } else if ((val = startswith(l, "exec-context-selinux-context="))) {
889,182✔
3268
                        if (val[0] == '-') {
×
3269
                                c->selinux_context_ignore = true;
×
3270
                                val++;
×
3271
                        } else
3272
                                c->selinux_context_ignore = false;
×
3273

3274
                        r = free_and_strdup(&c->selinux_context, val);
×
3275
                        if (r < 0)
×
3276
                                return r;
3277
                } else if ((val = startswith(l, "exec-context-apparmor-profile="))) {
889,182✔
3278
                        if (val[0] == '-') {
×
3279
                                c->apparmor_profile_ignore = true;
×
3280
                                val++;
×
3281
                        } else
3282
                                c->apparmor_profile_ignore = false;
×
3283

3284
                        r = free_and_strdup(&c->apparmor_profile, val);
×
3285
                        if (r < 0)
×
3286
                                return r;
3287
                } else if ((val = startswith(l, "exec-context-smack-process-label="))) {
889,182✔
3288
                        if (val[0] == '-') {
×
3289
                                c->smack_process_label_ignore = true;
×
3290
                                val++;
×
3291
                        } else
3292
                                c->smack_process_label_ignore = false;
×
3293

3294
                        r = free_and_strdup(&c->smack_process_label, val);
×
3295
                        if (r < 0)
×
3296
                                return r;
3297
                } else if ((val = startswith(l, "exec-context-personality="))) {
889,182✔
3298
                        c->personality = personality_from_string(val);
×
3299
                        if (c->personality == PERSONALITY_INVALID)
×
3300
                                return -EINVAL;
3301
                } else if ((val = startswith(l, "exec-context-lock-personality="))) {
889,182✔
3302
                        r = parse_boolean(val);
2,202✔
3303
                        if (r < 0)
2,202✔
3304
                                return r;
3305
                        c->lock_personality = r;
2,202✔
3306
#if HAVE_SECCOMP
3307
                } else if ((val = startswith(l, "exec-context-syscall-filter="))) {
886,980✔
3308
                        _cleanup_free_ char *s_id = NULL, *s_errno_num = NULL;
850,307✔
3309
                        int id, errno_num;
850,307✔
3310

3311
                        r = extract_many_words(&val, NULL, 0, &s_id, &s_errno_num);
850,307✔
3312
                        if (r < 0)
850,307✔
3313
                                return r;
3314
                        if (r != 2)
850,307✔
3315
                                continue;
×
3316

3317
                        r = safe_atoi(s_id, &id);
850,307✔
3318
                        if (r < 0)
850,307✔
3319
                                return r;
3320

3321
                        r = safe_atoi(s_errno_num, &errno_num);
850,307✔
3322
                        if (r < 0)
850,307✔
3323
                                return r;
3324

3325
                        r = hashmap_ensure_put(&c->syscall_filter, NULL, INT_TO_PTR(id + 1), INT_TO_PTR(errno_num));
850,307✔
3326
                        if (r < 0)
850,307✔
3327
                                return r;
3328
                } else if ((val = startswith(l, "exec-context-syscall-archs="))) {
36,673✔
3329
                        unsigned id;
2,201✔
3330

3331
                        r = safe_atou(val, &id);
2,201✔
3332
                        if (r < 0)
2,201✔
3333
                                return r;
×
3334

3335
                        r = set_ensure_put(&c->syscall_archs, NULL, UINT_TO_PTR(id + 1));
2,201✔
3336
                        if (r < 0)
2,201✔
3337
                                return r;
3338
                } else if ((val = startswith(l, "exec-context-syscall-errno="))) {
34,472✔
3339
                        r = safe_atoi(val, &c->syscall_errno);
11,500✔
3340
                        if (r < 0)
11,500✔
3341
                                return r;
3342
                } else if ((val = startswith(l, "exec-context-syscall-allow-list="))) {
22,972✔
3343
                        r = parse_boolean(val);
2,184✔
3344
                        if (r < 0)
2,184✔
3345
                                return r;
3346
                        c->syscall_allow_list = r;
2,184✔
3347
                } else if ((val = startswith(l, "exec-context-syscall-log="))) {
20,788✔
3348
                        _cleanup_free_ char *s_id = NULL, *s_errno_num = NULL;
×
3349
                        int id, errno_num;
×
3350

3351
                        r = extract_many_words(&val, " ", 0, &s_id, &s_errno_num);
×
3352
                        if (r < 0)
×
3353
                                return r;
3354
                        if (r != 2)
×
3355
                                continue;
×
3356

3357
                        r = safe_atoi(s_id, &id);
×
3358
                        if (r < 0)
×
3359
                                return r;
3360

3361
                        r = safe_atoi(s_errno_num, &errno_num);
×
3362
                        if (r < 0)
×
3363
                                return r;
3364

3365
                        r = hashmap_ensure_put(&c->syscall_log, NULL, INT_TO_PTR(id + 1), INT_TO_PTR(errno_num));
×
3366
                        if (r < 0)
×
3367
                                return r;
3368
                } else if ((val = startswith(l, "exec-context-syscall-log-allow-list="))) {
20,788✔
3369
                        r = parse_boolean(val);
×
3370
                        if (r < 0)
×
3371
                                return r;
3372
                        c->syscall_log_allow_list = r;
×
3373
#endif
3374
                } else if ((val = startswith(l, "exec-context-restrict-namespaces="))) {
20,788✔
3375
                        r = safe_atolu(val, &c->restrict_namespaces);
1,945✔
3376
                        if (r < 0)
1,945✔
3377
                                return r;
3378
                } else if ((val = startswith(l, "exec-context-delegate-namespaces="))) {
18,843✔
3379
                        r = safe_atolu(val, &c->delegate_namespaces);
10✔
3380
                        if (r < 0)
10✔
3381
                                return r;
3382
                } else if ((val = startswith(l, "exec-context-restrict-filesystems="))) {
18,833✔
3383
                        r = set_put_strdup(&c->restrict_filesystems, val);
×
3384
                        if (r < 0)
×
3385
                                return r;
3386
                } else if ((val = startswith(l, "exec-context-restrict-filesystems-allow-list="))) {
18,833✔
3387
                        r = parse_boolean(val);
×
3388
                        if (r < 0)
×
3389
                                return r;
3390
                        c->restrict_filesystems_allow_list = r;
×
3391
                } else if ((val = startswith(l, "exec-context-address-families="))) {
18,833✔
3392
                        int af;
9,171✔
3393

3394
                        r = safe_atoi(val, &af);
9,171✔
3395
                        if (r < 0)
9,171✔
3396
                                return r;
×
3397

3398
                        r = set_ensure_put(&c->address_families, NULL, INT_TO_PTR(af));
9,171✔
3399
                        if (r < 0)
9,171✔
3400
                                return r;
3401
                } else if ((val = startswith(l, "exec-context-address-families-allow-list="))) {
9,662✔
3402
                        r = parse_boolean(val);
2,199✔
3403
                        if (r < 0)
2,199✔
3404
                                return r;
3405
                        c->address_families_allow_list = r;
2,199✔
3406
                } else if ((val = startswith(l, "exec-context-network-namespace-path="))) {
7,463✔
3407
                        r = free_and_strdup(&c->network_namespace_path, val);
×
3408
                        if (r < 0)
×
3409
                                return r;
3410
                } else if ((val = startswith(l, "exec-context-ipc-namespace-path="))) {
7,463✔
3411
                        r = free_and_strdup(&c->ipc_namespace_path, val);
×
3412
                        if (r < 0)
×
3413
                                return r;
3414
                } else if ((val = startswith(l, "exec-context-mount-image="))) {
7,463✔
3415
                        _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
×
3416
                        _cleanup_free_ char *source = NULL, *destination = NULL;
60✔
3417
                        bool permissive = false;
60✔
3418
                        char *s;
60✔
3419

3420
                        r = extract_many_words(&val,
60✔
3421
                                               NULL,
3422
                                               EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS,
3423
                                               &source,
3424
                                               &destination);
3425
                        if (r < 0)
60✔
3426
                                return r;
3427
                        if (r == 0)
60✔
3428
                                return -EINVAL;
3429

3430
                        s = source;
60✔
3431
                        if (s[0] == '-') {
60✔
3432
                                permissive = true;
×
3433
                                s++;
×
3434
                        }
3435

3436
                        if (isempty(destination))
60✔
3437
                                continue;
×
3438

3439
                        for (;;) {
65✔
3440
                                _cleanup_free_ char *tuple = NULL, *partition = NULL, *opts = NULL;
5✔
3441
                                PartitionDesignator partition_designator;
65✔
3442
                                MountOptions *o = NULL;
65✔
3443
                                const char *p;
65✔
3444

3445
                                r = extract_first_word(&val, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
65✔
3446
                                if (r < 0)
65✔
3447
                                        return r;
3448
                                if (r == 0)
65✔
3449
                                        break;
3450

3451
                                p = tuple;
5✔
3452
                                r = extract_many_words(&p,
5✔
3453
                                                       ":",
3454
                                                       EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS,
3455
                                                       &partition,
3456
                                                       &opts);
3457
                                if (r < 0)
5✔
3458
                                        return r;
3459
                                if (r == 0)
5✔
3460
                                        continue;
×
3461
                                if (r == 1) {
5✔
3462
                                        o = new(MountOptions, 1);
×
3463
                                        if (!o)
×
3464
                                                return log_oom_debug();
×
3465
                                        *o = (MountOptions) {
×
3466
                                                .partition_designator = PARTITION_ROOT,
3467
                                                .options = TAKE_PTR(partition),
×
3468
                                        };
3469
                                        LIST_APPEND(mount_options, options, o);
×
3470

3471
                                        continue;
×
3472
                                }
3473

3474
                                partition_designator = partition_designator_from_string(partition);
5✔
3475
                                if (partition_designator < 0)
5✔
3476
                                        continue;
×
3477

3478
                                o = new(MountOptions, 1);
5✔
3479
                                if (!o)
5✔
3480
                                        return log_oom_debug();
×
3481
                                *o = (MountOptions) {
5✔
3482
                                        .partition_designator = partition_designator,
3483
                                        .options = TAKE_PTR(opts),
5✔
3484
                                };
3485
                                LIST_APPEND(mount_options, options, o);
5✔
3486
                        }
3487

3488
                        r = mount_image_add(&c->mount_images, &c->n_mount_images,
120✔
3489
                                        &(MountImage) {
60✔
3490
                                                .source = s,
3491
                                                .destination = destination,
3492
                                                .mount_options = options,
3493
                                                .ignore_enoent = permissive,
3494
                                                .type = MOUNT_IMAGE_DISCRETE,
3495
                                        });
3496
                        if (r < 0)
60✔
3497
                                return log_oom_debug();
×
3498
                } else if ((val = startswith(l, "exec-context-extension-image="))) {
7,403✔
3499
                        _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
×
3500
                        _cleanup_free_ char *source = NULL;
8✔
3501
                        bool permissive = false;
8✔
3502
                        char *s;
8✔
3503

3504
                        r = extract_first_word(&val,
8✔
3505
                                               &source,
3506
                                               NULL,
3507
                                               EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS);
3508
                        if (r < 0)
8✔
3509
                                return r;
3510
                        if (r == 0)
8✔
3511
                                return -EINVAL;
3512

3513
                        s = source;
8✔
3514
                        if (s[0] == '-') {
8✔
3515
                                permissive = true;
2✔
3516
                                s++;
2✔
3517
                        }
3518

3519
                        for (;;) {
8✔
3520
                                _cleanup_free_ char *tuple = NULL, *partition = NULL, *opts = NULL;
×
3521
                                PartitionDesignator partition_designator;
8✔
3522
                                MountOptions *o = NULL;
8✔
3523
                                const char *p;
8✔
3524

3525
                                r = extract_first_word(&val, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
8✔
3526
                                if (r < 0)
8✔
3527
                                        return r;
3528
                                if (r == 0)
8✔
3529
                                        break;
3530

3531
                                p = tuple;
×
3532
                                r = extract_many_words(&p,
×
3533
                                                       ":",
3534
                                                       EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS,
3535
                                                       &partition,
3536
                                                       &opts);
3537
                                if (r < 0)
×
3538
                                        return r;
3539
                                if (r == 0)
×
3540
                                        continue;
×
3541
                                if (r == 1) {
×
3542
                                        o = new(MountOptions, 1);
×
3543
                                        if (!o)
×
3544
                                                return log_oom_debug();
×
3545
                                        *o = (MountOptions) {
×
3546
                                                .partition_designator = PARTITION_ROOT,
3547
                                                .options = TAKE_PTR(partition),
×
3548
                                        };
3549
                                        LIST_APPEND(mount_options, options, o);
×
3550

3551
                                        continue;
×
3552
                                }
3553

3554
                                partition_designator = partition_designator_from_string(partition);
×
3555
                                if (partition_designator < 0)
×
3556
                                        continue;
×
3557

3558
                                o = new(MountOptions, 1);
×
3559
                                if (!o)
×
3560
                                        return log_oom_debug();
×
3561
                                *o = (MountOptions) {
×
3562
                                        .partition_designator = partition_designator,
3563
                                        .options = TAKE_PTR(opts),
×
3564
                                };
3565
                                LIST_APPEND(mount_options, options, o);
×
3566
                        }
3567

3568
                        r = mount_image_add(&c->extension_images, &c->n_extension_images,
16✔
3569
                                        &(MountImage) {
8✔
3570
                                                .source = s,
3571
                                                .mount_options = options,
3572
                                                .ignore_enoent = permissive,
3573
                                                .type = MOUNT_IMAGE_EXTENSION,
3574
                                        });
3575
                        if (r < 0)
8✔
3576
                                return log_oom_debug();
×
3577
                } else if ((val = startswith(l, "exec-context-extension-directories="))) {
7,395✔
3578
                        r = deserialize_strv(val, &c->extension_directories);
7✔
3579
                        if (r < 0)
7✔
3580
                                return r;
3581
                } else if ((val = startswith(l, "exec-context-set-credentials="))) {
7,388✔
3582
                        _cleanup_free_ char *id = NULL, *data = NULL, *encrypted = NULL;
×
3583

3584
                        r = extract_many_words(&val, " ", EXTRACT_DONT_COALESCE_SEPARATORS, &id, &data, &encrypted);
182✔
3585
                        if (r < 0)
182✔
3586
                                return r;
3587
                        if (r != 3)
182✔
3588
                                return -EINVAL;
3589

3590
                        r = parse_boolean(encrypted);
182✔
3591
                        if (r < 0)
182✔
3592
                                return r;
3593
                        bool e = r;
182✔
3594

3595
                        _cleanup_free_ void *d = NULL;
182✔
3596
                        size_t size;
182✔
3597

3598
                        r = unbase64mem_full(data, SIZE_MAX, /* secure = */ true, &d, &size);
182✔
3599
                        if (r < 0)
182✔
3600
                                return r;
3601

3602
                        r = exec_context_put_set_credential(c, id, TAKE_PTR(d), size, e);
182✔
3603
                        if (r < 0)
182✔
3604
                                return r;
3605
                } else if ((val = startswith(l, "exec-context-load-credentials="))) {
7,206✔
3606
                        _cleanup_free_ char *id = NULL, *path = NULL, *encrypted = NULL;
71✔
3607

3608
                        r = extract_many_words(&val, " ", EXTRACT_DONT_COALESCE_SEPARATORS, &id, &path, &encrypted);
71✔
3609
                        if (r < 0)
71✔
3610
                                return r;
3611
                        if (r != 3)
71✔
3612
                                return -EINVAL;
3613

3614
                        r = parse_boolean(encrypted);
71✔
3615
                        if (r < 0)
71✔
3616
                                return r;
3617

3618
                        r = exec_context_put_load_credential(c, id, path, r > 0);
71✔
3619
                        if (r < 0)
71✔
3620
                                return r;
3621
                } else if ((val = startswith(l, "exec-context-import-credentials="))) {
7,135✔
3622
                        _cleanup_free_ char *glob = NULL, *rename = NULL;
7,131✔
3623

3624
                        r = extract_many_words(&val, " ", EXTRACT_DONT_COALESCE_SEPARATORS, &glob, &rename);
7,131✔
3625
                        if (r < 0)
7,131✔
3626
                                return r;
3627
                        if (r == 0)
7,131✔
3628
                                return -EINVAL;
3629

3630
                        r = exec_context_put_import_credential(c, glob, rename);
7,131✔
3631
                        if (r < 0)
7,131✔
3632
                                return r;
3633
                } else if ((val = startswith(l, "exec-context-root-image-policy="))) {
4✔
3634
                        if (c->root_image_policy)
4✔
3635
                                return -EINVAL; /* duplicated */
3636

3637
                        r = image_policy_from_string(val, &c->root_image_policy);
4✔
3638
                        if (r < 0)
4✔
3639
                                return r;
3640
                } else if ((val = startswith(l, "exec-context-mount-image-policy="))) {
×
3641
                        if (c->mount_image_policy)
×
3642
                                return -EINVAL; /* duplicated */
3643

3644
                        r = image_policy_from_string(val, &c->mount_image_policy);
×
3645
                        if (r < 0)
×
3646
                                return r;
3647
                } else if ((val = startswith(l, "exec-context-extension-image-policy="))) {
×
3648
                        if (c->extension_image_policy)
×
3649
                                return -EINVAL; /* duplicated */
3650

3651
                        r = image_policy_from_string(val, &c->extension_image_policy);
×
3652
                        if (r < 0)
×
3653
                                return r;
3654
                } else
3655
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
1,268,945✔
3656
        }
3657

3658
        return 0;
11,500✔
3659
}
3660

3661
static int exec_command_serialize(const ExecCommand *c, FILE *f) {
2,199✔
3662
        int r;
2,199✔
3663

3664
        assert(c);
2,199✔
3665
        assert(f);
2,199✔
3666

3667
        r = serialize_item(f, "exec-command-path", c->path);
2,199✔
3668
        if (r < 0)
2,199✔
3669
                return r;
3670

3671
        r = serialize_strv(f, "exec-command-argv", c->argv);
2,199✔
3672
        if (r < 0)
2,199✔
3673
                return r;
3674

3675
        r = serialize_item_format(f, "exec-command-flags", "%d", (int) c->flags);
2,199✔
3676
        if (r < 0)
2,199✔
3677
                return r;
3678

3679
        fputc('\n', f); /* End marker */
2,199✔
3680

3681
        return 0;
2,199✔
3682
}
3683

3684
static int exec_command_deserialize(ExecCommand *c, FILE *f) {
11,500✔
3685
        int r;
11,500✔
3686

3687
        assert(c);
11,500✔
3688
        assert(f);
11,500✔
3689

3690
        for (;;) {
122,998✔
3691
                _cleanup_free_ char *l = NULL;
55,749✔
3692
                const char *val;
67,249✔
3693

3694
                r = deserialize_read_line(f, &l);
67,249✔
3695
                if (r < 0)
67,249✔
3696
                        return r;
3697
                if (r == 0) /* eof or end marker */
67,249✔
3698
                        break;
3699

3700
                if ((val = startswith(l, "exec-command-path="))) {
55,749✔
3701
                        r = free_and_strdup(&c->path, val);
11,500✔
3702
                        if (r < 0)
11,500✔
3703
                                return r;
3704
                } else if ((val = startswith(l, "exec-command-argv="))) {
44,249✔
3705
                        r = deserialize_strv(val, &c->argv);
32,749✔
3706
                        if (r < 0)
32,749✔
3707
                                return r;
3708
                } else if ((val = startswith(l, "exec-command-flags="))) {
11,500✔
3709
                        r = safe_atoi(val, &c->flags);
11,500✔
3710
                        if (r < 0)
11,500✔
3711
                                return r;
3712
                } else
3713
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
55,749✔
3714

3715
        }
3716

3717
        return 0;
11,500✔
3718
}
3719

3720
int exec_serialize_invocation(
2,199✔
3721
                FILE *f,
3722
                FDSet *fds,
3723
                const ExecContext *ctx,
3724
                const ExecCommand *cmd,
3725
                const ExecParameters *p,
3726
                const ExecRuntime *rt,
3727
                const CGroupContext *cg) {
3728

3729
        int r;
2,199✔
3730

3731
        assert(f);
2,199✔
3732
        assert(fds);
2,199✔
3733

3734
        r = exec_context_serialize(ctx, f);
2,199✔
3735
        if (r < 0)
2,199✔
3736
                return log_debug_errno(r, "Failed to serialize context: %m");
×
3737

3738
        r = exec_command_serialize(cmd, f);
2,199✔
3739
        if (r < 0)
2,199✔
3740
                return log_debug_errno(r, "Failed to serialize command: %m");
×
3741

3742
        r = exec_parameters_serialize(p, ctx, f, fds);
2,199✔
3743
        if (r < 0)
2,199✔
3744
                return log_debug_errno(r, "Failed to serialize parameters: %m");
×
3745

3746
        r = exec_runtime_serialize(rt, f, fds);
2,199✔
3747
        if (r < 0)
2,199✔
3748
                return log_debug_errno(r, "Failed to serialize runtime: %m");
×
3749

3750
        r = exec_cgroup_context_serialize(cg, f);
2,199✔
3751
        if (r < 0)
2,199✔
3752
                return log_debug_errno(r, "Failed to serialize cgroup context: %m");
×
3753

3754
        return 0;
3755
}
3756

3757
int exec_deserialize_invocation(
11,500✔
3758
                FILE *f,
3759
                FDSet *fds,
3760
                ExecContext *ctx,
3761
                ExecCommand *cmd,
3762
                ExecParameters *p,
3763
                ExecRuntime *rt,
3764
                CGroupContext *cg) {
3765

3766
        int r;
11,500✔
3767

3768
        assert(f);
11,500✔
3769
        assert(fds);
11,500✔
3770

3771
        r = exec_context_deserialize(ctx, f);
11,500✔
3772
        if (r < 0)
11,500✔
3773
                return log_debug_errno(r, "Failed to deserialize context: %m");
×
3774

3775
        r = exec_command_deserialize(cmd, f);
11,500✔
3776
        if (r < 0)
11,500✔
3777
                return log_debug_errno(r, "Failed to deserialize command: %m");
×
3778

3779
        r = exec_parameters_deserialize(p, f, fds);
11,500✔
3780
        if (r < 0)
11,500✔
3781
                return log_debug_errno(r, "Failed to deserialize parameters: %m");
×
3782

3783
        r = exec_runtime_deserialize(rt, f, fds);
11,500✔
3784
        if (r < 0)
11,500✔
3785
                return log_debug_errno(r, "Failed to deserialize runtime: %m");
×
3786

3787
        r = exec_cgroup_context_deserialize(cg, f);
11,500✔
3788
        if (r < 0)
11,500✔
3789
                return log_debug_errno(r, "Failed to deserialize cgroup context: %m");
×
3790

3791
        return 0;
3792
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc