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

systemd / systemd / 16280725298

14 Jul 2025 08:16PM UTC coverage: 72.166% (-0.006%) from 72.172%
16280725298

push

github

web-flow
Two fixlets for coverage test (#38183)

302135 of 418667 relevant lines covered (72.17%)

773261.64 hits per line

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

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

3
#include <unistd.h>
4

5
#include "af-list.h"
6
#include "capability-util.h"
7
#include "cgroup.h"
8
#include "dissect-image.h"
9
#include "dynamic-user.h"
10
#include "escape.h"
11
#include "exec-credential.h"
12
#include "execute.h"
13
#include "execute-serialize.h"
14
#include "extract-word.h"
15
#include "fd-util.h"
16
#include "hexdecoct.h"
17
#include "image-policy.h"
18
#include "in-addr-prefix-util.h"
19
#include "log.h"
20
#include "nsflags.h"
21
#include "open-file.h"
22
#include "ordered-set.h"
23
#include "parse-helpers.h"
24
#include "parse-util.h"
25
#include "path-util.h"
26
#include "process-util.h"
27
#include "rlimit-util.h"
28
#include "serialize.h"
29
#include "set.h"
30
#include "string-util.h"
31
#include "strv.h"
32
#include "time-util.h"
33

34
static int exec_cgroup_context_serialize(const CGroupContext *c, FILE *f) {
2,310✔
35
        _cleanup_free_ char *disable_controllers_str = NULL, *delegate_controllers_str = NULL,
×
36
                            *cpuset_cpus = NULL, *cpuset_mems = NULL, *startup_cpuset_cpus = NULL,
×
37
                            *startup_cpuset_mems = NULL;
2,310✔
38
        char *iface;
2,310✔
39
        struct in_addr_prefix *iaai;
2,310✔
40
        int r;
2,310✔
41

42
        assert(f);
2,310✔
43

44
        if (!c)
2,310✔
45
                return 0;
46

47
        r = serialize_bool_elide(f, "exec-cgroup-context-io-accounting", c->io_accounting);
2,310✔
48
        if (r < 0)
2,310✔
49
                return r;
50

51
        r = serialize_bool_elide(f, "exec-cgroup-context-memory-accounting", c->memory_accounting);
2,310✔
52
        if (r < 0)
2,310✔
53
                return r;
54

55
        r = serialize_bool_elide(f, "exec-cgroup-context-tasks-accounting", c->tasks_accounting);
2,310✔
56
        if (r < 0)
2,310✔
57
                return r;
58

59
        r = serialize_bool_elide(f, "exec-cgroup-context-ip-accounting", c->ip_accounting);
2,310✔
60
        if (r < 0)
2,310✔
61
                return r;
62

63
        r = serialize_bool_elide(f, "exec-cgroup-context-memory-oom-group", c->memory_oom_group);
2,310✔
64
        if (r < 0)
2,310✔
65
                return r;
66

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

73
        if (c->startup_cpu_weight != CGROUP_WEIGHT_INVALID) {
2,310✔
74
                r = serialize_item_format(f, "exec-cgroup-context-startup-cpu-weight", "%" PRIu64, c->startup_cpu_weight);
×
75
                if (r < 0)
×
76
                        return r;
77
        }
78

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

85
        if (c->cpu_quota_period_usec != USEC_INFINITY) {
2,310✔
86
                r = serialize_usec(f, "exec-cgroup-context-cpu-quota-period-usec", c->cpu_quota_period_usec);
×
87
                if (r < 0)
×
88
                        return r;
89
        }
90

91
        cpuset_cpus = cpu_set_to_range_string(&c->cpuset_cpus);
2,310✔
92
        if (!cpuset_cpus)
2,310✔
93
                return log_oom_debug();
×
94

95
        r = serialize_item(f, "exec-cgroup-context-allowed-cpus", cpuset_cpus);
2,310✔
96
        if (r < 0)
2,310✔
97
                return r;
98

99
        startup_cpuset_cpus = cpu_set_to_range_string(&c->startup_cpuset_cpus);
2,310✔
100
        if (!startup_cpuset_cpus)
2,310✔
101
                return log_oom_debug();
×
102

103
        r = serialize_item(f, "exec-cgroup-context-startup-allowed-cpus", startup_cpuset_cpus);
2,310✔
104
        if (r < 0)
2,310✔
105
                return r;
106

107
        cpuset_mems = cpu_set_to_range_string(&c->cpuset_mems);
2,310✔
108
        if (!cpuset_mems)
2,310✔
109
                return log_oom_debug();
×
110

111
        r = serialize_item(f, "exec-cgroup-context-allowed-memory-nodes", cpuset_mems);
2,310✔
112
        if (r < 0)
2,310✔
113
                return r;
114

115
        startup_cpuset_mems = cpu_set_to_range_string(&c->startup_cpuset_mems);
2,310✔
116
        if (!startup_cpuset_mems)
2,310✔
117
                return log_oom_debug();
×
118

119
        r = serialize_item(f, "exec-cgroup-context-startup-allowed-memory-nodes", startup_cpuset_mems);
2,310✔
120
        if (r < 0)
2,310✔
121
                return r;
122

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

129
        if (c->startup_io_weight != CGROUP_WEIGHT_INVALID) {
2,310✔
130
                r = serialize_item_format(f, "exec-cgroup-context-startup-io-weight", "%" PRIu64, c->startup_io_weight);
×
131
                if (r < 0)
×
132
                        return r;
133
        }
134

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

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

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

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

159
        if (c->startup_memory_low > 0) {
2,310✔
160
                r = serialize_item_format(f, "exec-cgroup-context-startup-memory-low", "%" PRIu64, c->startup_memory_low);
×
161
                if (r < 0)
×
162
                        return r;
163
        }
164

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

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

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

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

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

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

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

207
        if (c->startup_memory_zswap_max != CGROUP_LIMIT_MAX) {
2,310✔
208
                r = serialize_item_format(f, "exec-cgroup-context-startup-memory-zswap-max", "%" PRIu64, c->startup_memory_zswap_max);
×
209
                if (r < 0)
×
210
                        return r;
211
        }
212

213
        r = serialize_bool(f, "exec-cgroup-context-memory-zswap-writeback", c->memory_zswap_writeback);
2,310✔
214
        if (r < 0)
2,310✔
215
                return r;
216

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

223
        if (c->tasks_max.scale > 0) {
2,310✔
224
                r = serialize_item_format(f, "exec-cgroup-context-tasks-max-scale", "%" PRIu64, c->tasks_max.scale);
2,258✔
225
                if (r < 0)
2,258✔
226
                        return r;
227
        }
228

229
        r = serialize_bool_elide(f, "exec-cgroup-context-default-memory-min-set", c->default_memory_min_set);
2,310✔
230
        if (r < 0)
2,310✔
231
                return r;
232

233
        r = serialize_bool_elide(f, "exec-cgroup-context-default-memory-low-set", c->default_memory_low_set);
2,310✔
234
        if (r < 0)
2,310✔
235
                return r;
236

237
        r = serialize_bool_elide(f, "exec-cgroup-context-default-startup-memory-low-set", c->default_startup_memory_low_set);
2,310✔
238
        if (r < 0)
2,310✔
239
                return r;
240

241
        r = serialize_bool_elide(f, "exec-cgroup-context-memory-min-set", c->memory_min_set);
2,310✔
242
        if (r < 0)
2,310✔
243
                return r;
244

245
        r = serialize_bool_elide(f, "exec-cgroup-context-memory-low-set", c->memory_low_set);
2,310✔
246
        if (r < 0)
2,310✔
247
                return r;
248

249
        r = serialize_bool_elide(f, "exec-cgroup-context-startup-memory-low-set", c->startup_memory_low_set);
2,310✔
250
        if (r < 0)
2,310✔
251
                return r;
252

253
        r = serialize_bool_elide(f, "exec-cgroup-context-startup-memory-high-set", c->startup_memory_high_set);
2,310✔
254
        if (r < 0)
2,310✔
255
                return r;
256

257
        r = serialize_bool_elide(f, "exec-cgroup-context-startup-memory-max-set", c->startup_memory_max_set);
2,310✔
258
        if (r < 0)
2,310✔
259
                return r;
260

261
        r = serialize_bool_elide(f, "exec-cgroup-context-startup-memory-swap-max-set", c->startup_memory_swap_max_set);
2,310✔
262
        if (r < 0)
2,310✔
263
                return r;
264

265
        r = serialize_bool_elide(f, "exec-cgroup-context-startup-memory-zswap-max-set", c->startup_memory_zswap_max_set);
2,310✔
266
        if (r < 0)
2,310✔
267
                return r;
268

269
        r = serialize_item(f, "exec-cgroup-context-device-policy", cgroup_device_policy_to_string(c->device_policy));
2,310✔
270
        if (r < 0)
2,310✔
271
                return r;
272

273
        r = cg_mask_to_string(c->disable_controllers, &disable_controllers_str);
2,310✔
274
        if (r < 0)
2,310✔
275
                return r;
276

277
        r = serialize_item(f, "exec-cgroup-context-disable-controllers", disable_controllers_str);
2,310✔
278
        if (r < 0)
2,310✔
279
                return r;
280

281
        r = cg_mask_to_string(c->delegate_controllers, &delegate_controllers_str);
2,310✔
282
        if (r < 0)
2,310✔
283
                return r;
284

285
        r = serialize_item(f, "exec-cgroup-context-delegate-controllers", delegate_controllers_str);
2,310✔
286
        if (r < 0)
2,310✔
287
                return r;
288

289
        r = serialize_bool_elide(f, "exec-cgroup-context-delegate", c->delegate);
2,310✔
290
        if (r < 0)
2,310✔
291
                return r;
292

293
        r = serialize_item(f, "exec-cgroup-context-managed-oom-swap", managed_oom_mode_to_string(c->moom_swap));
2,310✔
294
        if (r < 0)
2,310✔
295
                return r;
296

297
        r = serialize_item(f, "exec-cgroup-context-managed-oom-memory-pressure", managed_oom_mode_to_string(c->moom_mem_pressure));
2,310✔
298
        if (r < 0)
2,310✔
299
                return r;
300

301
        r = serialize_item_format(f, "exec-cgroup-context-managed-oom-memory-pressure-limit", "%" PRIu32, c->moom_mem_pressure_limit);
2,310✔
302
        if (r < 0)
2,310✔
303
                return r;
304

305
        r = serialize_usec(f, "exec-cgroup-context-managed-oom-memory-pressure-duration-usec", c->moom_mem_pressure_duration_usec);
2,310✔
306
        if (r < 0)
2,310✔
307
                return r;
308

309
        r = serialize_item(f, "exec-cgroup-context-managed-oom-preference", managed_oom_preference_to_string(c->moom_preference));
2,310✔
310
        if (r < 0)
2,310✔
311
                return r;
312

313
        r = serialize_item(f, "exec-cgroup-context-memory-pressure-watch", cgroup_pressure_watch_to_string(c->memory_pressure_watch));
2,310✔
314
        if (r < 0)
2,310✔
315
                return r;
316

317
        r = serialize_item(f, "exec-cgroup-context-delegate-subgroup", c->delegate_subgroup);
2,310✔
318
        if (r < 0)
2,310✔
319
                return r;
320

321
        if (c->memory_pressure_threshold_usec != USEC_INFINITY) {
2,310✔
322
                r = serialize_usec(f, "exec-cgroup-context-memory-pressure-threshold-usec", c->memory_pressure_threshold_usec);
2,310✔
323
                if (r < 0)
2,310✔
324
                        return r;
325
        }
326

327
        LIST_FOREACH(device_allow, a, c->device_allow) {
2,832✔
328
                r = serialize_item_format(f, "exec-cgroup-context-device-allow", "%s %s",
522✔
329
                                          a->path,
330
                                          cgroup_device_permissions_to_string(a->permissions));
331
                if (r < 0)
522✔
332
                        return r;
333
        }
334

335
        LIST_FOREACH(device_weights, iw, c->io_device_weights) {
2,310✔
336
                r = serialize_item_format(f, "exec-cgroup-context-io-device-weight", "%s %" PRIu64,
×
337
                                          iw->path,
338
                                          iw->weight);
339
                if (r < 0)
×
340
                        return r;
341
        }
342

343
        LIST_FOREACH(device_latencies, l, c->io_device_latencies) {
2,310✔
344
                r = serialize_item_format(f, "exec-cgroup-context-io-device-latency-target-usec", "%s " USEC_FMT,
×
345
                                          l->path,
346
                                          l->target_usec);
347
                if (r < 0)
×
348
                        return r;
349
        }
350

351
        LIST_FOREACH(device_limits, il, c->io_device_limits)
2,310✔
352
                for (CGroupIOLimitType type = 0; type < _CGROUP_IO_LIMIT_TYPE_MAX; type++) {
×
353
                        _cleanup_free_ char *key = NULL;
×
354

355
                        if (il->limits[type] == cgroup_io_limit_defaults[type])
×
356
                                continue;
×
357

358
                        key = strjoin("exec-cgroup-context-io-device-limit-", cgroup_io_limit_type_to_string(type));
×
359
                        if (!key)
×
360
                                return -ENOMEM;
361

362
                        r = serialize_item_format(f, key, "%s %" PRIu64, il->path, il->limits[type]);
×
363
                        if (r < 0)
×
364
                                return r;
365
                }
366

367
        SET_FOREACH(iaai, c->ip_address_allow) {
2,310✔
368
                r = serialize_item(f,
×
369
                                   "exec-cgroup-context-ip-address-allow",
370
                                   IN_ADDR_PREFIX_TO_STRING(iaai->family, &iaai->address, iaai->prefixlen));
×
371
                if (r < 0)
×
372
                        return r;
×
373
        }
374
        SET_FOREACH(iaai, c->ip_address_deny) {
2,572✔
375
                r = serialize_item(f,
262✔
376
                                   "exec-cgroup-context-ip-address-deny",
377
                                   IN_ADDR_PREFIX_TO_STRING(iaai->family, &iaai->address, iaai->prefixlen));
262✔
378
                if (r < 0)
262✔
379
                        return r;
×
380
        }
381

382
        r = serialize_bool_elide(f, "exec-cgroup-context-ip-address-allow-reduced", c->ip_address_allow_reduced);
2,310✔
383
        if (r < 0)
2,310✔
384
                return r;
385

386
        r = serialize_bool_elide(f, "exec-cgroup-context-ip-address-deny-reduced", c->ip_address_deny_reduced);
2,310✔
387
        if (r < 0)
2,310✔
388
                return r;
389

390
        r = serialize_strv(f, "exec-cgroup-context-ip-ingress-filter-path", c->ip_filters_ingress);
2,310✔
391
        if (r < 0)
2,310✔
392
                return r;
393

394
        r = serialize_strv(f, "exec-cgroup-context-ip-egress-filter-path", c->ip_filters_egress);
2,310✔
395
        if (r < 0)
2,310✔
396
                return r;
397

398
        LIST_FOREACH(programs, p, c->bpf_foreign_programs) {
2,310✔
399
                r = serialize_item_format(f, "exec-cgroup-context-bpf-program", "%" PRIu32 " %s",
×
400
                                          p->attach_type,
401
                                          p->bpffs_path);
402
                if (r < 0)
×
403
                        return r;
404
        }
405

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

412
        LIST_FOREACH(socket_bind_items, bi, c->socket_bind_deny) {
2,310✔
413
                fprintf(f, "exec-cgroup-context-socket-bind-deny=");
×
414
                cgroup_context_dump_socket_bind_item(bi, f);
×
415
                fputc('\n', f);
×
416
        }
417

418
        SET_FOREACH(iface, c->restrict_network_interfaces) {
2,310✔
419
                r = serialize_item(f, "exec-cgroup-context-restrict-network-interfaces", iface);
×
420
                if (r < 0)
×
421
                        return r;
×
422
        }
423

424
        r = serialize_bool_elide(
4,620✔
425
                        f,
426
                        "exec-cgroup-context-restrict-network-interfaces-is-allow-list",
427
                        c->restrict_network_interfaces_is_allow_list);
2,310✔
428
        if (r < 0)
2,310✔
429
                return r;
430

431
        fputc('\n', f); /* End marker */
2,310✔
432

433
        return 0;
434
}
435

436
static int exec_cgroup_context_deserialize(CGroupContext *c, FILE *f) {
11,925✔
437
        int r;
11,925✔
438

439
        assert(f);
11,925✔
440

441
        if (!c)
11,925✔
442
                return 0;
443

444
        for (;;) {
446,345✔
445
                _cleanup_free_ char *l = NULL;
217,210✔
446
                const char *val;
229,135✔
447

448
                r = deserialize_read_line(f, &l);
229,135✔
449
                if (r < 0)
229,135✔
450
                        return r;
451
                if (r == 0) /* eof or end marker */
229,135✔
452
                        break;
453

454
                if ((val = startswith(l, "exec-cgroup-context-io-accounting="))) {
217,210✔
455
                        r = parse_boolean(val);
2✔
456
                        if (r < 0)
2✔
457
                                return r;
458
                        c->io_accounting = r;
2✔
459
                } else if ((val = startswith(l, "exec-cgroup-context-memory-accounting="))) {
217,208✔
460
                        r = parse_boolean(val);
11,689✔
461
                        if (r < 0)
11,689✔
462
                                return r;
463
                        c->memory_accounting = r;
11,689✔
464
                } else if ((val = startswith(l, "exec-cgroup-context-tasks-accounting="))) {
205,519✔
465
                        r = parse_boolean(val);
11,925✔
466
                        if (r < 0)
11,925✔
467
                                return r;
468
                        c->tasks_accounting = r;
11,925✔
469
                } else if ((val = startswith(l, "exec-cgroup-context-ip-accounting="))) {
193,594✔
470
                        r = parse_boolean(val);
×
471
                        if (r < 0)
×
472
                                return r;
473
                        c->ip_accounting = r;
×
474
                } else if ((val = startswith(l, "exec-cgroup-context-memory-oom-group="))) {
193,594✔
475
                        r = parse_boolean(val);
×
476
                        if (r < 0)
×
477
                                return r;
478
                        c->memory_oom_group = r;
×
479
                } else if ((val = startswith(l, "exec-cgroup-context-cpu-weight="))) {
193,594✔
480
                        r = safe_atou64(val, &c->cpu_weight);
1✔
481
                        if (r < 0)
1✔
482
                                return r;
483
                } else if ((val = startswith(l, "exec-cgroup-context-startup-cpu-weight="))) {
193,593✔
484
                        r = safe_atou64(val, &c->startup_cpu_weight);
×
485
                        if (r < 0)
×
486
                                return r;
487
                } else if ((val = startswith(l, "exec-cgroup-context-cpu-quota-per-sec-usec="))) {
193,593✔
488
                        r = deserialize_usec(val, &c->cpu_quota_per_sec_usec);
×
489
                        if (r < 0)
×
490
                                return r;
491
                } else if ((val = startswith(l, "exec-cgroup-context-cpu-quota-period-usec="))) {
193,593✔
492
                        r = deserialize_usec(val, &c->cpu_quota_period_usec);
×
493
                        if (r < 0)
×
494
                                return r;
495
                } else if ((val = startswith(l, "exec-cgroup-context-allowed-cpus="))) {
193,593✔
496
                        if (c->cpuset_cpus.set)
11,925✔
497
                                return -EINVAL; /* duplicated */
498

499
                        r = parse_cpu_set(val, &c->cpuset_cpus);
11,925✔
500
                        if (r < 0)
11,925✔
501
                                return r;
502
                } else if ((val = startswith(l, "exec-cgroup-context-startup-allowed-cpus="))) {
181,668✔
503
                        if (c->startup_cpuset_cpus.set)
11,925✔
504
                                return -EINVAL; /* duplicated */
505

506
                        r = parse_cpu_set(val, &c->startup_cpuset_cpus);
11,925✔
507
                        if (r < 0)
11,925✔
508
                                return r;
509
                } else if ((val = startswith(l, "exec-cgroup-context-allowed-memory-nodes="))) {
169,743✔
510
                        if (c->cpuset_mems.set)
11,925✔
511
                                return -EINVAL; /* duplicated */
512

513
                        r = parse_cpu_set(val, &c->cpuset_mems);
11,925✔
514
                        if (r < 0)
11,925✔
515
                                return r;
516
                } else if ((val = startswith(l, "exec-cgroup-context-startup-allowed-memory-nodes="))) {
157,818✔
517
                        if (c->startup_cpuset_mems.set)
11,925✔
518
                                return -EINVAL; /* duplicated */
519

520
                        r = parse_cpu_set(val, &c->startup_cpuset_mems);
11,925✔
521
                        if (r < 0)
11,925✔
522
                                return r;
523
                } else if ((val = startswith(l, "exec-cgroup-context-io-weight="))) {
145,893✔
524
                        r = safe_atou64(val, &c->io_weight);
×
525
                        if (r < 0)
×
526
                                return r;
527
                } else if ((val = startswith(l, "exec-cgroup-context-startup-io-weight="))) {
145,893✔
528
                        r = safe_atou64(val, &c->startup_io_weight);
×
529
                        if (r < 0)
×
530
                                return r;
531
                } else if ((val = startswith(l, "exec-cgroup-context-default-memory-min="))) {
145,893✔
532
                        r = safe_atou64(val, &c->default_memory_min);
×
533
                        if (r < 0)
×
534
                                return r;
535
                } else if ((val = startswith(l, "exec-cgroup-context-default-memory-low="))) {
145,893✔
536
                        r = safe_atou64(val, &c->default_memory_low);
×
537
                        if (r < 0)
×
538
                                return r;
539
                } else if ((val = startswith(l, "exec-cgroup-context-memory-min="))) {
145,893✔
540
                        r = safe_atou64(val, &c->memory_min);
1✔
541
                        if (r < 0)
1✔
542
                                return r;
543
                } else if ((val = startswith(l, "exec-cgroup-context-memory-low="))) {
145,892✔
544
                        r = safe_atou64(val, &c->memory_low);
1✔
545
                        if (r < 0)
1✔
546
                                return r;
547
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-low="))) {
145,891✔
548
                        r = safe_atou64(val, &c->startup_memory_low);
×
549
                        if (r < 0)
×
550
                                return r;
551
                } else if ((val = startswith(l, "exec-cgroup-context-memory-high="))) {
145,891✔
552
                        r = safe_atou64(val, &c->memory_high);
10✔
553
                        if (r < 0)
10✔
554
                                return r;
555
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-high="))) {
145,881✔
556
                        r = safe_atou64(val, &c->startup_memory_high);
×
557
                        if (r < 0)
×
558
                                return r;
559
                } else if ((val = startswith(l, "exec-cgroup-context-memory-max="))) {
145,881✔
560
                        r = safe_atou64(val, &c->memory_max);
2✔
561
                        if (r < 0)
2✔
562
                                return r;
563
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-max="))) {
145,879✔
564
                        r = safe_atou64(val, &c->startup_memory_max);
×
565
                        if (r < 0)
×
566
                                return r;
567
                } else if ((val = startswith(l, "exec-cgroup-context-memory-swap-max="))) {
145,879✔
568
                        r = safe_atou64(val, &c->memory_swap_max);
1✔
569
                        if (r < 0)
1✔
570
                                return r;
571
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-swap-max="))) {
145,878✔
572
                        r = safe_atou64(val, &c->startup_memory_swap_max);
×
573
                        if (r < 0)
×
574
                                return r;
575
                } else if ((val = startswith(l, "exec-cgroup-context-memory-zswap-max="))) {
145,878✔
576
                        r = safe_atou64(val, &c->memory_zswap_max);
1✔
577
                        if (r < 0)
1✔
578
                                return r;
579
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-zswap-max="))) {
145,877✔
580
                        r = safe_atou64(val, &c->startup_memory_zswap_max);
×
581
                        if (r < 0)
×
582
                                return r;
583
                } else if ((val = startswith(l, "exec-cgroup-context-memory-zswap-writeback="))) {
145,877✔
584
                        r = parse_boolean(val);
11,925✔
585
                        if (r < 0)
11,925✔
586
                                return r;
587
                        c->memory_zswap_writeback = r;
11,925✔
588
                } else if ((val = startswith(l, "exec-cgroup-context-tasks-max-value="))) {
133,952✔
589
                        r = safe_atou64(val, &c->tasks_max.value);
11,630✔
590
                        if (r < 0)
11,630✔
591
                                return r;
592
                } else if ((val = startswith(l, "exec-cgroup-context-tasks-max-scale="))) {
122,322✔
593
                        r = safe_atou64(val, &c->tasks_max.scale);
11,594✔
594
                        if (r < 0)
11,594✔
595
                                return r;
596
                } else if ((val = startswith(l, "exec-cgroup-context-default-memory-min-set="))) {
110,728✔
597
                        r = parse_boolean(val);
×
598
                        if (r < 0)
×
599
                                return r;
600
                        c->default_memory_min_set = r;
×
601
                } else if ((val = startswith(l, "exec-cgroup-context-default-memory-low-set="))) {
110,728✔
602
                        r = parse_boolean(val);
×
603
                        if (r < 0)
×
604
                                return r;
605
                        c->default_memory_low_set = r;
×
606
                } else if ((val = startswith(l, "exec-cgroup-context-default-startup-memory-low-set="))) {
110,728✔
607
                        r = parse_boolean(val);
×
608
                        if (r < 0)
×
609
                                return r;
610
                        c->default_startup_memory_low_set = r;
×
611
                } else if ((val = startswith(l, "exec-cgroup-context-memory-min-set="))) {
110,728✔
612
                        r = parse_boolean(val);
1✔
613
                        if (r < 0)
1✔
614
                                return r;
615
                        c->memory_min_set = r;
1✔
616
                } else if ((val = startswith(l, "exec-cgroup-context-memory-low-set="))) {
110,727✔
617
                        r = parse_boolean(val);
1✔
618
                        if (r < 0)
1✔
619
                                return r;
620
                        c->memory_low_set = r;
1✔
621
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-low-set="))) {
110,726✔
622
                        r = parse_boolean(val);
×
623
                        if (r < 0)
×
624
                                return r;
625
                        c->startup_memory_low_set = r;
×
626
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-high-set="))) {
110,726✔
627
                        r = parse_boolean(val);
×
628
                        if (r < 0)
×
629
                                return r;
630
                        c->startup_memory_high_set = r;
×
631
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-max-set="))) {
110,726✔
632
                        r = parse_boolean(val);
×
633
                        if (r < 0)
×
634
                                return r;
635
                        c->startup_memory_max_set = r;
×
636
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-swap-max-set="))) {
110,726✔
637
                        r = parse_boolean(val);
×
638
                        if (r < 0)
×
639
                                return r;
640
                        c->startup_memory_swap_max_set = r;
×
641
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-zswap-max-set="))) {
110,726✔
642
                        r = parse_boolean(val);
×
643
                        if (r < 0)
×
644
                                return r;
645
                        c->startup_memory_zswap_max_set = r;
×
646
                } else if ((val = startswith(l, "exec-cgroup-context-device-policy="))) {
110,726✔
647
                        c->device_policy = cgroup_device_policy_from_string(val);
11,925✔
648
                        if (c->device_policy < 0)
11,925✔
649
                                return -EINVAL;
650
                } else if ((val = startswith(l, "exec-cgroup-context-disable-controllers="))) {
98,801✔
651
                        r = cg_mask_from_string(val, &c->disable_controllers);
×
652
                        if (r < 0)
×
653
                                return r;
654
                } else if ((val = startswith(l, "exec-cgroup-context-delegate-controllers="))) {
98,801✔
655
                        r = cg_mask_from_string(val, &c->delegate_controllers);
566✔
656
                        if (r < 0)
566✔
657
                                return r;
658
                } else if ((val = startswith(l, "exec-cgroup-context-delegate="))) {
98,235✔
659
                        r = parse_boolean(val);
682✔
660
                        if (r < 0)
682✔
661
                                return r;
662
                        c->delegate = r;
682✔
663
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-swap="))) {
97,553✔
664
                        c->moom_swap = managed_oom_mode_from_string(val);
11,925✔
665
                        if (c->moom_swap < 0)
11,925✔
666
                                return -EINVAL;
667
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-memory-pressure="))) {
85,628✔
668
                        c->moom_mem_pressure = managed_oom_mode_from_string(val);
11,925✔
669
                        if (c->moom_mem_pressure < 0)
11,925✔
670
                                return -EINVAL;
671
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-memory-pressure-limit="))) {
73,703✔
672
                        r = safe_atou32(val, &c->moom_mem_pressure_limit);
11,925✔
673
                        if (r < 0)
11,925✔
674
                                return r;
675
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-preference="))) {
61,778✔
676
                        c->moom_preference = managed_oom_preference_from_string(val);
11,925✔
677
                        if (c->moom_preference < 0)
11,925✔
678
                                return -EINVAL;
679
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-memory-pressure-duration-usec="))) {
49,853✔
680
                        r = deserialize_usec(val, &c->moom_mem_pressure_duration_usec);
1✔
681
                        if (r < 0)
1✔
682
                                return r;
683
                } else if ((val = startswith(l, "exec-cgroup-context-memory-pressure-watch="))) {
49,852✔
684
                        c->memory_pressure_watch = cgroup_pressure_watch_from_string(val);
11,925✔
685
                        if (c->memory_pressure_watch < 0)
11,925✔
686
                                return -EINVAL;
687
                } else if ((val = startswith(l, "exec-cgroup-context-delegate-subgroup="))) {
37,927✔
688
                        r = free_and_strdup(&c->delegate_subgroup, val);
339✔
689
                        if (r < 0)
339✔
690
                                return r;
691
                } else if ((val = startswith(l, "exec-cgroup-context-memory-pressure-threshold-usec="))) {
37,588✔
692
                        r = deserialize_usec(val, &c->memory_pressure_threshold_usec);
11,925✔
693
                        if (r < 0)
11,925✔
694
                                return r;
695
                } else if ((val = startswith(l, "exec-cgroup-context-device-allow="))) {
25,663✔
696
                        _cleanup_free_ char *path = NULL, *rwm = NULL;
4,589✔
697
                        CGroupDevicePermissions p;
4,589✔
698

699
                        r = extract_many_words(&val, " ", 0, &path, &rwm);
4,589✔
700
                        if (r < 0)
4,589✔
701
                                return r;
702
                        if (r == 0)
4,589✔
703
                                return -EINVAL;
704

705
                        p = isempty(rwm) ? 0 : cgroup_device_permissions_from_string(rwm);
9,178✔
706
                        if (p < 0)
4,589✔
707
                                return p;
708

709
                        r = cgroup_context_add_or_update_device_allow(c, path, p);
4,589✔
710
                        if (r < 0)
4,589✔
711
                                return r;
712
                } else if ((val = startswith(l, "exec-cgroup-context-io-device-weight="))) {
21,074✔
713
                        _cleanup_free_ char *path = NULL, *weight = NULL;
×
714
                        CGroupIODeviceWeight *a = NULL;
×
715

716
                        r = extract_many_words(&val, " ", 0, &path, &weight);
×
717
                        if (r < 0)
×
718
                                return r;
719
                        if (r != 2)
×
720
                                return -EINVAL;
721

722
                        LIST_FOREACH(device_weights, b, c->io_device_weights)
×
723
                                if (path_equal(b->path, path)) {
×
724
                                        a = b;
725
                                        break;
726
                                }
727

728
                        if (!a) {
×
729
                                a = new0(CGroupIODeviceWeight, 1);
×
730
                                if (!a)
×
731
                                        return log_oom_debug();
×
732

733
                                a->path = TAKE_PTR(path);
×
734

735
                                LIST_PREPEND(device_weights, c->io_device_weights, a);
×
736
                        }
737

738
                        r = safe_atou64(weight, &a->weight);
×
739
                        if (r < 0)
×
740
                                return r;
741
                } else if ((val = startswith(l, "exec-cgroup-context-io-device-latency-target-usec="))) {
21,074✔
742
                        _cleanup_free_ char *path = NULL, *target = NULL;
×
743
                        CGroupIODeviceLatency *a = NULL;
×
744

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

751
                        LIST_FOREACH(device_latencies, b, c->io_device_latencies)
×
752
                                if (path_equal(b->path, path)) {
×
753
                                        a = b;
754
                                        break;
755
                                }
756

757
                        if (!a) {
×
758
                                a = new0(CGroupIODeviceLatency, 1);
×
759
                                if (!a)
×
760
                                        return log_oom_debug();
×
761

762
                                a->path = TAKE_PTR(path);
×
763

764
                                LIST_PREPEND(device_latencies, c->io_device_latencies, a);
×
765
                        }
766

767
                        r = deserialize_usec(target, &a->target_usec);
×
768
                        if (r < 0)
×
769
                                return r;
770
                } else if ((val = startswith(l, "exec-cgroup-context-io-device-limit-"))) {
21,074✔
771
                        _cleanup_free_ char *type = NULL, *path = NULL, *limits = NULL;
×
772
                        CGroupIODeviceLimit *limit = NULL;
×
773
                        CGroupIOLimitType t;
×
774

775
                        r = extract_many_words(&val, "= ", 0, &type, &path, &limits);
×
776
                        if (r < 0)
×
777
                                return r;
778
                        if (r != 3)
×
779
                                return -EINVAL;
780

781
                        t = cgroup_io_limit_type_from_string(type);
×
782
                        if (t < 0)
×
783
                                return t;
784

785
                        LIST_FOREACH(device_limits, i, c->io_device_limits)
×
786
                                if (path_equal(path, i->path)) {
×
787
                                        limit = i;
788
                                        break;
789
                                }
790

791
                        if (!limit) {
×
792
                                limit = new0(CGroupIODeviceLimit, 1);
×
793
                                if (!limit)
×
794
                                        return log_oom_debug();
×
795

796
                                limit->path = TAKE_PTR(path);
×
797
                                for (CGroupIOLimitType i = 0; i < _CGROUP_IO_LIMIT_TYPE_MAX; i++)
×
798
                                        limit->limits[i] = cgroup_io_limit_defaults[i];
×
799

800
                                LIST_PREPEND(device_limits, c->io_device_limits, limit);
×
801
                        }
802

803
                        r = safe_atou64(limits, &limit->limits[t]);
×
804
                        if (r < 0)
×
805
                                return r;
806
                } else if ((val = startswith(l, "exec-cgroup-context-ip-address-allow="))) {
21,074✔
807
                        struct in_addr_prefix a;
×
808

809
                        r = in_addr_prefix_from_string_auto(val, &a.family, &a.address, &a.prefixlen);
×
810
                        if (r < 0)
×
811
                                return r;
×
812

813
                        r = in_addr_prefix_add(&c->ip_address_allow, &a);
×
814
                        if (r < 0)
×
815
                                return r;
816
                } else if ((val = startswith(l, "exec-cgroup-context-ip-address-deny="))) {
21,074✔
817
                        struct in_addr_prefix a;
1,628✔
818

819
                        r = in_addr_prefix_from_string_auto(val, &a.family, &a.address, &a.prefixlen);
1,628✔
820
                        if (r < 0)
1,628✔
821
                                return r;
×
822

823
                        r = in_addr_prefix_add(&c->ip_address_deny, &a);
1,628✔
824
                        if (r < 0)
1,628✔
825
                                return r;
826
                } else if ((val = startswith(l, "exec-cgroup-context-ip-address-allow-reduced="))) {
19,446✔
827
                        r = parse_boolean(val);
9,711✔
828
                        if (r < 0)
9,711✔
829
                                return r;
830
                        c->ip_address_allow_reduced = r;
9,711✔
831
                } else if ((val = startswith(l, "exec-cgroup-context-ip-address-deny-reduced="))) {
9,735✔
832
                        r = parse_boolean(val);
9,711✔
833
                        if (r < 0)
9,711✔
834
                                return r;
835
                        c->ip_address_deny_reduced = r;
9,711✔
836
                } else if ((val = startswith(l, "exec-cgroup-context-ip-ingress-filter-path="))) {
24✔
837
                        r = deserialize_strv(val, &c->ip_filters_ingress);
×
838
                        if (r < 0)
×
839
                                return r;
840
                } else if ((val = startswith(l, "exec-cgroup-context-ip-egress-filter-path="))) {
24✔
841
                        r = deserialize_strv(val, &c->ip_filters_egress);
×
842
                        if (r < 0)
×
843
                                return r;
844
                } else if ((val = startswith(l, "exec-cgroup-context-bpf-program="))) {
24✔
845
                        _cleanup_free_ char *type = NULL, *path = NULL;
×
846
                        uint32_t t;
×
847

848
                        r = extract_many_words(&val, " ", 0, &type, &path);
×
849
                        if (r < 0)
×
850
                                return r;
851
                        if (r != 2)
×
852
                                return -EINVAL;
853

854
                        r = safe_atou32(type, &t);
×
855
                        if (r < 0)
×
856
                                return r;
857

858
                        r = cgroup_context_add_bpf_foreign_program(c, t, path);
×
859
                        if (r < 0)
×
860
                                return r;
861
                } else if ((val = startswith(l, "exec-cgroup-context-socket-bind-allow="))) {
24✔
862
                        CGroupSocketBindItem *item;
×
863
                        uint16_t nr_ports, port_min;
×
864
                        int af, ip_protocol;
×
865

866
                        r = parse_socket_bind_item(val, &af, &ip_protocol, &nr_ports, &port_min);
×
867
                        if (r < 0)
×
868
                                return r;
×
869

870
                        item = new(CGroupSocketBindItem, 1);
×
871
                        if (!item)
×
872
                                return log_oom_debug();
×
873
                        *item = (CGroupSocketBindItem) {
×
874
                                .address_family = af,
875
                                .ip_protocol = ip_protocol,
876
                                .nr_ports = nr_ports,
877
                                .port_min = port_min,
878
                        };
879

880
                        LIST_PREPEND(socket_bind_items, c->socket_bind_allow, item);
×
881
                } else if ((val = startswith(l, "exec-cgroup-context-socket-bind-deny="))) {
24✔
882
                        CGroupSocketBindItem *item;
×
883
                        uint16_t nr_ports, port_min;
×
884
                        int af, ip_protocol;
×
885

886
                        r = parse_socket_bind_item(val, &af, &ip_protocol, &nr_ports, &port_min);
×
887
                        if (r < 0)
×
888
                                return r;
×
889

890
                        item = new(CGroupSocketBindItem, 1);
×
891
                        if (!item)
×
892
                                return log_oom_debug();
×
893
                        *item = (CGroupSocketBindItem) {
×
894
                                .address_family = af,
895
                                .ip_protocol = ip_protocol,
896
                                .nr_ports = nr_ports,
897
                                .port_min = port_min,
898
                        };
899

900
                        LIST_PREPEND(socket_bind_items, c->socket_bind_deny, item);
×
901
                } else if ((val = startswith(l, "exec-cgroup-context-restrict-network-interfaces="))) {
24✔
902
                        r = set_put_strdup(&c->restrict_network_interfaces, val);
15✔
903
                        if (r < 0)
15✔
904
                                return r;
905
                } else if ((val = startswith(l, "exec-cgroup-context-restrict-network-interfaces-is-allow-list="))) {
9✔
906
                        r = parse_boolean(val);
9✔
907
                        if (r < 0)
9✔
908
                                return r;
909
                        c->restrict_network_interfaces_is_allow_list = r;
9✔
910
                } else
911
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
912
        }
913

914
        return 0;
11,925✔
915
}
916

917
static int exec_runtime_serialize(const ExecRuntime *rt, FILE *f, FDSet *fds) {
2,310✔
918
        int r;
2,310✔
919

920
        assert(f);
2,310✔
921
        assert(fds);
2,310✔
922

923
        if (!rt) {
2,310✔
924
                fputc('\n', f); /* End marker */
2,238✔
925
                return 0;
2,238✔
926
        }
927

928
        if (rt->shared) {
72✔
929
                r = serialize_item(f, "exec-runtime-id", rt->shared->id);
71✔
930
                if (r < 0)
71✔
931
                        return r;
932

933
                r = serialize_item(f, "exec-runtime-tmp-dir", rt->shared->tmp_dir);
71✔
934
                if (r < 0)
71✔
935
                        return r;
936

937
                r = serialize_item(f, "exec-runtime-var-tmp-dir", rt->shared->var_tmp_dir);
71✔
938
                if (r < 0)
71✔
939
                        return r;
940

941
                if (rt->shared->netns_storage_socket[0] >= 0 && rt->shared->netns_storage_socket[1] >= 0) {
71✔
942
                        r = serialize_fd_many(f, fds, "exec-runtime-netns-storage-socket", rt->shared->netns_storage_socket, 2);
7✔
943
                        if (r < 0)
7✔
944
                                return r;
945
                }
946

947
                if (rt->shared->ipcns_storage_socket[0] >= 0 && rt->shared->ipcns_storage_socket[1] >= 0) {
71✔
948
                        r = serialize_fd_many(f, fds, "exec-runtime-ipcns-storage-socket", rt->shared->ipcns_storage_socket, 2);
2✔
949
                        if (r < 0)
2✔
950
                                return r;
951
                }
952
        }
953

954
        if (rt->dynamic_creds) {
72✔
955
                r = dynamic_user_serialize_one(rt->dynamic_creds->user, "exec-runtime-dynamic-creds-user", f, fds);
1✔
956
                if (r < 0)
1✔
957
                        return r;
958
        }
959

960
        if (rt->dynamic_creds && rt->dynamic_creds->group && rt->dynamic_creds->group == rt->dynamic_creds->user) {
72✔
961
                r = serialize_bool(f, "exec-runtime-dynamic-creds-group-copy", true);
1✔
962
                if (r < 0)
1✔
963
                        return r;
964
        } else if (rt->dynamic_creds) {
71✔
965
                r = dynamic_user_serialize_one(rt->dynamic_creds->group, "exec-runtime-dynamic-creds-group", f, fds);
×
966
                if (r < 0)
×
967
                        return r;
968
        }
969

970
        r = serialize_item(f, "exec-runtime-ephemeral-copy", rt->ephemeral_copy);
72✔
971
        if (r < 0)
72✔
972
                return r;
973

974
        if (rt->ephemeral_storage_socket[0] >= 0 && rt->ephemeral_storage_socket[1] >= 0) {
72✔
975
                r = serialize_fd_many(f, fds, "exec-runtime-ephemeral-storage-socket", rt->ephemeral_storage_socket, 2);
×
976
                if (r < 0)
×
977
                        return r;
978
        }
979

980
        fputc('\n', f); /* End marker */
72✔
981

982
        return 0;
72✔
983
}
984

985
static int exec_runtime_deserialize(ExecRuntime *rt, FILE *f, FDSet *fds) {
11,925✔
986
        int r;
11,925✔
987

988
        assert(rt);
11,925✔
989
        assert(rt->shared);
11,925✔
990
        assert(rt->dynamic_creds);
11,925✔
991
        assert(f);
11,925✔
992
        assert(fds);
11,925✔
993

994
        for (;;) {
13,153✔
995
                _cleanup_free_ char *l = NULL;
1,228✔
996
                const char *val;
13,153✔
997

998
                r = deserialize_read_line(f, &l);
13,153✔
999
                if (r < 0)
13,153✔
1000
                        return r;
1001
                if (r == 0) /* eof or end marker */
13,153✔
1002
                        break;
1003

1004
                if ((val = startswith(l, "exec-runtime-id="))) {
1,228✔
1005
                        r = free_and_strdup(&rt->shared->id, val);
358✔
1006
                        if (r < 0)
358✔
1007
                                return r;
1008
                } else if ((val = startswith(l, "exec-runtime-tmp-dir="))) {
870✔
1009
                        r = free_and_strdup(&rt->shared->tmp_dir, val);
338✔
1010
                        if (r < 0)
338✔
1011
                                return r;
1012
                } else if ((val = startswith(l, "exec-runtime-var-tmp-dir="))) {
532✔
1013
                        r = free_and_strdup(&rt->shared->var_tmp_dir, val);
338✔
1014
                        if (r < 0)
338✔
1015
                                return r;
1016
                } else if ((val = startswith(l, "exec-runtime-netns-storage-socket="))) {
194✔
1017

1018
                        r = deserialize_fd_many(fds, val, 2, rt->shared->netns_storage_socket);
64✔
1019
                        if (r < 0)
64✔
1020
                                continue;
×
1021

1022
                } else if ((val = startswith(l, "exec-runtime-ipcns-storage-socket="))) {
130✔
1023

1024
                        r = deserialize_fd_many(fds, val, 2, rt->shared->ipcns_storage_socket);
6✔
1025
                        if (r < 0)
6✔
1026
                                continue;
×
1027

1028
                } else if ((val = startswith(l, "exec-runtime-dynamic-creds-user=")))
124✔
1029
                        dynamic_user_deserialize_one(/* m= */ NULL, val, fds, &rt->dynamic_creds->user);
62✔
1030
                else if ((val = startswith(l, "exec-runtime-dynamic-creds-group=")))
62✔
1031
                        dynamic_user_deserialize_one(/* m= */ NULL, val, fds, &rt->dynamic_creds->group);
×
1032
                else if ((val = startswith(l, "exec-runtime-dynamic-creds-group-copy="))) {
62✔
1033
                        r = parse_boolean(val);
62✔
1034
                        if (r < 0)
62✔
1035
                                return r;
1036
                        if (!r)
62✔
1037
                                continue; /* Nothing to do */
×
1038

1039
                        if (!rt->dynamic_creds->user)
62✔
1040
                                return -EINVAL;
1041

1042
                        rt->dynamic_creds->group = dynamic_user_ref(rt->dynamic_creds->user);
62✔
1043
                } else if ((val = startswith(l, "exec-runtime-ephemeral-copy="))) {
×
1044
                        r = free_and_strdup(&rt->ephemeral_copy, val);
×
1045
                        if (r < 0)
×
1046
                                return r;
1047
                } else if ((val = startswith(l, "exec-runtime-ephemeral-storage-socket="))) {
×
1048

1049
                        r = deserialize_fd_many(fds, val, 2, rt->ephemeral_storage_socket);
×
1050
                        if (r < 0)
×
1051
                                continue;
×
1052
                } else
1053
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
1054
        }
1055

1056
        return 0;
11,925✔
1057
}
1058

1059
static bool exec_parameters_is_idle_pipe_set(const ExecParameters *p) {
2,310✔
1060
        assert(p);
2,310✔
1061

1062
        return p->idle_pipe &&
2,338✔
1063
                p->idle_pipe[0] >= 0 &&
28✔
1064
                p->idle_pipe[1] >= 0 &&
26✔
1065
                p->idle_pipe[2] >= 0 &&
2,336✔
1066
                p->idle_pipe[3] >= 0;
26✔
1067
}
1068

1069
static int exec_parameters_serialize(const ExecParameters *p, const ExecContext *c, FILE *f, FDSet *fds) {
2,310✔
1070
        int r;
2,310✔
1071

1072
        assert(f);
2,310✔
1073
        assert(fds);
2,310✔
1074

1075
        if (!p)
2,310✔
1076
                return 0;
1077

1078
        r = serialize_item(f, "exec-parameters-runtime-scope", runtime_scope_to_string(p->runtime_scope));
2,310✔
1079
        if (r < 0)
2,310✔
1080
                return r;
1081

1082
        r = serialize_strv(f, "exec-parameters-environment", p->environment);
2,310✔
1083
        if (r < 0)
2,310✔
1084
                return r;
1085

1086
        if (p->fds) {
2,310✔
1087
                if (p->n_socket_fds > 0) {
426✔
1088
                        r = serialize_item_format(f, "exec-parameters-n-socket-fds", "%zu", p->n_socket_fds);
425✔
1089
                        if (r < 0)
425✔
1090
                                return r;
1091
                }
1092

1093
                if (p->n_storage_fds > 0) {
426✔
1094
                        r = serialize_item_format(f, "exec-parameters-n-storage-fds", "%zu", p->n_storage_fds);
4✔
1095
                        if (r < 0)
4✔
1096
                                return r;
1097
                }
1098

1099
                if (p->n_extra_fds > 0) {
426✔
1100
                        r = serialize_item_format(f, "exec-parameters-n-extra-fds", "%zu", p->n_extra_fds);
1✔
1101
                        if (r < 0)
1✔
1102
                                return r;
1103
                }
1104

1105
                r = serialize_fd_many(f, fds, "exec-parameters-fds", p->fds, p->n_socket_fds + p->n_storage_fds + p->n_extra_fds);
426✔
1106
                if (r < 0)
426✔
1107
                        return r;
1108
        }
1109

1110
        r = serialize_strv(f, "exec-parameters-fd-names", p->fd_names);
2,310✔
1111
        if (r < 0)
2,310✔
1112
                return r;
1113

1114
        if (p->flags != 0) {
2,310✔
1115
                r = serialize_item_format(f, "exec-parameters-flags", "%u", (unsigned) p->flags);
2,310✔
1116
                if (r < 0)
2,310✔
1117
                        return r;
1118
        }
1119

1120
        r = serialize_bool_elide(f, "exec-parameters-selinux-context-net", p->selinux_context_net);
2,310✔
1121
        if (r < 0)
2,310✔
1122
                return r;
1123

1124
        if (p->cgroup_supported != 0) {
2,310✔
1125
                r = serialize_item_format(f, "exec-parameters-cgroup-supported", "%u", (unsigned) p->cgroup_supported);
2,310✔
1126
                if (r < 0)
2,310✔
1127
                        return r;
1128
        }
1129

1130
        r = serialize_item(f, "exec-parameters-cgroup-path", p->cgroup_path);
2,310✔
1131
        if (r < 0)
2,310✔
1132
                return r;
1133

1134
        r = serialize_item_format(f, "exec-parameters-cgroup-id", "%" PRIu64, p->cgroup_id);
2,310✔
1135
        if (r < 0)
2,310✔
1136
                return r;
1137

1138
        for (ExecDirectoryType dt = 0; dt < _EXEC_DIRECTORY_TYPE_MAX; dt++) {
13,860✔
1139
                _cleanup_free_ char *key = NULL;
11,550✔
1140

1141
                key = strjoin("exec-parameters-prefix-directories-", exec_directory_type_to_string(dt));
11,550✔
1142
                if (!key)
11,550✔
1143
                        return log_oom_debug();
×
1144

1145
                /* Always serialize, even an empty prefix, as this is a fixed array and we always expect
1146
                 * to have all elements (unless fuzzing is happening, hence the NULL check). */
1147
                r = serialize_item(f, key, strempty(p->prefix ? p->prefix[dt] : NULL));
11,550✔
1148
                if (r < 0)
11,550✔
1149
                        return r;
1150
        }
1151

1152
        r = serialize_item(f, "exec-parameters-received-credentials-directory", p->received_credentials_directory);
2,310✔
1153
        if (r < 0)
2,310✔
1154
                return r;
1155

1156
        r = serialize_item(f, "exec-parameters-received-encrypted-credentials-directory", p->received_encrypted_credentials_directory);
2,310✔
1157
        if (r < 0)
2,310✔
1158
                return r;
1159

1160
        r = serialize_item(f, "exec-parameters-confirm-spawn", p->confirm_spawn);
2,310✔
1161
        if (r < 0)
2,310✔
1162
                return r;
1163

1164
        r = serialize_bool_elide(f, "exec-parameters-shall-confirm-spawn", p->shall_confirm_spawn);
2,310✔
1165
        if (r < 0)
2,310✔
1166
                return r;
1167

1168
        if (p->watchdog_usec > 0) {
2,310✔
1169
                r = serialize_usec(f, "exec-parameters-watchdog-usec", p->watchdog_usec);
214✔
1170
                if (r < 0)
214✔
1171
                        return r;
1172
        }
1173

1174
        if (exec_parameters_is_idle_pipe_set(p)) {
2,310✔
1175
                r = serialize_fd_many(f, fds, "exec-parameters-idle-pipe", p->idle_pipe, 4);
26✔
1176
                if (r < 0)
26✔
1177
                        return r;
1178
        }
1179

1180
        r = serialize_fd(f, fds, "exec-parameters-stdin-fd", p->stdin_fd);
2,310✔
1181
        if (r < 0)
2,310✔
1182
                return r;
1183

1184
        r = serialize_fd(f, fds, "exec-parameters-stdout-fd", p->stdout_fd);
2,310✔
1185
        if (r < 0)
2,310✔
1186
                return r;
1187

1188
        r = serialize_fd(f, fds, "exec-parameters-stderr-fd", p->stderr_fd);
2,310✔
1189
        if (r < 0)
2,310✔
1190
                return r;
1191

1192
        r = serialize_fd(f, fds, "exec-parameters-exec-fd", p->exec_fd);
2,310✔
1193
        if (r < 0)
2,310✔
1194
                return r;
1195

1196
        r = serialize_fd(f, fds, "exec-parameters-handoff-timestamp-fd", p->handoff_timestamp_fd);
2,310✔
1197
        if (r < 0)
2,310✔
1198
                return r;
1199

1200
        r = serialize_fd(f, fds, "exec-parameters-pidref-transport-fd", p->pidref_transport_fd);
2,310✔
1201
        if (r < 0)
2,310✔
1202
                return r;
1203

1204
        if (c && exec_context_restrict_filesystems_set(c)) {
2,310✔
1205
                r = serialize_fd(f, fds, "exec-parameters-bpf-outer-map-fd", p->bpf_restrict_fs_map_fd);
×
1206
                if (r < 0)
×
1207
                        return r;
1208
        }
1209

1210
        r = serialize_item(f, "exec-parameters-notify-socket", p->notify_socket);
2,310✔
1211
        if (r < 0)
2,310✔
1212
                return r;
1213

1214
        LIST_FOREACH(open_files, file, p->open_files) {
2,310✔
1215
                _cleanup_free_ char *ofs = NULL;
×
1216

1217
                r = open_file_to_string(file, &ofs);
×
1218
                if (r < 0)
×
1219
                        return r;
1220

1221
                r = serialize_item(f, "exec-parameters-open-file", ofs);
×
1222
                if (r < 0)
×
1223
                        return r;
1224
        }
1225

1226
        r = serialize_item(f, "exec-parameters-fallback-smack-process-label", p->fallback_smack_process_label);
2,310✔
1227
        if (r < 0)
2,310✔
1228
                return r;
1229

1230
        r = serialize_fd(f, fds, "exec-parameters-user-lookup-fd", p->user_lookup_fd);
2,310✔
1231
        if (r < 0)
2,310✔
1232
                return r;
1233

1234
        r = serialize_strv(f, "exec-parameters-files-env", p->files_env);
2,310✔
1235
        if (r < 0)
2,310✔
1236
                return r;
1237

1238
        r = serialize_item(f, "exec-parameters-unit-id", p->unit_id);
2,310✔
1239
        if (r < 0)
2,310✔
1240
                return r;
1241

1242
        r = serialize_item(f, "exec-parameters-invocation-id-string", p->invocation_id_string);
2,310✔
1243
        if (r < 0)
2,310✔
1244
                return r;
1245

1246
        r = serialize_bool_elide(f, "exec-parameters-debug-invocation", p->debug_invocation);
2,310✔
1247
        if (r < 0)
2,310✔
1248
                return r;
1249

1250
        fputc('\n', f); /* End marker */
2,310✔
1251

1252
        return 0;
2,310✔
1253
}
1254

1255
static int exec_parameters_deserialize(ExecParameters *p, FILE *f, FDSet *fds) {
11,925✔
1256
        int r;
11,925✔
1257

1258
        assert(p);
11,925✔
1259
        assert(f);
11,925✔
1260
        assert(fds);
11,925✔
1261

1262
        unsigned nr_open = MAX(read_nr_open(), NR_OPEN_MINIMUM);
11,925✔
1263

1264
        for (;;) {
268,110✔
1265
                _cleanup_free_ char *l = NULL;
256,185✔
1266
                const char *val;
268,110✔
1267

1268
                r = deserialize_read_line(f, &l);
268,110✔
1269
                if (r < 0)
268,110✔
1270
                        return r;
1271
                if (r == 0) /* eof or end marker */
268,110✔
1272
                        break;
1273

1274
                if ((val = startswith(l, "exec-parameters-runtime-scope="))) {
256,185✔
1275
                        p->runtime_scope = runtime_scope_from_string(val);
11,925✔
1276
                        if (p->runtime_scope < 0)
11,925✔
1277
                                return p->runtime_scope;
1278
                } else if ((val = startswith(l, "exec-parameters-environment="))) {
244,260✔
1279
                        r = deserialize_strv(val, &p->environment);
50,351✔
1280
                        if (r < 0)
50,351✔
1281
                                return r;
1282
                } else if ((val = startswith(l, "exec-parameters-n-socket-fds="))) {
193,909✔
1283
                        if (p->fds)
2,419✔
1284
                                return -EINVAL; /* Already received */
1285

1286
                        r = safe_atozu(val, &p->n_socket_fds);
2,419✔
1287
                        if (r < 0)
2,419✔
1288
                                return r;
1289

1290
                        if (p->n_socket_fds > nr_open)
2,419✔
1291
                                return -EINVAL; /* too many, someone is playing games with us */
1292
                } else if ((val = startswith(l, "exec-parameters-n-storage-fds="))) {
191,490✔
1293
                        if (p->fds)
145✔
1294
                                return -EINVAL; /* Already received */
1295

1296
                        r = safe_atozu(val, &p->n_storage_fds);
145✔
1297
                        if (r < 0)
145✔
1298
                                return r;
1299

1300
                        if (p->n_storage_fds > nr_open)
145✔
1301
                                return -EINVAL; /* too many, someone is playing games with us */
1302
                } else if ((val = startswith(l, "exec-parameters-n-extra-fds="))) {
191,345✔
1303
                        if (p->fds)
2✔
1304
                                return -EINVAL; /* Already received */
1305

1306
                        r = safe_atozu(val, &p->n_extra_fds);
2✔
1307
                        if (r < 0)
2✔
1308
                                return r;
1309

1310
                        if (p->n_extra_fds > nr_open)
2✔
1311
                                return -EINVAL; /* too many, someone is playing games with us */
1312
                } else if ((val = startswith(l, "exec-parameters-fds="))) {
191,343✔
1313
                        if (p->n_socket_fds + p->n_storage_fds + p->n_extra_fds == 0)
2,424✔
1314
                                return log_warning_errno(
×
1315
                                                SYNTHETIC_ERRNO(EINVAL),
1316
                                                "Got exec-parameters-fds= without "
1317
                                                "prior exec-parameters-n-socket-fds= or exec-parameters-n-storage-fds= or exec-parameters-n-extra-fds=");
1318
                        if (p->n_socket_fds + p->n_storage_fds + p->n_extra_fds > nr_open)
2,424✔
1319
                                return -EINVAL; /* too many, someone is playing games with us */
1320

1321
                        if (p->fds)
2,424✔
1322
                                return -EINVAL; /* duplicated */
1323

1324
                        p->fds = new(int, p->n_socket_fds + p->n_storage_fds + p->n_extra_fds);
2,424✔
1325
                        if (!p->fds)
2,424✔
1326
                                return log_oom_debug();
×
1327

1328
                        /* Ensure we don't leave any FD uninitialized on error, it makes the fuzzer sad */
1329
                        FOREACH_ARRAY(i, p->fds, p->n_socket_fds + p->n_storage_fds + p->n_extra_fds)
7,448✔
1330
                                *i = -EBADF;
5,024✔
1331

1332
                        r = deserialize_fd_many(fds, val, p->n_socket_fds + p->n_storage_fds + p->n_extra_fds, p->fds);
2,424✔
1333
                        if (r < 0)
2,424✔
1334
                                continue;
×
1335

1336
                } else if ((val = startswith(l, "exec-parameters-fd-names="))) {
188,919✔
1337
                        r = deserialize_strv(val, &p->fd_names);
5,024✔
1338
                        if (r < 0)
5,024✔
1339
                                return r;
1340
                } else if ((val = startswith(l, "exec-parameters-flags="))) {
183,895✔
1341
                        unsigned flags;
11,925✔
1342

1343
                        r = safe_atou(val, &flags);
11,925✔
1344
                        if (r < 0)
11,925✔
1345
                                return r;
×
1346
                        p->flags = flags;
11,925✔
1347
                } else if ((val = startswith(l, "exec-parameters-selinux-context-net="))) {
171,970✔
1348
                        r = parse_boolean(val);
×
1349
                        if (r < 0)
×
1350
                                return r;
1351

1352
                        p->selinux_context_net = r;
×
1353
                } else if ((val = startswith(l, "exec-parameters-cgroup-supported="))) {
171,970✔
1354
                        unsigned cgroup_supported;
11,925✔
1355

1356
                        r = safe_atou(val, &cgroup_supported);
11,925✔
1357
                        if (r < 0)
11,925✔
1358
                                return r;
×
1359
                        p->cgroup_supported = cgroup_supported;
11,925✔
1360
                } else if ((val = startswith(l, "exec-parameters-cgroup-path="))) {
160,045✔
1361
                        r = free_and_strdup(&p->cgroup_path, val);
11,925✔
1362
                        if (r < 0)
11,925✔
1363
                                return r;
1364
                } else if ((val = startswith(l, "exec-parameters-cgroup-id="))) {
148,120✔
1365
                        r = safe_atou64(val, &p->cgroup_id);
11,925✔
1366
                        if (r < 0)
11,925✔
1367
                                return r;
1368
                } else if ((val = startswith(l, "exec-parameters-prefix-directories-"))) {
136,195✔
1369
                        _cleanup_free_ char *type = NULL, *prefix = NULL;
59,625✔
1370
                        ExecDirectoryType dt;
59,625✔
1371

1372
                        r = extract_many_words(&val, "= ", 0, &type, &prefix);
59,625✔
1373
                        if (r < 0)
59,625✔
1374
                                return r;
1375
                        if (r == 0)
59,625✔
1376
                                return -EINVAL;
1377

1378
                        dt = exec_directory_type_from_string(type);
59,625✔
1379
                        if (dt < 0)
59,625✔
1380
                                return -EINVAL;
1381

1382
                        if (!p->prefix) {
59,625✔
1383
                                p->prefix = new0(char*, _EXEC_DIRECTORY_TYPE_MAX+1);
11,925✔
1384
                                if (!p->prefix)
11,925✔
1385
                                        return log_oom_debug();
×
1386
                        }
1387

1388
                        if (isempty(prefix))
59,625✔
1389
                                p->prefix[dt] = mfree(p->prefix[dt]);
×
1390
                        else
1391
                                free_and_replace(p->prefix[dt], prefix);
59,625✔
1392
                } else if ((val = startswith(l, "exec-parameters-received-credentials-directory="))) {
76,570✔
1393
                        r = free_and_strdup(&p->received_credentials_directory, val);
11,095✔
1394
                        if (r < 0)
11,095✔
1395
                                return r;
1396
                } else if ((val = startswith(l, "exec-parameters-received-encrypted-credentials-directory="))) {
65,475✔
1397
                        r = free_and_strdup(&p->received_encrypted_credentials_directory, val);
×
1398
                        if (r < 0)
×
1399
                                return r;
1400
                } else if ((val = startswith(l, "exec-parameters-confirm-spawn="))) {
65,475✔
1401
                        r = free_and_strdup(&p->confirm_spawn, val);
×
1402
                        if (r < 0)
×
1403
                                return r;
1404
                } else if ((val = startswith(l, "exec-parameters-shall-confirm-spawn="))) {
65,475✔
1405
                        r = parse_boolean(val);
×
1406
                        if (r < 0)
×
1407
                                return r;
1408

1409
                        p->shall_confirm_spawn = r;
×
1410
                } else if ((val = startswith(l, "exec-parameters-watchdog-usec="))) {
65,475✔
1411
                        r = deserialize_usec(val, &p->watchdog_usec);
2,183✔
1412
                        if (r < 0)
2,183✔
1413
                                return r;
1414
                } else if ((val = startswith(l, "exec-parameters-idle-pipe="))) {
63,292✔
1415
                        if (p->idle_pipe)
156✔
1416
                                return -EINVAL; /* duplicated */
1417

1418
                        p->idle_pipe = new(int, 4);
156✔
1419
                        if (!p->idle_pipe)
156✔
1420
                                return log_oom_debug();
×
1421

1422
                        p->idle_pipe[0] = p->idle_pipe[1] = p->idle_pipe[2] = p->idle_pipe[3] = -EBADF;
156✔
1423

1424
                        r = deserialize_fd_many(fds, val, 4, p->idle_pipe);
156✔
1425
                        if (r < 0)
156✔
1426
                                continue;
×
1427

1428
                } else if ((val = startswith(l, "exec-parameters-stdin-fd="))) {
63,136✔
1429
                        int fd;
562✔
1430

1431
                        fd = deserialize_fd(fds, val);
562✔
1432
                        if (fd < 0)
562✔
1433
                                continue;
×
1434

1435
                        close_and_replace(p->stdin_fd, fd);
562✔
1436

1437
                } else if ((val = startswith(l, "exec-parameters-stdout-fd="))) {
62,574✔
1438
                        int fd;
562✔
1439

1440
                        fd = deserialize_fd(fds, val);
562✔
1441
                        if (fd < 0)
562✔
1442
                                continue;
×
1443

1444
                        close_and_replace(p->stdout_fd, fd);
562✔
1445

1446
                } else if ((val = startswith(l, "exec-parameters-stderr-fd="))) {
62,012✔
1447
                        int fd;
562✔
1448

1449
                        fd = deserialize_fd(fds, val);
562✔
1450
                        if (fd < 0)
562✔
1451
                                continue;
×
1452

1453
                        close_and_replace(p->stderr_fd, fd);
562✔
1454
                } else if ((val = startswith(l, "exec-parameters-exec-fd="))) {
61,450✔
1455
                        int fd;
414✔
1456

1457
                        fd = deserialize_fd(fds, val);
414✔
1458
                        if (fd < 0)
414✔
1459
                                continue;
×
1460

1461
                        close_and_replace(p->exec_fd, fd);
414✔
1462
                } else if ((val = startswith(l, "exec-parameters-handoff-timestamp-fd="))) {
61,036✔
1463
                        int fd;
11,925✔
1464

1465
                        fd = deserialize_fd(fds, val);
11,925✔
1466
                        if (fd < 0)
11,925✔
1467
                                continue;
×
1468

1469
                        close_and_replace(p->handoff_timestamp_fd, fd);
11,925✔
1470
                } else if ((val = startswith(l, "exec-parameters-pidref-transport-fd="))) {
49,111✔
1471
                        int fd;
10,737✔
1472

1473
                        fd = deserialize_fd(fds, val);
10,737✔
1474
                        if (fd < 0)
10,737✔
1475
                                continue;
×
1476

1477
                        close_and_replace(p->pidref_transport_fd, fd);
10,737✔
1478
                } else if ((val = startswith(l, "exec-parameters-bpf-outer-map-fd="))) {
38,374✔
1479
                        int fd;
×
1480

1481
                        fd = deserialize_fd(fds, val);
×
1482
                        if (fd < 0)
×
1483
                                continue;
×
1484

1485
                        close_and_replace(p->bpf_restrict_fs_map_fd, fd);
×
1486
                } else if ((val = startswith(l, "exec-parameters-notify-socket="))) {
38,374✔
1487
                        r = free_and_strdup(&p->notify_socket, val);
2,590✔
1488
                        if (r < 0)
2,590✔
1489
                                return r;
1490
                } else if ((val = startswith(l, "exec-parameters-open-file="))) {
35,784✔
1491
                        OpenFile *of;
5✔
1492

1493
                        r = open_file_parse(val, &of);
5✔
1494
                        if (r < 0)
5✔
1495
                                return r;
×
1496

1497
                        LIST_APPEND(open_files, p->open_files, of);
5✔
1498
                } else if ((val = startswith(l, "exec-parameters-fallback-smack-process-label="))) {
35,779✔
1499
                        r = free_and_strdup(&p->fallback_smack_process_label, val);
×
1500
                        if (r < 0)
×
1501
                                return r;
1502
                } else if ((val = startswith(l, "exec-parameters-user-lookup-fd="))) {
35,779✔
1503
                        int fd;
11,925✔
1504

1505
                        fd = deserialize_fd(fds, val);
11,925✔
1506
                        if (fd < 0)
11,925✔
1507
                                continue;
×
1508

1509
                        close_and_replace(p->user_lookup_fd, fd);
11,925✔
1510
                } else if ((val = startswith(l, "exec-parameters-files-env="))) {
23,854✔
1511
                        r = deserialize_strv(val, &p->files_env);
2✔
1512
                        if (r < 0)
2✔
1513
                                return r;
1514
                } else if ((val = startswith(l, "exec-parameters-unit-id="))) {
23,852✔
1515
                        r = free_and_strdup(&p->unit_id, val);
11,925✔
1516
                        if (r < 0)
11,925✔
1517
                                return r;
1518
                } else if ((val = startswith(l, "exec-parameters-invocation-id-string="))) {
11,927✔
1519
                        if (strlen(val) > SD_ID128_STRING_MAX - 1)
11,925✔
1520
                                return -EINVAL;
1521

1522
                        r = sd_id128_from_string(val, &p->invocation_id);
11,925✔
1523
                        if (r < 0)
11,925✔
1524
                                return r;
1525

1526
                        sd_id128_to_string(p->invocation_id, p->invocation_id_string);
11,925✔
1527
                } else if ((val = startswith(l, "exec-parameters-debug-invocation="))) {
2✔
1528
                        r = parse_boolean(val);
2✔
1529
                        if (r < 0)
2✔
1530
                                return r;
1531

1532
                        p->debug_invocation = r;
2✔
1533
                } else
1534
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
1535
        }
1536

1537
        /* Bail out if we got exec-parameters-n-{socket/storage}-fds= but no corresponding
1538
         * exec-parameters-fds= */
1539
        if (p->n_socket_fds + p->n_storage_fds > 0 && !p->fds)
11,925✔
1540
                return -EINVAL;
×
1541

1542
        return 0;
1543
}
1544

1545
static int serialize_std_out_err(const ExecContext *c, FILE *f, int fileno) {
4,620✔
1546
        char *key, *value;
4,620✔
1547
        const char *type;
4,620✔
1548

1549
        assert(c);
4,620✔
1550
        assert(f);
4,620✔
1551
        assert(IN_SET(fileno, STDOUT_FILENO, STDERR_FILENO));
4,620✔
1552

1553
        type = fileno == STDOUT_FILENO ? "output" : "error";
4,620✔
1554

1555
        switch (fileno == STDOUT_FILENO ? c->std_output : c->std_error) {
4,620✔
1556
        case EXEC_OUTPUT_NAMED_FD:
×
1557
                key = strjoina("exec-context-std-", type, "-fd-name");
×
1558
                value = c->stdio_fdname[fileno];
×
1559

1560
                break;
×
1561

1562
        case EXEC_OUTPUT_FILE:
2✔
1563
                key = strjoina("exec-context-std-", type, "-file");
14✔
1564
                value = c->stdio_file[fileno];
2✔
1565

1566
                break;
2✔
1567

1568
        case EXEC_OUTPUT_FILE_APPEND:
×
1569
                key = strjoina("exec-context-std-", type, "-file-append");
×
1570
                value = c->stdio_file[fileno];
×
1571

1572
                break;
×
1573

1574
        case EXEC_OUTPUT_FILE_TRUNCATE:
×
1575
                key = strjoina("exec-context-std-", type, "-file-truncate");
×
1576
                value = c->stdio_file[fileno];
×
1577

1578
                break;
×
1579

1580
        default:
1581
                return 0;
1582
        }
1583

1584
        return serialize_item(f, key, value);
2✔
1585
}
1586

1587
static int exec_context_serialize(const ExecContext *c, FILE *f) {
2,310✔
1588
        int r;
2,310✔
1589

1590
        assert(f);
2,310✔
1591

1592
        if (!c)
2,310✔
1593
                return 0;
2,310✔
1594

1595
        r = serialize_strv(f, "exec-context-environment", c->environment);
2,310✔
1596
        if (r < 0)
2,310✔
1597
                return r;
1598

1599
        r = serialize_strv(f, "exec-context-environment-files", c->environment_files);
2,310✔
1600
        if (r < 0)
2,310✔
1601
                return r;
1602

1603
        r = serialize_strv(f, "exec-context-pass-environment", c->pass_environment);
2,310✔
1604
        if (r < 0)
2,310✔
1605
                return r;
1606

1607
        r = serialize_strv(f, "exec-context-unset-environment", c->unset_environment);
2,310✔
1608
        if (r < 0)
2,310✔
1609
                return r;
1610

1611
        r = serialize_item_escaped(f, "exec-context-working-directory", c->working_directory);
2,310✔
1612
        if (r < 0)
2,310✔
1613
                return r;
1614

1615
        r = serialize_bool_elide(f, "exec-context-working-directory-missing-ok", c->working_directory_missing_ok);
2,310✔
1616
        if (r < 0)
2,310✔
1617
                return r;
1618

1619
        r = serialize_bool_elide(f, "exec-context-working-directory-home", c->working_directory_home);
2,310✔
1620
        if (r < 0)
2,310✔
1621
                return r;
1622

1623
        r = serialize_item_escaped(f, "exec-context-root-directory", c->root_directory);
2,310✔
1624
        if (r < 0)
2,310✔
1625
                return r;
1626

1627
        r = serialize_item_escaped(f, "exec-context-root-image", c->root_image);
2,310✔
1628
        if (r < 0)
2,310✔
1629
                return r;
1630

1631
        if (c->root_image_options) {
2,310✔
1632
                _cleanup_free_ char *options = NULL;
×
1633

1634
                LIST_FOREACH(mount_options, o, c->root_image_options) {
×
1635
                        if (isempty(o->options))
×
1636
                                continue;
×
1637

1638
                        _cleanup_free_ char *escaped = NULL;
×
1639
                        escaped = shell_escape(o->options, ":");
×
1640
                        if (!escaped)
×
1641
                                return log_oom_debug();
×
1642

1643
                        if (!strextend(&options,
×
1644
                                        " ",
1645
                                        partition_designator_to_string(o->partition_designator),
1646
                                               ":",
1647
                                               escaped))
1648
                                        return log_oom_debug();
×
1649
                }
1650

1651
                r = serialize_item(f, "exec-context-root-image-options", options);
×
1652
                if (r < 0)
×
1653
                        return r;
1654
        }
1655

1656
        r = serialize_item(f, "exec-context-root-verity", c->root_verity);
2,310✔
1657
        if (r < 0)
2,310✔
1658
                return r;
1659

1660
        r = serialize_item(f, "exec-context-root-hash-path", c->root_hash_path);
2,310✔
1661
        if (r < 0)
2,310✔
1662
                return r;
1663

1664
        r = serialize_item(f, "exec-context-root-hash-sig-path", c->root_hash_sig_path);
2,310✔
1665
        if (r < 0)
2,310✔
1666
                return r;
1667

1668
        r = serialize_item_hexmem(f, "exec-context-root-hash", c->root_hash, c->root_hash_size);
2,310✔
1669
        if (r < 0)
2,310✔
1670
                return r;
1671

1672
        r = serialize_item_base64mem(f, "exec-context-root-hash-sig", c->root_hash_sig, c->root_hash_sig_size);
2,310✔
1673
        if (r < 0)
2,310✔
1674
                return r;
1675

1676
        r = serialize_bool_elide(f, "exec-context-root-ephemeral", c->root_ephemeral);
2,310✔
1677
        if (r < 0)
2,310✔
1678
                return r;
1679

1680
        r = serialize_item_format(f, "exec-context-umask", "%04o", c->umask);
2,310✔
1681
        if (r < 0)
2,310✔
1682
                return r;
1683

1684
        r = serialize_bool_elide(f, "exec-context-non-blocking", c->non_blocking);
2,310✔
1685
        if (r < 0)
2,310✔
1686
                return r;
1687

1688
        r = serialize_item_tristate(f, "exec-context-private-mounts", c->private_mounts);
2,310✔
1689
        if (r < 0)
27✔
1690
                return r;
1691

1692
        r = serialize_item_tristate(f, "exec-context-mount-api-vfs", c->mount_apivfs);
2,310✔
1693
        if (r < 0)
2✔
1694
                return r;
1695

1696
        r = serialize_item_tristate(f, "exec-context-bind-log-sockets", c->bind_log_sockets);
2,310✔
1697
        if (r < 0)
×
1698
                return r;
1699

1700
        r = serialize_item_tristate(f, "exec-context-memory-ksm", c->memory_ksm);
2,310✔
1701
        if (r < 0)
×
1702
                return r;
1703

1704
        r = serialize_item(f, "exec-context-private-tmp", private_tmp_to_string(c->private_tmp));
2,310✔
1705
        if (r < 0)
2,310✔
1706
                return r;
1707

1708
        /* This must be set in unit_patch_contexts() before executing a command. */
1709
        assert(c->private_var_tmp >= 0 && c->private_var_tmp < _PRIVATE_TMP_MAX);
2,310✔
1710
        r = serialize_item(f, "exec-context-private-var-tmp", private_tmp_to_string(c->private_var_tmp));
2,310✔
1711
        if (r < 0)
2,310✔
1712
                return r;
1713

1714
        r = serialize_bool_elide(f, "exec-context-private-devices", c->private_devices);
2,310✔
1715
        if (r < 0)
2,310✔
1716
                return r;
1717

1718
        r = serialize_bool_elide(f, "exec-context-protect-kernel-tunables", c->protect_kernel_tunables);
2,310✔
1719
        if (r < 0)
2,310✔
1720
                return r;
1721

1722
        r = serialize_bool_elide(f, "exec-context-protect-kernel-modules", c->protect_kernel_modules);
2,310✔
1723
        if (r < 0)
2,310✔
1724
                return r;
1725

1726
        r = serialize_bool_elide(f, "exec-context-protect-kernel-logs", c->protect_kernel_logs);
2,310✔
1727
        if (r < 0)
2,310✔
1728
                return r;
1729

1730
        r = serialize_bool_elide(f, "exec-context-protect-clock", c->protect_clock);
2,310✔
1731
        if (r < 0)
2,310✔
1732
                return r;
1733

1734
        r = serialize_item(f, "exec-context-protect-control-groups", protect_control_groups_to_string(c->protect_control_groups));
2,310✔
1735
        if (r < 0)
2,310✔
1736
                return r;
1737

1738
        r = serialize_bool_elide(f, "exec-context-private-network", c->private_network);
2,310✔
1739
        if (r < 0)
2,310✔
1740
                return r;
1741

1742
        r = serialize_item(f, "exec-context-private-users", private_users_to_string(c->private_users));
2,310✔
1743
        if (r < 0)
2,310✔
1744
                return r;
1745

1746
        r = serialize_bool_elide(f, "exec-context-private-ipc", c->private_ipc);
2,310✔
1747
        if (r < 0)
2,310✔
1748
                return r;
1749

1750
        r = serialize_item(f, "exec-context-private-pids", private_pids_to_string(c->private_pids));
2,310✔
1751
        if (r < 0)
2,310✔
1752
                return r;
1753

1754
        r = serialize_bool_elide(f, "exec-context-remove-ipc", c->remove_ipc);
2,310✔
1755
        if (r < 0)
2,310✔
1756
                return r;
1757

1758
        r = serialize_item(f, "exec-context-protect-home", protect_home_to_string(c->protect_home));
2,310✔
1759
        if (r < 0)
2,310✔
1760
                return r;
1761

1762
        r = serialize_item(f, "exec-context-protect-system", protect_system_to_string(c->protect_system));
2,310✔
1763
        if (r < 0)
2,310✔
1764
                return r;
1765

1766
        r = serialize_bool_elide(f, "exec-context-same-pgrp", c->same_pgrp);
2,310✔
1767
        if (r < 0)
2,310✔
1768
                return r;
1769

1770
        r = serialize_bool(f, "exec-context-ignore-sigpipe", c->ignore_sigpipe);
2,310✔
1771
        if (r < 0)
2,310✔
1772
                return r;
1773

1774
        r = serialize_bool_elide(f, "exec-context-memory-deny-write-execute", c->memory_deny_write_execute);
2,310✔
1775
        if (r < 0)
2,310✔
1776
                return r;
1777

1778
        r = serialize_bool_elide(f, "exec-context-restrict-realtime", c->restrict_realtime);
2,310✔
1779
        if (r < 0)
2,310✔
1780
                return r;
1781

1782
        r = serialize_bool_elide(f, "exec-context-restrict-suid-sgid", c->restrict_suid_sgid);
2,310✔
1783
        if (r < 0)
2,310✔
1784
                return r;
1785

1786
        r = serialize_item(f, "exec-context-keyring-mode", exec_keyring_mode_to_string(c->keyring_mode));
2,310✔
1787
        if (r < 0)
2,310✔
1788
                return r;
1789

1790
        r = serialize_item(f, "exec-context-protect-hostname", protect_hostname_to_string(c->protect_hostname));
2,310✔
1791
        if (r < 0)
2,310✔
1792
                return r;
1793

1794
        r = serialize_item(f, "exec-context-private-hostname", c->private_hostname);
2,310✔
1795
        if (r < 0)
2,310✔
1796
                return r;
1797

1798
        r = serialize_item(f, "exec-context-protect-proc", protect_proc_to_string(c->protect_proc));
2,310✔
1799
        if (r < 0)
2,310✔
1800
                return r;
1801

1802
        r = serialize_item(f, "exec-context-proc-subset", proc_subset_to_string(c->proc_subset));
2,310✔
1803
        if (r < 0)
2,310✔
1804
                return r;
1805

1806
        r = serialize_item(f, "exec-context-private-bpf", private_bpf_to_string(c->private_bpf));
2,310✔
1807
        if (r < 0)
2,310✔
1808
                return r;
1809

1810
        if (c->bpf_delegate_commands != 0) {
2,310✔
1811
                r = serialize_item_format(f, "exec-context-bpf-delegate-commands", "0x%"PRIx64, c->bpf_delegate_commands);
×
1812
                if (r < 0)
×
1813
                        return r;
1814
        }
1815

1816
        if (c->bpf_delegate_maps != 0) {
2,310✔
1817
                r = serialize_item_format(f, "exec-context-bpf-delegate-maps", "0x%"PRIx64, c->bpf_delegate_maps);
×
1818
                if (r < 0)
×
1819
                        return r;
1820
        }
1821

1822
        if (c->bpf_delegate_programs != 0) {
2,310✔
1823
                r = serialize_item_format(f, "exec-context-bpf-delegate-programs", "0x%"PRIx64, c->bpf_delegate_programs);
×
1824
                if (r < 0)
×
1825
                        return r;
1826
        }
1827

1828
        if (c->bpf_delegate_attachments != 0) {
2,310✔
1829
                r = serialize_item_format(f, "exec-context-bpf-delegate-attachments", "0x%"PRIx64, c->bpf_delegate_attachments);
×
1830
                if (r < 0)
×
1831
                        return r;
1832
        }
1833

1834
        r = serialize_item(f, "exec-context-runtime-directory-preserve-mode", exec_preserve_mode_to_string(c->runtime_directory_preserve_mode));
2,310✔
1835
        if (r < 0)
2,310✔
1836
                return r;
1837

1838
        for (ExecDirectoryType dt = 0; dt < _EXEC_DIRECTORY_TYPE_MAX; dt++) {
13,860✔
1839
                _cleanup_free_ char *key = NULL, *value = NULL;
11,550✔
1840

1841
                key = strjoin("exec-context-directories-", exec_directory_type_to_string(dt));
11,550✔
1842
                if (!key)
11,550✔
1843
                        return log_oom_debug();
×
1844

1845
                if (asprintf(&value, "%04o", c->directories[dt].mode) < 0)
11,550✔
1846
                        return log_oom_debug();
×
1847

1848
                FOREACH_ARRAY(i, c->directories[dt].items, c->directories[dt].n_items) {
11,956✔
1849
                        _cleanup_free_ char *path_escaped = NULL;
406✔
1850

1851
                        path_escaped = shell_escape(i->path, ":" WHITESPACE);
406✔
1852
                        if (!path_escaped)
406✔
1853
                                return log_oom_debug();
×
1854

1855
                        if (!strextend(&value, " ", path_escaped))
406✔
1856
                                return log_oom_debug();
×
1857

1858
                        if (!strextend(&value, ":", yes_no(FLAGS_SET(i->flags, EXEC_DIRECTORY_ONLY_CREATE))))
807✔
1859
                                return log_oom_debug();
×
1860

1861
                        if (!strextend(&value, ":", yes_no(FLAGS_SET(i->flags, EXEC_DIRECTORY_READ_ONLY))))
810✔
1862
                                return log_oom_debug();
×
1863

1864
                        STRV_FOREACH(d, i->symlinks) {
412✔
1865
                                _cleanup_free_ char *link_escaped = NULL;
6✔
1866

1867
                                link_escaped = shell_escape(*d, ":" WHITESPACE);
6✔
1868
                                if (!link_escaped)
6✔
1869
                                        return log_oom_debug();
×
1870

1871
                                if (!strextend(&value, ":", link_escaped))
6✔
1872
                                        return log_oom_debug();
×
1873
                        }
1874
                }
1875

1876
                r = serialize_item(f, key, value);
11,550✔
1877
                if (r < 0)
11,550✔
1878
                        return r;
1879

1880
                if (c->directories[dt].exec_quota.quota_enforce) {
11,550✔
1881
                        _cleanup_free_ char *key_quota = NULL;
×
1882
                        key_quota = strjoin("exec-context-quota-directories-", exec_directory_type_to_string(dt));
×
1883
                        if (!key_quota)
×
1884
                                return log_oom_debug();
×
1885

1886
                        r = serialize_item_format(f, key_quota, "%" PRIu64 " %" PRIu32, c->directories[dt].exec_quota.quota_absolute,
×
1887
                                                                                        c->directories[dt].exec_quota.quota_scale);
×
1888
                        if (r < 0)
×
1889
                                return r;
1890

1891
                } else if (c->directories[dt].exec_quota.quota_accounting) {
11,550✔
1892
                        _cleanup_free_ char *key_quota = NULL;
×
1893
                        key_quota = strjoin("exec-context-quota-accounting-directories-", exec_directory_type_to_string(dt));
×
1894
                        if (!key_quota)
×
1895
                                return log_oom_debug();
×
1896

1897
                        r = serialize_bool(f, key_quota, c->directories[dt].exec_quota.quota_accounting);
×
1898
                        if (r < 0)
×
1899
                                return r;
1900
                }
1901
        }
1902

1903
        r = serialize_usec(f, "exec-context-timeout-clean-usec", c->timeout_clean_usec);
2,310✔
1904
        if (r < 0)
2,310✔
1905
                return r;
1906

1907
        if (c->nice_set) {
2,310✔
1908
                r = serialize_item_format(f, "exec-context-nice", "%i", c->nice);
2✔
1909
                if (r < 0)
2✔
1910
                        return r;
1911
        }
1912

1913
        if (c->oom_score_adjust_set) {
2,310✔
1914
                r = serialize_item_format(f, "exec-context-oom-score-adjust", "%i", c->oom_score_adjust);
687✔
1915
                if (r < 0)
687✔
1916
                        return r;
1917
        }
1918

1919
        if (c->coredump_filter_set) {
2,310✔
1920
                r = serialize_item_format(f, "exec-context-coredump-filter", "%"PRIx64, c->coredump_filter);
×
1921
                if (r < 0)
×
1922
                        return r;
1923
        }
1924

1925
        for (unsigned i = 0; i < RLIM_NLIMITS; i++) {
39,270✔
1926
                _cleanup_free_ char *key = NULL, *limit = NULL;
4,613✔
1927

1928
                if (!c->rlimit[i])
36,960✔
1929
                        continue;
32,347✔
1930

1931
                key = strjoin("exec-context-limit-", rlimit_to_string(i));
4,613✔
1932
                if (!key)
4,613✔
1933
                        return log_oom_debug();
×
1934

1935
                r = rlimit_format(c->rlimit[i], &limit);
4,613✔
1936
                if (r < 0)
4,613✔
1937
                        return r;
1938

1939
                r = serialize_item(f, key, limit);
4,613✔
1940
                if (r < 0)
4,613✔
1941
                        return r;
1942
        }
1943

1944
        if (c->ioprio_is_set) {
2,310✔
1945
                r = serialize_item_format(f, "exec-context-ioprio", "%d", c->ioprio);
4✔
1946
                if (r < 0)
4✔
1947
                        return r;
1948
        }
1949

1950
        if (c->cpu_sched_set) {
2,310✔
1951
                _cleanup_free_ char *policy_str = NULL;
×
1952

1953
                r = sched_policy_to_string_alloc(c->cpu_sched_policy, &policy_str);
×
1954
                if (r < 0)
×
1955
                        return r;
1956

1957
                r = serialize_item(f, "exec-context-cpu-scheduling-policy", policy_str);
×
1958
                if (r < 0)
×
1959
                        return r;
1960

1961
                r = serialize_item_format(f, "exec-context-cpu-scheduling-priority", "%i", c->cpu_sched_priority);
×
1962
                if (r < 0)
×
1963
                        return r;
1964

1965
                r = serialize_bool_elide(f, "exec-context-cpu-scheduling-reset-on-fork", c->cpu_sched_reset_on_fork);
×
1966
                if (r < 0)
×
1967
                        return r;
1968
        }
1969

1970
        if (c->cpu_set.set) {
2,310✔
1971
                _cleanup_free_ char *affinity = NULL;
×
1972

1973
                affinity = cpu_set_to_range_string(&c->cpu_set);
×
1974
                if (!affinity)
×
1975
                        return log_oom_debug();
×
1976

1977
                r = serialize_item(f, "exec-context-cpu-affinity", affinity);
×
1978
                if (r < 0)
×
1979
                        return r;
1980
        }
1981

1982
        if (mpol_is_valid(numa_policy_get_type(&c->numa_policy))) {
2,310✔
1983
                _cleanup_free_ char *nodes = NULL;
×
1984

1985
                nodes = cpu_set_to_range_string(&c->numa_policy.nodes);
×
1986
                if (!nodes)
×
1987
                        return log_oom_debug();
×
1988

1989
                if (nodes) {
×
1990
                        r = serialize_item(f, "exec-context-numa-mask", nodes);
×
1991
                        if (r < 0)
×
1992
                                return r;
1993
                }
1994

1995
                r = serialize_item_format(f, "exec-context-numa-policy", "%d", c->numa_policy.type);
×
1996
                if (r < 0)
×
1997
                        return r;
1998
        }
1999

2000
        r = serialize_bool_elide(f, "exec-context-cpu-affinity-from-numa", c->cpu_affinity_from_numa);
2,310✔
2001
        if (r < 0)
2,310✔
2002
                return r;
2003

2004
        if (c->timer_slack_nsec != NSEC_INFINITY) {
2,310✔
2005
                r = serialize_item_format(f, "exec-context-timer-slack-nsec", NSEC_FMT, c->timer_slack_nsec);
×
2006
                if (r < 0)
×
2007
                        return r;
2008
        }
2009

2010
        r = serialize_item(f, "exec-context-std-input", exec_input_to_string(c->std_input));
2,310✔
2011
        if (r < 0)
2,310✔
2012
                return r;
2013

2014
        r = serialize_item(f, "exec-context-std-output", exec_output_to_string(c->std_output));
2,310✔
2015
        if (r < 0)
2,310✔
2016
                return r;
2017

2018
        r = serialize_item(f, "exec-context-std-error", exec_output_to_string(c->std_error));
2,310✔
2019
        if (r < 0)
2,310✔
2020
                return r;
2021

2022
        r = serialize_bool_elide(f, "exec-context-stdio-as-fds", c->stdio_as_fds);
2,310✔
2023
        if (r < 0)
2,310✔
2024
                return r;
2025

2026
        switch (c->std_input) {
2,310✔
2027
        case EXEC_INPUT_NAMED_FD:
×
2028
                r = serialize_item(f, "exec-context-std-input-fd-name", c->stdio_fdname[STDIN_FILENO]);
×
2029
                if (r < 0)
×
2030
                        return r;
2031
                break;
2032

2033
        case EXEC_INPUT_FILE:
×
2034
                r = serialize_item(f, "exec-context-std-input-file", c->stdio_file[STDIN_FILENO]);
×
2035
                if (r < 0)
×
2036
                        return r;
2037
                break;
2038

2039
        default:
2,310✔
2040
                ;
2,310✔
2041
        }
2042

2043
        r = serialize_std_out_err(c, f, STDOUT_FILENO);
2,310✔
2044
        if (r < 0)
2,310✔
2045
                return r;
2046

2047
        r = serialize_std_out_err(c, f, STDERR_FILENO);
2,310✔
2048
        if (r < 0)
2,310✔
2049
                return r;
2050

2051
        r = serialize_item_base64mem(f, "exec-context-stdin-data", c->stdin_data, c->stdin_data_size);
2,310✔
2052
        if (r < 0)
2,310✔
2053
                return r;
2054

2055
        r = serialize_item(f, "exec-context-tty-path", c->tty_path);
2,310✔
2056
        if (r < 0)
2,310✔
2057
                return r;
2058

2059
        r = serialize_bool_elide(f, "exec-context-tty-reset", c->tty_reset);
2,310✔
2060
        if (r < 0)
2,310✔
2061
                return r;
2062

2063
        r = serialize_bool_elide(f, "exec-context-tty-vhangup", c->tty_vhangup);
2,310✔
2064
        if (r < 0)
2,310✔
2065
                return r;
2066

2067
        r = serialize_bool_elide(f, "exec-context-tty-vt-disallocate", c->tty_vt_disallocate);
2,310✔
2068
        if (r < 0)
2,310✔
2069
                return r;
2070

2071
        r = serialize_item_format(f, "exec-context-tty-rows", "%u", c->tty_rows);
2,310✔
2072
        if (r < 0)
2,310✔
2073
                return r;
2074

2075
        r = serialize_item_format(f, "exec-context-tty-columns", "%u", c->tty_cols);
2,310✔
2076
        if (r < 0)
2,310✔
2077
                return r;
2078

2079
        r = serialize_item_format(f, "exec-context-syslog-priority", "%i", c->syslog_priority);
2,310✔
2080
        if (r < 0)
2,310✔
2081
                return r;
2082

2083
        r = serialize_bool(f, "exec-context-syslog-level-prefix", c->syslog_level_prefix);
2,310✔
2084
        if (r < 0)
2,310✔
2085
                return r;
2086

2087
        r = serialize_item(f, "exec-context-syslog-identifier", c->syslog_identifier);
2,310✔
2088
        if (r < 0)
2,310✔
2089
                return r;
2090

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

2097
        if (c->log_ratelimit.interval > 0) {
2,310✔
2098
                r = serialize_usec(f, "exec-context-log-ratelimit-interval-usec", c->log_ratelimit.interval);
×
2099
                if (r < 0)
×
2100
                        return r;
2101
        }
2102

2103
        if (c->log_ratelimit.burst > 0) {
2,310✔
2104
                r = serialize_item_format(f, "exec-context-log-ratelimit-burst", "%u", c->log_ratelimit.burst);
×
2105
                if (r < 0)
×
2106
                        return r;
2107
        }
2108

2109
        r = serialize_string_set(f, "exec-context-log-filter-allowed-patterns", c->log_filter_allowed_patterns);
2,310✔
2110
        if (r < 0)
2,310✔
2111
                return r;
2112

2113
        r = serialize_string_set(f, "exec-context-log-filter-denied-patterns", c->log_filter_denied_patterns);
2,310✔
2114
        if (r < 0)
2,310✔
2115
                return r;
2116

2117
        FOREACH_ARRAY(field, c->log_extra_fields, c->n_log_extra_fields) {
2,310✔
2118
                r = serialize_item(f, "exec-context-log-extra-fields", field->iov_base);
×
2119
                if (r < 0)
×
2120
                        return r;
2121
        }
2122

2123
        r = serialize_item(f, "exec-context-log-namespace", c->log_namespace);
2,310✔
2124
        if (r < 0)
2,310✔
2125
                return r;
2126

2127
        if (c->secure_bits != 0) {
2,310✔
2128
                r = serialize_item_format(f, "exec-context-secure-bits", "%d", c->secure_bits);
×
2129
                if (r < 0)
×
2130
                        return r;
2131
        }
2132

2133
        if (c->capability_bounding_set != CAP_MASK_UNSET) {
2,310✔
2134
                r = serialize_item_format(f, "exec-context-capability-bounding-set", "%" PRIu64, c->capability_bounding_set);
255✔
2135
                if (r < 0)
255✔
2136
                        return r;
2137
        }
2138

2139
        if (c->capability_ambient_set != 0) {
2,310✔
2140
                r = serialize_item_format(f, "exec-context-capability-ambient-set", "%" PRIu64, c->capability_ambient_set);
63✔
2141
                if (r < 0)
63✔
2142
                        return r;
2143
        }
2144

2145
        if (c->user) {
2,310✔
2146
                r = serialize_item(f, "exec-context-user", c->user);
145✔
2147
                if (r < 0)
145✔
2148
                        return r;
2149
        }
2150

2151
        r = serialize_item(f, "exec-context-group", c->group);
2,310✔
2152
        if (r < 0)
2,310✔
2153
                return r;
2154

2155
        r = serialize_bool_elide(f, "exec-context-dynamic-user", c->dynamic_user);
2,310✔
2156
        if (r < 0)
2,310✔
2157
                return r;
2158

2159
        r = serialize_strv(f, "exec-context-supplementary-groups", c->supplementary_groups);
2,310✔
2160
        if (r < 0)
2,310✔
2161
                return r;
2162

2163
        r = serialize_item_tristate(f, "exec-context-set-login-environment", c->set_login_environment);
2,310✔
2164
        if (r < 0)
×
2165
                return r;
2166

2167
        r = serialize_item(f, "exec-context-pam-name", c->pam_name);
2,310✔
2168
        if (r < 0)
2,310✔
2169
                return r;
2170

2171
        r = serialize_strv(f, "exec-context-read-write-paths", c->read_write_paths);
2,310✔
2172
        if (r < 0)
2,310✔
2173
                return r;
2174

2175
        r = serialize_strv(f, "exec-context-read-only-paths", c->read_only_paths);
2,310✔
2176
        if (r < 0)
2,310✔
2177
                return r;
2178

2179
        r = serialize_strv(f, "exec-context-inaccessible-paths", c->inaccessible_paths);
2,310✔
2180
        if (r < 0)
2,310✔
2181
                return r;
2182

2183
        r = serialize_strv(f, "exec-context-exec-paths", c->exec_paths);
2,310✔
2184
        if (r < 0)
2,310✔
2185
                return r;
2186

2187
        r = serialize_strv(f, "exec-context-no-exec-paths", c->no_exec_paths);
2,310✔
2188
        if (r < 0)
2,310✔
2189
                return r;
2190

2191
        r = serialize_strv(f, "exec-context-exec-search-path", c->exec_search_path);
2,310✔
2192
        if (r < 0)
2,310✔
2193
                return r;
2194

2195
        r = serialize_item_format(f, "exec-context-mount-propagation-flag", "%lu", c->mount_propagation_flag);
2,310✔
2196
        if (r < 0)
2,310✔
2197
                return r;
2198

2199
        FOREACH_ARRAY(mount, c->bind_mounts, c->n_bind_mounts) {
2,325✔
2200
                _cleanup_free_ char *src_escaped = NULL, *dst_escaped = NULL;
15✔
2201

2202
                src_escaped = shell_escape(mount->source, ":" WHITESPACE);
15✔
2203
                if (!src_escaped)
15✔
2204
                        return log_oom_debug();
×
2205

2206
                dst_escaped = shell_escape(mount->destination, ":" WHITESPACE);
15✔
2207
                if (!dst_escaped)
15✔
2208
                        return log_oom_debug();
×
2209

2210
                r = serialize_item_format(f,
15✔
2211
                                          mount->read_only ? "exec-context-bind-read-only-path" : "exec-context-bind-path",
15✔
2212
                                          "%s%s:%s:%s",
2213
                                          mount->ignore_enoent ? "-" : "",
15✔
2214
                                          src_escaped,
2215
                                          dst_escaped,
2216
                                          mount->recursive ? "rbind" : "norbind");
15✔
2217
                if (r < 0)
15✔
2218
                        return r;
2219
        }
2220

2221
        FOREACH_ARRAY(tmpfs, c->temporary_filesystems, c->n_temporary_filesystems) {
2,314✔
2222
                _cleanup_free_ char *escaped = NULL;
4✔
2223

2224
                if (!isempty(tmpfs->options)) {
4✔
2225
                        escaped = shell_escape(tmpfs->options, ":");
×
2226
                        if (!escaped)
×
2227
                                return log_oom_debug();
×
2228
                }
2229

2230
                r = serialize_item_format(f, "exec-context-temporary-filesystems", "%s%s%s",
×
2231
                                          tmpfs->path,
2232
                                          isempty(escaped) ? "" : ":",
4✔
2233
                                          strempty(escaped));
2234
                if (r < 0)
4✔
2235
                        return r;
2236
        }
2237

2238
        r = serialize_item(f, "exec-context-utmp-id", c->utmp_id);
2,310✔
2239
        if (r < 0)
2,310✔
2240
                return r;
2241

2242
        r = serialize_item(f, "exec-context-utmp-mode", exec_utmp_mode_to_string(c->utmp_mode));
2,310✔
2243
        if (r < 0)
2,310✔
2244
                return r;
2245

2246
        r = serialize_bool_elide(f, "exec-context-no-new-privileges", c->no_new_privileges);
2,310✔
2247
        if (r < 0)
2,310✔
2248
                return r;
2249

2250
        if (c->selinux_context) {
2,310✔
2251
                r = serialize_item_format(f, "exec-context-selinux-context",
×
2252
                                          "%s%s",
2253
                                          c->selinux_context_ignore ? "-" : "",
×
2254
                                          c->selinux_context);
2255
                if (r < 0)
×
2256
                        return r;
2257
        }
2258

2259
        if (c->apparmor_profile) {
2,310✔
2260
                r = serialize_item_format(f, "exec-context-apparmor-profile",
×
2261
                                          "%s%s",
2262
                                          c->apparmor_profile_ignore ? "-" : "",
×
2263
                                          c->apparmor_profile);
2264
                if (r < 0)
×
2265
                        return r;
2266
        }
2267

2268
        if (c->smack_process_label) {
2,310✔
2269
                r = serialize_item_format(f, "exec-context-smack-process-label",
×
2270
                                          "%s%s",
2271
                                          c->smack_process_label_ignore ? "-" : "",
×
2272
                                          c->smack_process_label);
2273
                if (r < 0)
×
2274
                        return r;
2275
        }
2276

2277
        if (c->personality != PERSONALITY_INVALID) {
2,310✔
2278
                r = serialize_item(f, "exec-context-personality", personality_to_string(c->personality));
×
2279
                if (r < 0)
×
2280
                        return r;
2281
        }
2282

2283
        r = serialize_bool_elide(f, "exec-context-lock-personality", c->lock_personality);
2,310✔
2284
        if (r < 0)
2,310✔
2285
                return r;
2286

2287
#if HAVE_SECCOMP
2288
        if (!hashmap_isempty(c->syscall_filter)) {
2,310✔
2289
                void *errno_num, *id;
215✔
2290
                HASHMAP_FOREACH_KEY(errno_num, id, c->syscall_filter) {
84,258✔
2291
                        r = serialize_item_format(f, "exec-context-syscall-filter", "%d %d", PTR_TO_INT(id) - 1, PTR_TO_INT(errno_num));
84,043✔
2292
                        if (r < 0)
84,043✔
2293
                                return r;
×
2294
                }
2295
        }
2296

2297
        if (!set_isempty(c->syscall_archs)) {
2,310✔
2298
                void *id;
215✔
2299
                SET_FOREACH(id, c->syscall_archs) {
430✔
2300
                        r = serialize_item_format(f, "exec-context-syscall-archs", "%u", PTR_TO_UINT(id) - 1);
215✔
2301
                        if (r < 0)
215✔
2302
                                return r;
×
2303
                }
2304
        }
2305

2306
        if (c->syscall_errno > 0) {
2,310✔
2307
                r = serialize_item_format(f, "exec-context-syscall-errno", "%d", c->syscall_errno);
2,310✔
2308
                if (r < 0)
2,310✔
2309
                        return r;
2310
        }
2311

2312
        r = serialize_bool_elide(f, "exec-context-syscall-allow-list", c->syscall_allow_list);
2,310✔
2313
        if (r < 0)
2,310✔
2314
                return r;
2315

2316
        if (!hashmap_isempty(c->syscall_log)) {
2,310✔
2317
                void *errno_num, *id;
×
2318
                HASHMAP_FOREACH_KEY(errno_num, id, c->syscall_log) {
×
2319
                        r = serialize_item_format(f, "exec-context-syscall-log", "%d %d", PTR_TO_INT(id) - 1, PTR_TO_INT(errno_num));
×
2320
                        if (r < 0)
×
2321
                                return r;
×
2322
                }
2323
        }
2324

2325
        r = serialize_bool_elide(f, "exec-context-syscall-log-allow-list", c->syscall_log_allow_list);
2,310✔
2326
        if (r < 0)
2,310✔
2327
                return r;
2328
#endif
2329

2330
        if (c->restrict_namespaces != NAMESPACE_FLAGS_INITIAL) {
2,310✔
2331
                r = serialize_item_format(f, "exec-context-restrict-namespaces", "%lu", c->restrict_namespaces);
170✔
2332
                if (r < 0)
170✔
2333
                        return r;
2334
        }
2335

2336
        if (c->delegate_namespaces != NAMESPACE_FLAGS_INITIAL) {
2,310✔
2337
                r = serialize_item_format(f, "exec-context-delegate-namespaces", "%lu", c->delegate_namespaces);
9✔
2338
                if (r < 0)
9✔
2339
                        return r;
2340
        }
2341

2342
#if HAVE_LIBBPF
2343
        if (exec_context_restrict_filesystems_set(c)) {
2,310✔
2344
                char *fs;
×
2345
                SET_FOREACH(fs, c->restrict_filesystems) {
×
2346
                        r = serialize_item(f, "exec-context-restrict-filesystems", fs);
×
2347
                        if (r < 0)
×
2348
                                return r;
×
2349
                }
2350
        }
2351

2352
        r = serialize_bool_elide(f, "exec-context-restrict-filesystems-allow-list", c->restrict_filesystems_allow_list);
2,310✔
2353
        if (r < 0)
2,310✔
2354
                return r;
2355
#endif
2356

2357
        if (!set_isempty(c->address_families)) {
2,310✔
2358
                void *afp;
215✔
2359

2360
                SET_FOREACH(afp, c->address_families) {
1,050✔
2361
                        int af = PTR_TO_INT(afp);
835✔
2362

2363
                        if (af <= 0 || af >= af_max())
835✔
2364
                                continue;
×
2365

2366
                        r = serialize_item_format(f, "exec-context-address-families", "%d", af);
835✔
2367
                        if (r < 0)
835✔
2368
                                return r;
×
2369
                }
2370
        }
2371

2372
        r = serialize_bool_elide(f, "exec-context-address-families-allow-list", c->address_families_allow_list);
2,310✔
2373
        if (r < 0)
2,310✔
2374
                return r;
2375

2376
        r = serialize_item(f, "exec-context-network-namespace-path", c->network_namespace_path);
2,310✔
2377
        if (r < 0)
2,310✔
2378
                return r;
2379

2380
        r = serialize_item(f, "exec-context-ipc-namespace-path", c->ipc_namespace_path);
2,310✔
2381
        if (r < 0)
2,310✔
2382
                return r;
2383

2384
        FOREACH_ARRAY(mount, c->mount_images, c->n_mount_images) {
2,310✔
2385
                _cleanup_free_ char *s = NULL, *source_escaped = NULL, *dest_escaped = NULL;
×
2386

2387
                source_escaped = shell_escape(mount->source, WHITESPACE);
×
2388
                if (!source_escaped)
×
2389
                        return log_oom_debug();
×
2390

2391
                dest_escaped = shell_escape(mount->destination, WHITESPACE);
×
2392
                if (!dest_escaped)
×
2393
                        return log_oom_debug();
×
2394

2395
                s = strjoin(mount->ignore_enoent ? "-" : "",
×
2396
                            source_escaped,
2397
                            " ",
2398
                            dest_escaped);
2399
                if (!s)
×
2400
                        return log_oom_debug();
×
2401

2402
                LIST_FOREACH(mount_options, o, mount->mount_options) {
×
2403
                        _cleanup_free_ char *escaped = NULL;
×
2404

2405
                        if (isempty(o->options))
×
2406
                                continue;
×
2407

2408
                        escaped = shell_escape(o->options, ":");
×
2409
                        if (!escaped)
×
2410
                                return log_oom_debug();
×
2411

2412
                        if (!strextend(&s,
×
2413
                                       " ",
2414
                                       partition_designator_to_string(o->partition_designator),
2415
                                       ":",
2416
                                       escaped))
2417
                                return log_oom_debug();
×
2418
                }
2419

2420
                r = serialize_item(f, "exec-context-mount-image", s);
×
2421
                if (r < 0)
×
2422
                        return r;
2423
        }
2424

2425
        FOREACH_ARRAY(mount, c->extension_images, c->n_extension_images) {
2,310✔
2426
                _cleanup_free_ char *s = NULL, *source_escaped = NULL;
×
2427

2428
                source_escaped = shell_escape(mount->source, ":" WHITESPACE);
×
2429
                if (!source_escaped)
×
2430
                        return log_oom_debug();
×
2431

2432
                s = strjoin(mount->ignore_enoent ? "-" : "",
×
2433
                            source_escaped);
2434
                if (!s)
×
2435
                        return log_oom_debug();
×
2436

2437
                LIST_FOREACH(mount_options, o, mount->mount_options) {
×
2438
                        _cleanup_free_ char *escaped = NULL;
×
2439

2440
                        if (isempty(o->options))
×
2441
                                continue;
×
2442

2443
                        escaped = shell_escape(o->options, ":");
×
2444
                        if (!escaped)
×
2445
                                return log_oom_debug();
×
2446

2447
                        if (!strextend(&s,
×
2448
                                       " ",
2449
                                       partition_designator_to_string(o->partition_designator),
2450
                                       ":",
2451
                                       escaped))
2452
                                return log_oom_debug();
×
2453
                }
2454

2455
                r = serialize_item(f, "exec-context-extension-image", s);
×
2456
                if (r < 0)
×
2457
                        return r;
2458
        }
2459

2460
        r = serialize_strv(f, "exec-context-extension-directories", c->extension_directories);
2,310✔
2461
        if (r < 0)
2,310✔
2462
                return r;
2463

2464
        ExecSetCredential *sc;
2,310✔
2465
        HASHMAP_FOREACH(sc, c->set_credentials) {
2,310✔
2466
                _cleanup_free_ char *data = NULL;
×
2467

2468
                if (base64mem(sc->data, sc->size, &data) < 0)
×
2469
                        return log_oom_debug();
×
2470

2471
                r = serialize_item_format(f, "exec-context-set-credentials", "%s %s %s", sc->id, data, yes_no(sc->encrypted));
×
2472
                if (r < 0)
×
2473
                        return r;
2474
        }
2475

2476
        ExecLoadCredential *lc;
2,310✔
2477
        HASHMAP_FOREACH(lc, c->load_credentials) {
2,313✔
2478
                r = serialize_item_format(f, "exec-context-load-credentials", "%s %s %s", lc->id, lc->path, yes_no(lc->encrypted));
5✔
2479
                if (r < 0)
3✔
2480
                        return r;
×
2481
        }
2482

2483
        ExecImportCredential *ic;
2,310✔
2484
        ORDERED_SET_FOREACH(ic, c->import_credentials) {
3,216✔
2485
                r = serialize_item_format(f, "exec-context-import-credentials", "%s%s%s",
1,764✔
2486
                                          ic->glob,
2487
                                          ic->rename ? " " : "",
2488
                                          strempty(ic->rename));
906✔
2489
                if (r < 0)
906✔
2490
                        return r;
×
2491
        }
2492

2493
        r = serialize_image_policy(f, "exec-context-root-image-policy", c->root_image_policy);
2,310✔
2494
        if (r < 0)
2,310✔
2495
                return r;
2496

2497
        r = serialize_image_policy(f, "exec-context-mount-image-policy", c->mount_image_policy);
2,310✔
2498
        if (r < 0)
2,310✔
2499
                return r;
2500

2501
        r = serialize_image_policy(f, "exec-context-extension-image-policy", c->extension_image_policy);
2,310✔
2502
        if (r < 0)
2,310✔
2503
                return r;
2504

2505
        fputc('\n', f); /* End marker */
2,310✔
2506

2507
        return 0;
2508
}
2509

2510
static int exec_context_deserialize(ExecContext *c, FILE *f) {
11,925✔
2511
        int r;
11,925✔
2512

2513
        assert(f);
11,925✔
2514

2515
        if (!c)
11,925✔
2516
                return 0;
2517

2518
        for (;;) {
1,309,360✔
2519
                _cleanup_free_ char *l = NULL;
1,297,435✔
2520
                const char *val;
1,309,360✔
2521

2522
                r = deserialize_read_line(f, &l);
1,309,360✔
2523
                if (r < 0)
1,309,360✔
2524
                        return r;
2525
                if (r == 0) /* eof or end marker */
1,309,360✔
2526
                        break;
2527

2528
                if ((val = startswith(l, "exec-context-environment="))) {
1,297,435✔
2529
                        r = deserialize_strv(val, &c->environment);
3,901✔
2530
                        if (r < 0)
3,901✔
2531
                                return r;
2532
                } else if ((val = startswith(l, "exec-context-environment-files="))) {
1,293,534✔
2533
                        r = deserialize_strv(val, &c->environment_files);
340✔
2534
                        if (r < 0)
340✔
2535
                                return r;
2536
                } else if ((val = startswith(l, "exec-context-pass-environment="))) {
1,293,194✔
2537
                        r = deserialize_strv(val, &c->pass_environment);
443✔
2538
                        if (r < 0)
443✔
2539
                                return r;
2540
                } else if ((val = startswith(l, "exec-context-unset-environment="))) {
1,292,751✔
2541
                        r = deserialize_strv(val, &c->unset_environment);
1,514✔
2542
                        if (r < 0)
1,514✔
2543
                                return r;
2544
                } else if ((val = startswith(l, "exec-context-working-directory="))) {
1,291,237✔
2545
                        ssize_t k;
895✔
2546
                        char *p;
895✔
2547

2548
                        k = cunescape(val, 0, &p);
895✔
2549
                        if (k < 0)
895✔
2550
                                return k;
×
2551
                        free_and_replace(c->working_directory, p);
895✔
2552
                } else if ((val = startswith(l, "exec-context-root-directory="))) {
1,290,342✔
2553
                        ssize_t k;
7✔
2554
                        char *p;
7✔
2555

2556
                        k = cunescape(val, 0, &p);
7✔
2557
                        if (k < 0)
7✔
2558
                                return k;
×
2559
                        free_and_replace(c->root_directory, p);
7✔
2560
                } else if ((val = startswith(l, "exec-context-root-image="))) {
1,290,335✔
2561
                        ssize_t k;
8✔
2562
                        char *p;
8✔
2563

2564
                        k = cunescape(val, 0, &p);
8✔
2565
                        if (k < 0)
8✔
2566
                                return k;
×
2567
                        free_and_replace(c->root_image, p);
8✔
2568
                } else if ((val = startswith(l, "exec-context-root-image-options="))) {
1,290,327✔
2569
                        for (;;) {
×
2570
                                _cleanup_free_ char *word = NULL, *mount_options = NULL, *partition = NULL;
×
2571
                                PartitionDesignator partition_designator;
×
2572
                                MountOptions *o = NULL;
×
2573
                                const char *p;
×
2574

2575
                                r = extract_first_word(&val, &word, NULL, 0);
×
2576
                                if (r < 0)
×
2577
                                        return r;
2578
                                if (r == 0)
×
2579
                                        break;
2580

2581
                                p = word;
×
2582
                                r = extract_many_words(&p, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &partition, &mount_options);
×
2583
                                if (r < 0)
×
2584
                                        return r;
2585
                                if (r == 0)
×
2586
                                        continue;
×
2587

2588
                                partition_designator = partition_designator_from_string(partition);
×
2589
                                if (partition_designator < 0)
×
2590
                                        return -EINVAL;
2591

2592
                                o = new(MountOptions, 1);
×
2593
                                if (!o)
×
2594
                                        return log_oom_debug();
×
2595
                                *o = (MountOptions) {
×
2596
                                        .partition_designator = partition_designator,
2597
                                        .options = TAKE_PTR(mount_options),
×
2598
                                };
2599
                                LIST_APPEND(mount_options, c->root_image_options, o);
×
2600
                        }
2601
                } else if ((val = startswith(l, "exec-context-root-verity="))) {
1,290,327✔
2602
                        r = free_and_strdup(&c->root_verity, val);
×
2603
                        if (r < 0)
×
2604
                                return r;
2605
                } else if ((val = startswith(l, "exec-context-root-hash-path="))) {
1,290,327✔
2606
                        r = free_and_strdup(&c->root_hash_path, val);
×
2607
                        if (r < 0)
×
2608
                                return r;
2609
                } else if ((val = startswith(l, "exec-context-root-hash-sig-path="))) {
1,290,327✔
2610
                        r = free_and_strdup(&c->root_hash_sig_path, val);
×
2611
                        if (r < 0)
×
2612
                                return r;
2613
                } else if ((val = startswith(l, "exec-context-root-hash="))) {
1,290,327✔
2614
                        c->root_hash = mfree(c->root_hash);
4✔
2615
                        r = unhexmem(val, &c->root_hash, &c->root_hash_size);
4✔
2616
                        if (r < 0)
4✔
2617
                                return r;
2618
                } else if ((val = startswith(l, "exec-context-root-hash-sig="))) {
1,290,323✔
2619
                        c->root_hash_sig = mfree(c->root_hash_sig);
×
2620
                        r= unbase64mem(val, &c->root_hash_sig, &c->root_hash_sig_size);
×
2621
                        if (r < 0)
×
2622
                                return r;
2623
                } else if ((val = startswith(l, "exec-context-root-ephemeral="))) {
1,290,323✔
2624
                        r = parse_boolean(val);
×
2625
                        if (r < 0)
×
2626
                                return r;
2627
                        c->root_ephemeral = r;
×
2628
                } else if ((val = startswith(l, "exec-context-umask="))) {
1,290,323✔
2629
                        r = parse_mode(val, &c->umask);
11,925✔
2630
                        if (r < 0)
11,925✔
2631
                                return r;
2632
                } else if ((val = startswith(l, "exec-context-private-non-blocking="))) {
1,278,398✔
2633
                        r = parse_boolean(val);
×
2634
                        if (r < 0)
×
2635
                                return r;
2636
                        c->non_blocking = r;
×
2637
                } else if ((val = startswith(l, "exec-context-private-mounts="))) {
1,278,398✔
2638
                        r = safe_atoi(val, &c->private_mounts);
138✔
2639
                        if (r < 0)
138✔
2640
                                return r;
2641
                } else if ((val = startswith(l, "exec-context-mount-api-vfs="))) {
1,278,260✔
2642
                        r = safe_atoi(val, &c->mount_apivfs);
30✔
2643
                        if (r < 0)
30✔
2644
                                return r;
2645
                } else if ((val = startswith(l, "exec-context-bind-log-sockets="))) {
1,278,230✔
2646
                        r = safe_atoi(val, &c->bind_log_sockets);
2✔
2647
                        if (r < 0)
2✔
2648
                                return r;
2649
                } else if ((val = startswith(l, "exec-context-memory-ksm="))) {
1,278,228✔
2650
                        r = safe_atoi(val, &c->memory_ksm);
×
2651
                        if (r < 0)
×
2652
                                return r;
2653
                } else if ((val = startswith(l, "exec-context-private-tmp="))) {
1,278,228✔
2654
                        c->private_tmp = private_tmp_from_string(val);
11,925✔
2655
                        if (c->private_tmp < 0)
11,925✔
2656
                                return c->private_tmp;
2657
                } else if ((val = startswith(l, "exec-context-private-var-tmp="))) {
1,266,303✔
2658
                        c->private_var_tmp = private_tmp_from_string(val);
11,925✔
2659
                        if (c->private_var_tmp < 0)
11,925✔
2660
                                return c->private_var_tmp;
2661
                } else if ((val = startswith(l, "exec-context-private-devices="))) {
1,254,378✔
2662
                        r = parse_boolean(val);
648✔
2663
                        if (r < 0)
648✔
2664
                                return r;
2665
                        c->private_devices = r;
648✔
2666
                } else if ((val = startswith(l, "exec-context-protect-kernel-tunables="))) {
1,253,730✔
2667
                        r = parse_boolean(val);
459✔
2668
                        if (r < 0)
459✔
2669
                                return r;
2670
                        c->protect_kernel_tunables = r;
459✔
2671
                } else if ((val = startswith(l, "exec-context-protect-kernel-modules="))) {
1,253,271✔
2672
                        r = parse_boolean(val);
1,680✔
2673
                        if (r < 0)
1,680✔
2674
                                return r;
2675
                        c->protect_kernel_modules = r;
1,680✔
2676
                } else if ((val = startswith(l, "exec-context-protect-kernel-logs="))) {
1,251,591✔
2677
                        r = parse_boolean(val);
1,680✔
2678
                        if (r < 0)
1,680✔
2679
                                return r;
2680
                        c->protect_kernel_logs = r;
1,680✔
2681
                } else if ((val = startswith(l, "exec-context-protect-clock="))) {
1,249,911✔
2682
                        r = parse_boolean(val);
1,600✔
2683
                        if (r < 0)
1,600✔
2684
                                return r;
2685
                        c->protect_clock = r;
1,600✔
2686
                } else if ((val = startswith(l, "exec-context-protect-control-groups="))) {
1,248,311✔
2687
                        r = protect_control_groups_from_string(val);
11,925✔
2688
                        if (r < 0)
11,925✔
2689
                                return r;
2690
                        c->protect_control_groups = r;
11,925✔
2691
                } else if ((val = startswith(l, "exec-context-private-network="))) {
1,236,386✔
2692
                        r = parse_boolean(val);
64✔
2693
                        if (r < 0)
64✔
2694
                                return r;
2695
                        c->private_network = r;
64✔
2696
                } else if ((val = startswith(l, "exec-context-private-users="))) {
1,236,322✔
2697
                        c->private_users = private_users_from_string(val);
11,925✔
2698
                        if (c->private_users < 0)
11,925✔
2699
                                return -EINVAL;
2700
                } else if ((val = startswith(l, "exec-context-private-ipc="))) {
1,224,397✔
2701
                        r = parse_boolean(val);
6✔
2702
                        if (r < 0)
6✔
2703
                                return r;
2704
                        c->private_ipc = r;
6✔
2705
                } else if ((val = startswith(l, "exec-context-private-pids="))) {
1,224,391✔
2706
                        c->private_pids = private_pids_from_string(val);
11,925✔
2707
                        if (c->private_pids < 0)
11,925✔
2708
                                return -EINVAL;
2709
                } else if ((val = startswith(l, "exec-context-remove-ipc="))) {
1,212,466✔
2710
                        r = parse_boolean(val);
70✔
2711
                        if (r < 0)
70✔
2712
                                return r;
2713
                        c->remove_ipc = r;
70✔
2714
                } else if ((val = startswith(l, "exec-context-protect-home="))) {
1,212,396✔
2715
                        c->protect_home = protect_home_from_string(val);
11,925✔
2716
                        if (c->protect_home < 0)
11,925✔
2717
                                return -EINVAL;
2718
                } else if ((val = startswith(l, "exec-context-protect-system="))) {
1,200,471✔
2719
                        c->protect_system = protect_system_from_string(val);
11,925✔
2720
                        if (c->protect_system < 0)
11,925✔
2721
                                return -EINVAL;
2722
                } else if ((val = startswith(l, "exec-context-same-pgrp="))) {
1,188,546✔
2723
                        r = parse_boolean(val);
868✔
2724
                        if (r < 0)
868✔
2725
                                return r;
2726
                        c->same_pgrp = r;
868✔
2727
                } else if ((val = startswith(l, "exec-context-non-blocking="))) {
1,187,678✔
2728
                        r = parse_boolean(val);
×
2729
                        if (r < 0)
×
2730
                                return r;
2731
                        c->non_blocking = r;
×
2732
                } else if ((val = startswith(l, "exec-context-ignore-sigpipe="))) {
1,187,678✔
2733
                        r = parse_boolean(val);
11,925✔
2734
                        if (r < 0)
11,925✔
2735
                                return r;
2736
                        c->ignore_sigpipe = r;
11,925✔
2737
                } else if ((val = startswith(l, "exec-context-memory-deny-write-execute="))) {
1,175,753✔
2738
                        r = parse_boolean(val);
2,171✔
2739
                        if (r < 0)
2,171✔
2740
                                return r;
2741
                        c->memory_deny_write_execute = r;
2,171✔
2742
                } else if ((val = startswith(l, "exec-context-restrict-realtime="))) {
1,173,582✔
2743
                        r = parse_boolean(val);
2,173✔
2744
                        if (r < 0)
2,173✔
2745
                                return r;
2746
                        c->restrict_realtime = r;
2,173✔
2747
                } else if ((val = startswith(l, "exec-context-restrict-suid-sgid="))) {
1,171,409✔
2748
                        r = parse_boolean(val);
2,107✔
2749
                        if (r < 0)
2,107✔
2750
                                return r;
2751
                        c->restrict_suid_sgid = r;
2,107✔
2752
                } else if ((val = startswith(l, "exec-context-keyring-mode="))) {
1,169,302✔
2753
                        c->keyring_mode = exec_keyring_mode_from_string(val);
11,925✔
2754
                        if (c->keyring_mode < 0)
11,925✔
2755
                                return -EINVAL;
2756
                } else if ((val = startswith(l, "exec-context-protect-hostname="))) {
1,157,377✔
2757
                        c->protect_hostname = protect_hostname_from_string(val);
11,925✔
2758
                        if (c->protect_hostname < 0)
11,925✔
2759
                                return -EINVAL;
2760
                } else if ((val = startswith(l, "exec-context-private-hostname="))) {
1,145,452✔
2761
                        r = free_and_strdup(&c->private_hostname, val);
5✔
2762
                        if (r < 0)
5✔
2763
                                return r;
2764
                } else if ((val = startswith(l, "exec-context-protect-proc="))) {
1,145,447✔
2765
                        c->protect_proc = protect_proc_from_string(val);
11,925✔
2766
                        if (c->protect_proc < 0)
11,925✔
2767
                                return -EINVAL;
2768
                } else if ((val = startswith(l, "exec-context-proc-subset="))) {
1,133,522✔
2769
                        c->proc_subset = proc_subset_from_string(val);
11,925✔
2770
                        if (c->proc_subset < 0)
11,925✔
2771
                                return -EINVAL;
2772
                } else if ((val = startswith(l, "exec-context-private-bpf="))) {
1,121,597✔
2773
                        c->private_bpf = private_bpf_from_string(val);
11,925✔
2774
                        if (c->private_bpf < 0)
11,925✔
2775
                                return -EINVAL;
2776
                } else if ((val = startswith(l, "exec-context-bpf-delegate-commands="))) {
1,109,672✔
2777
                        r = safe_atoux64(val, &c->bpf_delegate_commands);
2✔
2778
                        if (r < 0)
2✔
2779
                                return r;
2780
                } else if ((val = startswith(l, "exec-context-bpf-delegate-maps="))) {
1,109,670✔
2781
                        r = safe_atoux64(val, &c->bpf_delegate_maps);
1✔
2782
                        if (r < 0)
1✔
2783
                                return r;
2784
                } else if ((val = startswith(l, "exec-context-bpf-delegate-programs="))) {
1,109,669✔
2785
                        r = safe_atoux64(val, &c->bpf_delegate_programs);
1✔
2786
                        if (r < 0)
1✔
2787
                                return r;
2788
                } else if ((val = startswith(l, "exec-context-bpf-delegate-attachments="))) {
1,109,668✔
2789
                        r = safe_atoux64(val, &c->bpf_delegate_attachments);
1✔
2790
                        if (r < 0)
1✔
2791
                                return r;
2792
                } else if ((val = startswith(l, "exec-context-runtime-directory-preserve-mode="))) {
1,109,667✔
2793
                        c->runtime_directory_preserve_mode = exec_preserve_mode_from_string(val);
11,925✔
2794
                        if (c->runtime_directory_preserve_mode < 0)
11,925✔
2795
                                return -EINVAL;
2796
                } else if ((val = startswith(l, "exec-context-directories-"))) {
1,097,742✔
2797
                        _cleanup_free_ char *type = NULL, *mode = NULL;
×
2798
                        ExecDirectoryType dt;
59,625✔
2799

2800
                        r = extract_many_words(&val, "= ", 0, &type, &mode);
59,625✔
2801
                        if (r < 0)
59,625✔
2802
                                return r;
2803
                        if (r == 0 || !mode)
59,625✔
2804
                                return -EINVAL;
2805

2806
                        dt = exec_directory_type_from_string(type);
59,625✔
2807
                        if (dt < 0)
59,625✔
2808
                                return dt;
2809

2810
                        r = parse_mode(mode, &c->directories[dt].mode);
59,625✔
2811
                        if (r < 0)
59,625✔
2812
                                return r;
2813

2814
                        for (;;) {
63,251✔
2815
                                _cleanup_free_ char *tuple = NULL, *path = NULL, *only_create = NULL, *read_only = NULL;
63,144✔
2816
                                ExecDirectoryFlags exec_directory_flags = 0;
63,251✔
2817
                                const char *p;
63,251✔
2818

2819
                                /* Use EXTRACT_UNESCAPE_RELAX here, as we unescape the colons in subsequent calls */
2820
                                r = extract_first_word(&val, &tuple, WHITESPACE, EXTRACT_UNESCAPE_SEPARATORS|EXTRACT_UNESCAPE_RELAX);
63,251✔
2821
                                if (r < 0)
63,251✔
2822
                                        return r;
2823
                                if (r == 0)
63,251✔
2824
                                        break;
2825

2826
                                p = tuple;
3,626✔
2827
                                r = extract_many_words(&p, ":", EXTRACT_UNESCAPE_SEPARATORS, &path, &only_create, &read_only);
3,626✔
2828
                                if (r < 0)
3,626✔
2829
                                        return r;
2830
                                if (r < 2)
3,626✔
2831
                                        continue;
×
2832

2833
                                r = parse_boolean(only_create);
3,626✔
2834
                                if (r < 0)
3,626✔
2835
                                        return r;
2836
                                if (r > 0)
3,626✔
2837
                                        exec_directory_flags |= EXEC_DIRECTORY_ONLY_CREATE;
5✔
2838

2839
                                r = parse_boolean(read_only);
3,626✔
2840
                                if (r < 0)
3,626✔
2841
                                        return r;
2842
                                if (r > 0)
3,626✔
2843
                                        exec_directory_flags |= EXEC_DIRECTORY_READ_ONLY;
50✔
2844

2845
                                r = exec_directory_add(&c->directories[dt], path, /* symlink= */ NULL, exec_directory_flags);
3,626✔
2846
                                if (r < 0)
3,626✔
2847
                                        return r;
2848

2849
                                if (isempty(p))
3,626✔
2850
                                        continue;
3,519✔
2851

2852
                                for (;;) {
385✔
2853
                                        _cleanup_free_ char *link = NULL;
246✔
2854

2855
                                        r = extract_first_word(&p, &link, ":", EXTRACT_UNESCAPE_SEPARATORS);
246✔
2856
                                        if (r < 0)
246✔
2857
                                                return r;
2858
                                        if (r == 0)
246✔
2859
                                                break;
2860

2861
                                        r = strv_consume(&c->directories[dt].items[c->directories[dt].n_items - 1].symlinks, TAKE_PTR(link));
139✔
2862
                                        if (r < 0)
139✔
2863
                                                return r;
2864
                                }
2865
                        }
2866
                } else if ((val = startswith(l, "exec-context-quota-accounting-directories-"))) {
1,038,117✔
2867
                        _cleanup_free_ char *type = NULL, *quota_accounting = NULL;
×
2868
                        ExecDirectoryType dt;
×
2869

2870
                        r = split_pair(val, "=", &type, &quota_accounting);
×
2871
                        if (r < 0)
×
2872
                                return r;
2873

2874
                        dt = exec_directory_type_from_string(type);
×
2875
                        if (dt < 0)
×
2876
                                return dt;
2877

2878
                        r = parse_boolean(quota_accounting);
×
2879
                        if (r < 0)
×
2880
                                return r;
2881

2882
                        c->directories[dt].exec_quota.quota_accounting = r;
×
2883
                } else if ((val = startswith(l, "exec-context-quota-directories-"))) {
1,038,117✔
2884
                        _cleanup_free_ char *type = NULL, *quota_info = NULL, *quota_absolute = NULL, *quota_scale = NULL;
×
2885
                        ExecDirectoryType dt;
×
2886

2887
                        r = split_pair(val, "=", &type, &quota_info);
×
2888
                        if (r < 0)
×
2889
                                return r;
2890

2891
                        r = split_pair(quota_info, " ", &quota_absolute, &quota_scale);
×
2892
                        if (r < 0)
×
2893
                                return r;
2894

2895
                        dt = exec_directory_type_from_string(type);
×
2896
                        if (dt < 0)
×
2897
                                return dt;
2898

2899
                        r = safe_atou64(quota_absolute, &c->directories[dt].exec_quota.quota_absolute);
×
2900
                        if (r < 0)
×
2901
                               return r;
2902

2903
                        r = safe_atou32(quota_scale, &c->directories[dt].exec_quota.quota_scale);
×
2904
                        if (r < 0)
×
2905
                               return r;
2906

2907
                        c->directories[dt].exec_quota.quota_enforce = true;
×
2908
                } else if ((val = startswith(l, "exec-context-timeout-clean-usec="))) {
1,038,117✔
2909
                        r = deserialize_usec(val, &c->timeout_clean_usec);
×
2910
                        if (r < 0)
×
2911
                                return r;
2912
                } else if ((val = startswith(l, "exec-context-nice="))) {
1,038,117✔
2913
                        r = safe_atoi(val, &c->nice);
17✔
2914
                        if (r < 0)
17✔
2915
                                return r;
2916
                        c->nice_set = true;
17✔
2917
                } else if ((val = startswith(l, "exec-context-working-directory-missing-ok="))) {
1,038,100✔
2918
                        r = parse_boolean(val);
835✔
2919
                        if (r < 0)
835✔
2920
                                return r;
2921
                        c->working_directory_missing_ok = r;
835✔
2922
                } else if ((val = startswith(l, "exec-context-working-directory-home="))) {
1,037,265✔
2923
                        r = parse_boolean(val);
165✔
2924
                        if (r < 0)
165✔
2925
                                return r;
2926
                        c->working_directory_home = r;
165✔
2927
                } else if ((val = startswith(l, "exec-context-oom-score-adjust="))) {
1,037,100✔
2928
                        r = safe_atoi(val, &c->oom_score_adjust);
1,342✔
2929
                        if (r < 0)
1,342✔
2930
                                return r;
2931
                        c->oom_score_adjust_set = true;
1,342✔
2932
                } else if ((val = startswith(l, "exec-context-coredump-filter="))) {
1,035,758✔
2933
                        r = safe_atoux64(val, &c->coredump_filter);
2✔
2934
                        if (r < 0)
2✔
2935
                                return r;
2936
                        c->coredump_filter_set = true;
2✔
2937
                } else if ((val = startswith(l, "exec-context-limit-"))) {
1,035,756✔
2938
                        _cleanup_free_ struct rlimit *rlimit = NULL;
×
2939
                        _cleanup_free_ char *limit = NULL;
23,845✔
2940
                        int type;
23,845✔
2941

2942
                        r = extract_first_word(&val, &limit, "=", 0);
23,845✔
2943
                        if (r < 0)
23,845✔
2944
                                return r;
2945
                        if (r == 0 || !val)
23,845✔
2946
                                return -EINVAL;
2947

2948
                        type = rlimit_from_string(limit);
23,845✔
2949
                        if (type < 0)
23,845✔
2950
                                return -EINVAL;
2951

2952
                        if (!c->rlimit[type]) {
23,845✔
2953
                                rlimit = new0(struct rlimit, 1);
23,845✔
2954
                                if (!rlimit)
23,845✔
2955
                                        return log_oom_debug();
×
2956

2957
                                r = rlimit_parse(type, val, rlimit);
23,845✔
2958
                                if (r < 0)
23,845✔
2959
                                        return r;
2960

2961
                                c->rlimit[type] = TAKE_PTR(rlimit);
23,845✔
2962
                        } else {
2963
                                r = rlimit_parse(type, val, c->rlimit[type]);
×
2964
                                if (r < 0)
×
2965
                                        return r;
2966
                        }
2967
                } else if ((val = startswith(l, "exec-context-ioprio="))) {
1,011,911✔
2968
                        r = safe_atoi(val, &c->ioprio);
10✔
2969
                        if (r < 0)
10✔
2970
                                return r;
2971
                        c->ioprio_is_set = true;
10✔
2972
                } else if ((val = startswith(l, "exec-context-cpu-scheduling-policy="))) {
1,011,901✔
2973
                        c->cpu_sched_policy = sched_policy_from_string(val);
×
2974
                        if (c->cpu_sched_policy < 0)
×
2975
                                return -EINVAL;
2976
                        c->cpu_sched_set = true;
×
2977
                } else if ((val = startswith(l, "exec-context-cpu-scheduling-priority="))) {
1,011,901✔
2978
                        r = safe_atoi(val, &c->cpu_sched_priority);
×
2979
                        if (r < 0)
×
2980
                                return r;
2981
                        c->cpu_sched_set = true;
×
2982
                } else if ((val = startswith(l, "exec-context-cpu-scheduling-reset-on-fork="))) {
1,011,901✔
2983
                        r = parse_boolean(val);
×
2984
                        if (r < 0)
×
2985
                                return r;
2986
                        c->cpu_sched_reset_on_fork = r;
×
2987
                        c->cpu_sched_set = true;
×
2988
                } else if ((val = startswith(l, "exec-context-cpu-affinity="))) {
1,011,901✔
2989
                        if (c->cpu_set.set)
×
2990
                                return -EINVAL; /* duplicated */
2991

2992
                        r = parse_cpu_set(val, &c->cpu_set);
×
2993
                        if (r < 0)
×
2994
                                return r;
2995
                } else if ((val = startswith(l, "exec-context-numa-mask="))) {
1,011,901✔
2996
                        if (c->numa_policy.nodes.set)
19✔
2997
                                return -EINVAL; /* duplicated */
2998

2999
                        r = parse_cpu_set(val, &c->numa_policy.nodes);
19✔
3000
                        if (r < 0)
19✔
3001
                                return r;
3002
                } else if ((val = startswith(l, "exec-context-numa-policy="))) {
1,011,882✔
3003
                        r = safe_atoi(val, &c->numa_policy.type);
19✔
3004
                        if (r < 0)
19✔
3005
                                return r;
3006
                } else if ((val = startswith(l, "exec-context-cpu-affinity-from-numa="))) {
1,011,863✔
3007
                        r = parse_boolean(val);
2✔
3008
                        if (r < 0)
2✔
3009
                                return r;
3010
                        c->cpu_affinity_from_numa = r;
2✔
3011
                } else if ((val = startswith(l, "exec-context-timer-slack-nsec="))) {
1,011,861✔
3012
                        r = deserialize_usec(val, (usec_t *)&c->timer_slack_nsec);
×
3013
                        if (r < 0)
×
3014
                                return r;
3015
                } else if ((val = startswith(l, "exec-context-std-input="))) {
1,011,861✔
3016
                        c->std_input = exec_input_from_string(val);
11,925✔
3017
                        if (c->std_input < 0)
11,925✔
3018
                                return c->std_input;
3019
                } else if ((val = startswith(l, "exec-context-std-output="))) {
999,936✔
3020
                        c->std_output = exec_output_from_string(val);
11,925✔
3021
                        if (c->std_output < 0)
11,925✔
3022
                                return c->std_output;
3023
                } else if ((val = startswith(l, "exec-context-std-error="))) {
988,011✔
3024
                        c->std_error = exec_output_from_string(val);
11,925✔
3025
                        if (c->std_error < 0)
11,925✔
3026
                                return c->std_error;
3027
                } else if ((val = startswith(l, "exec-context-stdio-as-fds="))) {
976,086✔
3028
                        r = parse_boolean(val);
562✔
3029
                        if (r < 0)
562✔
3030
                                return r;
3031
                        c->stdio_as_fds = r;
562✔
3032
                } else if ((val = startswith(l, "exec-context-std-input-fd-name="))) {
975,524✔
3033
                        r = free_and_strdup(&c->stdio_fdname[STDIN_FILENO], val);
×
3034
                        if (r < 0)
×
3035
                                return r;
3036
                } else if ((val = startswith(l, "exec-context-std-output-fd-name="))) {
975,524✔
3037
                        r = free_and_strdup(&c->stdio_fdname[STDOUT_FILENO], val);
×
3038
                        if (r < 0)
×
3039
                                return r;
3040
                } else if ((val = startswith(l, "exec-context-std-error-fd-name="))) {
975,524✔
3041
                        r = free_and_strdup(&c->stdio_fdname[STDERR_FILENO], val);
×
3042
                        if (r < 0)
×
3043
                                return r;
3044
                } else if ((val = startswith(l, "exec-context-std-input-file="))) {
975,524✔
3045
                        r = free_and_strdup(&c->stdio_file[STDIN_FILENO], val);
×
3046
                        if (r < 0)
×
3047
                                return r;
3048
                } else if ((val = startswith(l, "exec-context-std-output-file="))) {
975,524✔
3049
                        r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], val);
5✔
3050
                        if (r < 0)
5✔
3051
                                return r;
3052
                } else if ((val = startswith(l, "exec-context-std-output-file-append="))) {
975,519✔
3053
                        r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], val);
1✔
3054
                        if (r < 0)
1✔
3055
                                return r;
3056
                } else if ((val = startswith(l, "exec-context-std-output-file-truncate="))) {
975,518✔
3057
                        r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], val);
2✔
3058
                        if (r < 0)
2✔
3059
                                return r;
3060
                } else if ((val = startswith(l, "exec-context-std-error-file="))) {
975,516✔
3061
                        r = free_and_strdup(&c->stdio_file[STDERR_FILENO], val);
2✔
3062
                        if (r < 0)
2✔
3063
                                return r;
3064
                } else if ((val = startswith(l, "exec-context-std-error-file-append="))) {
975,514✔
3065
                        r = free_and_strdup(&c->stdio_file[STDERR_FILENO], val);
1✔
3066
                        if (r < 0)
1✔
3067
                                return r;
3068
                } else if ((val = startswith(l, "exec-context-std-error-file-truncate="))) {
975,513✔
3069
                        r = free_and_strdup(&c->stdio_file[STDERR_FILENO], val);
1✔
3070
                        if (r < 0)
1✔
3071
                                return r;
3072
                } else if ((val = startswith(l, "exec-context-stdin-data="))) {
975,512✔
3073
                        if (c->stdin_data)
1✔
3074
                                return -EINVAL; /* duplicated */
3075

3076
                        r = unbase64mem(val, &c->stdin_data, &c->stdin_data_size);
1✔
3077
                        if (r < 0)
1✔
3078
                                return r;
3079
                } else if ((val = startswith(l, "exec-context-tty-path="))) {
975,511✔
3080
                        r = free_and_strdup(&c->tty_path, val);
170✔
3081
                        if (r < 0)
170✔
3082
                                return r;
3083
                } else if ((val = startswith(l, "exec-context-tty-reset="))) {
975,341✔
3084
                        r = parse_boolean(val);
159✔
3085
                        if (r < 0)
159✔
3086
                                return r;
3087
                        c->tty_reset = r;
159✔
3088
                } else if ((val = startswith(l, "exec-context-tty-vhangup="))) {
975,182✔
3089
                        r = parse_boolean(val);
154✔
3090
                        if (r < 0)
154✔
3091
                                return r;
3092
                        c->tty_vhangup = r;
154✔
3093
                } else if ((val = startswith(l, "exec-context-tty-vt-disallocate="))) {
975,028✔
3094
                        r = parse_boolean(val);
91✔
3095
                        if (r < 0)
91✔
3096
                                return r;
3097
                        c->tty_vt_disallocate = r;
91✔
3098
                } else if ((val = startswith(l, "exec-context-tty-rows="))) {
974,937✔
3099
                        r = safe_atou(val, &c->tty_rows);
11,925✔
3100
                        if (r < 0)
11,925✔
3101
                                return r;
3102
                } else if ((val = startswith(l, "exec-context-tty-columns="))) {
963,012✔
3103
                        r = safe_atou(val, &c->tty_cols);
11,925✔
3104
                        if (r < 0)
11,925✔
3105
                                return r;
3106
                } else if ((val = startswith(l, "exec-context-syslog-priority="))) {
951,087✔
3107
                        r = safe_atoi(val, &c->syslog_priority);
11,925✔
3108
                        if (r < 0)
11,925✔
3109
                                return r;
3110
                } else if ((val = startswith(l, "exec-context-syslog-level-prefix="))) {
939,162✔
3111
                        r = parse_boolean(val);
11,925✔
3112
                        if (r < 0)
11,925✔
3113
                                return r;
3114
                        c->syslog_level_prefix = r;
11,925✔
3115
                } else if ((val = startswith(l, "exec-context-syslog-identifier="))) {
927,237✔
3116
                        r = free_and_strdup(&c->syslog_identifier, val);
×
3117
                        if (r < 0)
×
3118
                                return r;
3119
                } else if ((val = startswith(l, "exec-context-log-level-max="))) {
927,237✔
3120
                        /* See comment in serialization. */
3121
                        r = safe_atoi(val, &c->log_level_max);
11,925✔
3122
                        if (r < 0)
11,925✔
3123
                                return r;
3124
                } else if ((val = startswith(l, "exec-context-log-ratelimit-interval-usec="))) {
915,312✔
3125
                        r = deserialize_usec(val, &c->log_ratelimit.interval);
×
3126
                        if (r < 0)
×
3127
                                return r;
3128
                } else if ((val = startswith(l, "exec-context-log-ratelimit-burst="))) {
915,312✔
3129
                        r = safe_atou(val, &c->log_ratelimit.burst);
×
3130
                        if (r < 0)
×
3131
                                return r;
3132
                } else if ((val = startswith(l, "exec-context-log-filter-allowed-patterns="))) {
915,312✔
3133
                        r = set_put_strdup(&c->log_filter_allowed_patterns, val);
9✔
3134
                        if (r < 0)
9✔
3135
                                return r;
3136
                } else if ((val = startswith(l, "exec-context-log-filter-denied-patterns="))) {
915,303✔
3137
                        r = set_put_strdup(&c->log_filter_denied_patterns, val);
5✔
3138
                        if (r < 0)
5✔
3139
                                return r;
3140
                } else if ((val = startswith(l, "exec-context-log-extra-fields="))) {
915,298✔
3141
                        if (!GREEDY_REALLOC(c->log_extra_fields, c->n_log_extra_fields + 1))
661✔
3142
                                return log_oom_debug();
×
3143

3144
                        c->log_extra_fields[c->n_log_extra_fields++].iov_base = strdup(val);
661✔
3145
                        if (!c->log_extra_fields[c->n_log_extra_fields-1].iov_base)
661✔
3146
                                return log_oom_debug();
×
3147
                } else if ((val = startswith(l, "exec-context-log-namespace="))) {
914,637✔
3148
                        r = free_and_strdup(&c->log_namespace, val);
2✔
3149
                        if (r < 0)
2✔
3150
                                return r;
3151
                } else if ((val = startswith(l, "exec-context-secure-bits="))) {
914,635✔
3152
                        r = safe_atoi(val, &c->secure_bits);
×
3153
                        if (r < 0)
×
3154
                                return r;
3155
                } else if ((val = startswith(l, "exec-context-capability-bounding-set="))) {
914,635✔
3156
                        r = safe_atou64(val, &c->capability_bounding_set);
2,305✔
3157
                        if (r < 0)
2,305✔
3158
                                return r;
3159
                } else if ((val = startswith(l, "exec-context-capability-ambient-set="))) {
912,330✔
3160
                        r = safe_atou64(val, &c->capability_ambient_set);
1,230✔
3161
                        if (r < 0)
1,230✔
3162
                                return r;
3163
                } else if ((val = startswith(l, "exec-context-user="))) {
911,100✔
3164
                        r = free_and_strdup(&c->user, val);
2,613✔
3165
                        if (r < 0)
2,613✔
3166
                                return r;
3167
                } else if ((val = startswith(l, "exec-context-group="))) {
908,487✔
3168
                        r = free_and_strdup(&c->group, val);
73✔
3169
                        if (r < 0)
73✔
3170
                                return r;
3171
                } else if ((val = startswith(l, "exec-context-dynamic-user="))) {
908,414✔
3172
                        r = parse_boolean(val);
62✔
3173
                        if (r < 0)
62✔
3174
                                return r;
3175
                        c->dynamic_user = r;
62✔
3176
                } else if ((val = startswith(l, "exec-context-supplementary-groups="))) {
908,352✔
3177
                        r = deserialize_strv(val, &c->supplementary_groups);
9✔
3178
                        if (r < 0)
9✔
3179
                                return r;
3180
                } else if ((val = startswith(l, "exec-context-set-login-environment="))) {
908,343✔
3181
                        r = safe_atoi(val, &c->set_login_environment);
×
3182
                        if (r < 0)
×
3183
                                return r;
3184
                } else if ((val = startswith(l, "exec-context-pam-name="))) {
908,343✔
3185
                        r = free_and_strdup(&c->pam_name, val);
474✔
3186
                        if (r < 0)
474✔
3187
                                return r;
3188
                } else if ((val = startswith(l, "exec-context-read-write-paths="))) {
907,869✔
3189
                        r = deserialize_strv(val, &c->read_write_paths);
811✔
3190
                        if (r < 0)
811✔
3191
                                return r;
3192
                } else if ((val = startswith(l, "exec-context-read-only-paths="))) {
907,058✔
3193
                        r = deserialize_strv(val, &c->read_only_paths);
2✔
3194
                        if (r < 0)
2✔
3195
                                return r;
3196
                } else if ((val = startswith(l, "exec-context-inaccessible-paths="))) {
907,056✔
3197
                        r = deserialize_strv(val, &c->inaccessible_paths);
5✔
3198
                        if (r < 0)
5✔
3199
                                return r;
3200
                } else if ((val = startswith(l, "exec-context-exec-paths="))) {
907,051✔
3201
                        r = deserialize_strv(val, &c->exec_paths);
1✔
3202
                        if (r < 0)
1✔
3203
                                return r;
3204
                } else if ((val = startswith(l, "exec-context-no-exec-paths="))) {
907,050✔
3205
                        r = deserialize_strv(val, &c->no_exec_paths);
1✔
3206
                        if (r < 0)
1✔
3207
                                return r;
3208
                } else if ((val = startswith(l, "exec-context-exec-search-path="))) {
907,049✔
3209
                        r = deserialize_strv(val, &c->exec_search_path);
×
3210
                        if (r < 0)
×
3211
                                return r;
3212
                } else if ((val = startswith(l, "exec-context-mount-propagation-flag="))) {
907,049✔
3213
                        r = safe_atolu(val, &c->mount_propagation_flag);
11,925✔
3214
                        if (r < 0)
11,925✔
3215
                                return r;
3216
                } else if ((val = startswith(l, "exec-context-bind-read-only-path="))) {
895,124✔
3217
                        _cleanup_free_ char *source = NULL, *destination = NULL;
7✔
3218
                        bool rbind = true, ignore_enoent = false;
7✔
3219
                        char *s = NULL, *d = NULL;
7✔
3220

3221
                        r = extract_first_word(&val,
7✔
3222
                                               &source,
3223
                                               ":" WHITESPACE,
3224
                                               EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3225
                        if (r < 0)
7✔
3226
                                return r;
3227
                        if (r == 0)
7✔
3228
                                return -EINVAL;
3229

3230
                        s = source;
7✔
3231
                        if (s[0] == '-') {
7✔
3232
                                ignore_enoent = true;
1✔
3233
                                s++;
1✔
3234
                        }
3235

3236
                        if (val && val[-1] == ':') {
7✔
3237
                                r = extract_first_word(&val,
7✔
3238
                                                       &destination,
3239
                                                       ":" WHITESPACE,
3240
                                                       EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3241
                                if (r < 0)
7✔
3242
                                        return r;
3243
                                if (r == 0)
7✔
3244
                                        continue;
×
3245

3246
                                d = destination;
7✔
3247

3248
                                if (val && val[-1] == ':') {
7✔
3249
                                        _cleanup_free_ char *options = NULL;
7✔
3250

3251
                                        r = extract_first_word(&val, &options, NULL, EXTRACT_UNQUOTE);
7✔
3252
                                        if (r < 0)
7✔
3253
                                                return -r;
×
3254

3255
                                        if (isempty(options) || streq(options, "rbind"))
15✔
3256
                                                rbind = true;
3257
                                        else if (streq(options, "norbind"))
1✔
3258
                                                rbind = false;
3259
                                        else
3260
                                                continue;
×
3261
                                }
3262
                        } else
3263
                                d = s;
3264

3265
                        r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts,
14✔
3266
                                        &(BindMount) {
7✔
3267
                                                .source = s,
3268
                                                .destination = d,
3269
                                                .read_only = true,
3270
                                                .recursive = rbind,
3271
                                                .ignore_enoent = ignore_enoent,
3272
                                        });
3273
                        if (r < 0)
7✔
3274
                                return log_oom_debug();
×
3275
                } else if ((val = startswith(l, "exec-context-bind-path="))) {
895,117✔
3276
                        _cleanup_free_ char *source = NULL, *destination = NULL;
20✔
3277
                        bool rbind = true, ignore_enoent = false;
20✔
3278
                        char *s = NULL, *d = NULL;
20✔
3279

3280
                        r = extract_first_word(&val,
20✔
3281
                                               &source,
3282
                                               ":" WHITESPACE,
3283
                                               EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3284
                        if (r < 0)
20✔
3285
                                return r;
3286
                        if (r == 0)
20✔
3287
                                return -EINVAL;
3288

3289
                        s = source;
20✔
3290
                        if (s[0] == '-') {
20✔
3291
                                ignore_enoent = true;
1✔
3292
                                s++;
1✔
3293
                        }
3294

3295
                        if (val && val[-1] == ':') {
20✔
3296
                                r = extract_first_word(&val,
20✔
3297
                                                       &destination,
3298
                                                       ":" WHITESPACE,
3299
                                                       EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3300
                                if (r < 0)
20✔
3301
                                        return r;
3302
                                if (r == 0)
20✔
3303
                                        continue;
×
3304

3305
                                d = destination;
20✔
3306

3307
                                if (val && val[-1] == ':') {
20✔
3308
                                        _cleanup_free_ char *options = NULL;
20✔
3309

3310
                                        r = extract_first_word(&val, &options, NULL, EXTRACT_UNQUOTE);
20✔
3311
                                        if (r < 0)
20✔
3312
                                                return -r;
×
3313

3314
                                        if (isempty(options) || streq(options, "rbind"))
43✔
3315
                                                rbind = true;
3316
                                        else if (streq(options, "norbind"))
3✔
3317
                                                rbind = false;
3318
                                        else
3319
                                                continue;
×
3320
                                }
3321
                        } else
3322
                                d = s;
3323

3324
                        r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts,
40✔
3325
                                        &(BindMount) {
20✔
3326
                                                .source = s,
3327
                                                .destination = d,
3328
                                                .read_only = false,
3329
                                                .recursive = rbind,
3330
                                                .ignore_enoent = ignore_enoent,
3331
                                        });
3332
                        if (r < 0)
20✔
3333
                                return log_oom_debug();
×
3334
                } else if ((val = startswith(l, "exec-context-temporary-filesystems="))) {
895,097✔
3335
                        _cleanup_free_ char *path = NULL, *options = NULL;
61✔
3336

3337
                        r = extract_many_words(&val, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &path, &options);
61✔
3338
                        if (r < 0)
61✔
3339
                                return r;
3340
                        if (r < 1)
61✔
3341
                                continue;
×
3342

3343
                        r = temporary_filesystem_add(&c->temporary_filesystems, &c->n_temporary_filesystems, path, options);
61✔
3344
                        if (r < 0)
61✔
3345
                                return log_oom_debug();
×
3346
                } else if ((val = startswith(l, "exec-context-utmp-id="))) {
895,036✔
3347
                        r = free_and_strdup(&c->utmp_id, val);
161✔
3348
                        if (r < 0)
161✔
3349
                                return r;
3350
                } else if ((val = startswith(l, "exec-context-utmp-mode="))) {
894,875✔
3351
                        c->utmp_mode = exec_utmp_mode_from_string(val);
11,925✔
3352
                        if (c->utmp_mode < 0)
11,925✔
3353
                                return c->utmp_mode;
3354
                } else if ((val = startswith(l, "exec-context-no-new-privileges="))) {
882,950✔
3355
                        r = parse_boolean(val);
2,117✔
3356
                        if (r < 0)
2,117✔
3357
                                return r;
3358
                        c->no_new_privileges = r;
2,117✔
3359
                } else if ((val = startswith(l, "exec-context-selinux-context="))) {
880,833✔
3360
                        if (val[0] == '-') {
×
3361
                                c->selinux_context_ignore = true;
×
3362
                                val++;
×
3363
                        } else
3364
                                c->selinux_context_ignore = false;
×
3365

3366
                        r = free_and_strdup(&c->selinux_context, val);
×
3367
                        if (r < 0)
×
3368
                                return r;
3369
                } else if ((val = startswith(l, "exec-context-apparmor-profile="))) {
880,833✔
3370
                        if (val[0] == '-') {
×
3371
                                c->apparmor_profile_ignore = true;
×
3372
                                val++;
×
3373
                        } else
3374
                                c->apparmor_profile_ignore = false;
×
3375

3376
                        r = free_and_strdup(&c->apparmor_profile, val);
×
3377
                        if (r < 0)
×
3378
                                return r;
3379
                } else if ((val = startswith(l, "exec-context-smack-process-label="))) {
880,833✔
3380
                        if (val[0] == '-') {
×
3381
                                c->smack_process_label_ignore = true;
×
3382
                                val++;
×
3383
                        } else
3384
                                c->smack_process_label_ignore = false;
×
3385

3386
                        r = free_and_strdup(&c->smack_process_label, val);
×
3387
                        if (r < 0)
×
3388
                                return r;
3389
                } else if ((val = startswith(l, "exec-context-personality="))) {
880,833✔
3390
                        c->personality = personality_from_string(val);
×
3391
                        if (c->personality == PERSONALITY_INVALID)
×
3392
                                return -EINVAL;
3393
                } else if ((val = startswith(l, "exec-context-lock-personality="))) {
880,833✔
3394
                        r = parse_boolean(val);
2,176✔
3395
                        if (r < 0)
2,176✔
3396
                                return r;
3397
                        c->lock_personality = r;
2,176✔
3398
#if HAVE_SECCOMP
3399
                } else if ((val = startswith(l, "exec-context-syscall-filter="))) {
878,657✔
3400
                        _cleanup_free_ char *s_id = NULL, *s_errno_num = NULL;
841,064✔
3401
                        int id, errno_num;
841,064✔
3402

3403
                        r = extract_many_words(&val, NULL, 0, &s_id, &s_errno_num);
841,064✔
3404
                        if (r < 0)
841,064✔
3405
                                return r;
3406
                        if (r != 2)
841,064✔
3407
                                continue;
×
3408

3409
                        r = safe_atoi(s_id, &id);
841,064✔
3410
                        if (r < 0)
841,064✔
3411
                                return r;
3412

3413
                        r = safe_atoi(s_errno_num, &errno_num);
841,064✔
3414
                        if (r < 0)
841,064✔
3415
                                return r;
3416

3417
                        r = hashmap_ensure_put(&c->syscall_filter, NULL, INT_TO_PTR(id + 1), INT_TO_PTR(errno_num));
841,064✔
3418
                        if (r < 0)
841,064✔
3419
                                return r;
3420
                } else if ((val = startswith(l, "exec-context-syscall-archs="))) {
37,593✔
3421
                        unsigned id;
2,172✔
3422

3423
                        r = safe_atou(val, &id);
2,172✔
3424
                        if (r < 0)
2,172✔
3425
                                return r;
×
3426

3427
                        r = set_ensure_put(&c->syscall_archs, NULL, UINT_TO_PTR(id + 1));
2,172✔
3428
                        if (r < 0)
2,172✔
3429
                                return r;
3430
                } else if ((val = startswith(l, "exec-context-syscall-errno="))) {
35,421✔
3431
                        r = safe_atoi(val, &c->syscall_errno);
11,925✔
3432
                        if (r < 0)
11,925✔
3433
                                return r;
3434
                } else if ((val = startswith(l, "exec-context-syscall-allow-list="))) {
23,496✔
3435
                        r = parse_boolean(val);
2,156✔
3436
                        if (r < 0)
2,156✔
3437
                                return r;
3438
                        c->syscall_allow_list = r;
2,156✔
3439
                } else if ((val = startswith(l, "exec-context-syscall-log="))) {
21,340✔
3440
                        _cleanup_free_ char *s_id = NULL, *s_errno_num = NULL;
×
3441
                        int id, errno_num;
×
3442

3443
                        r = extract_many_words(&val, " ", 0, &s_id, &s_errno_num);
×
3444
                        if (r < 0)
×
3445
                                return r;
3446
                        if (r != 2)
×
3447
                                continue;
×
3448

3449
                        r = safe_atoi(s_id, &id);
×
3450
                        if (r < 0)
×
3451
                                return r;
3452

3453
                        r = safe_atoi(s_errno_num, &errno_num);
×
3454
                        if (r < 0)
×
3455
                                return r;
3456

3457
                        r = hashmap_ensure_put(&c->syscall_log, NULL, INT_TO_PTR(id + 1), INT_TO_PTR(errno_num));
×
3458
                        if (r < 0)
×
3459
                                return r;
3460
                } else if ((val = startswith(l, "exec-context-syscall-log-allow-list="))) {
21,340✔
3461
                        r = parse_boolean(val);
×
3462
                        if (r < 0)
×
3463
                                return r;
3464
                        c->syscall_log_allow_list = r;
×
3465
#endif
3466
                } else if ((val = startswith(l, "exec-context-restrict-namespaces="))) {
21,340✔
3467
                        r = safe_atolu(val, &c->restrict_namespaces);
1,917✔
3468
                        if (r < 0)
1,917✔
3469
                                return r;
3470
                } else if ((val = startswith(l, "exec-context-delegate-namespaces="))) {
19,423✔
3471
                        r = safe_atolu(val, &c->delegate_namespaces);
20✔
3472
                        if (r < 0)
20✔
3473
                                return r;
3474
                } else if ((val = startswith(l, "exec-context-restrict-filesystems="))) {
19,403✔
3475
                        r = set_put_strdup(&c->restrict_filesystems, val);
×
3476
                        if (r < 0)
×
3477
                                return r;
3478
                } else if ((val = startswith(l, "exec-context-restrict-filesystems-allow-list="))) {
19,403✔
3479
                        r = parse_boolean(val);
×
3480
                        if (r < 0)
×
3481
                                return r;
3482
                        c->restrict_filesystems_allow_list = r;
×
3483
                } else if ((val = startswith(l, "exec-context-address-families="))) {
19,403✔
3484
                        int af;
9,167✔
3485

3486
                        r = safe_atoi(val, &af);
9,167✔
3487
                        if (r < 0)
9,167✔
3488
                                return r;
×
3489

3490
                        r = set_ensure_put(&c->address_families, NULL, INT_TO_PTR(af));
9,167✔
3491
                        if (r < 0)
9,167✔
3492
                                return r;
3493
                } else if ((val = startswith(l, "exec-context-address-families-allow-list="))) {
10,236✔
3494
                        r = parse_boolean(val);
2,171✔
3495
                        if (r < 0)
2,171✔
3496
                                return r;
3497
                        c->address_families_allow_list = r;
2,171✔
3498
                } else if ((val = startswith(l, "exec-context-network-namespace-path="))) {
8,065✔
3499
                        r = free_and_strdup(&c->network_namespace_path, val);
×
3500
                        if (r < 0)
×
3501
                                return r;
3502
                } else if ((val = startswith(l, "exec-context-ipc-namespace-path="))) {
8,065✔
3503
                        r = free_and_strdup(&c->ipc_namespace_path, val);
×
3504
                        if (r < 0)
×
3505
                                return r;
3506
                } else if ((val = startswith(l, "exec-context-mount-image="))) {
8,065✔
3507
                        _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
×
3508
                        _cleanup_free_ char *source = NULL, *destination = NULL;
48✔
3509
                        bool permissive = false;
48✔
3510
                        char *s;
48✔
3511

3512
                        r = extract_many_words(&val,
48✔
3513
                                               NULL,
3514
                                               EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS,
3515
                                               &source,
3516
                                               &destination);
3517
                        if (r < 0)
48✔
3518
                                return r;
3519
                        if (r == 0)
48✔
3520
                                return -EINVAL;
3521

3522
                        s = source;
48✔
3523
                        if (s[0] == '-') {
48✔
3524
                                permissive = true;
×
3525
                                s++;
×
3526
                        }
3527

3528
                        if (isempty(destination))
48✔
3529
                                continue;
×
3530

3531
                        for (;;) {
53✔
3532
                                _cleanup_free_ char *tuple = NULL, *partition = NULL, *opts = NULL;
5✔
3533
                                PartitionDesignator partition_designator;
53✔
3534
                                MountOptions *o = NULL;
53✔
3535
                                const char *p;
53✔
3536

3537
                                r = extract_first_word(&val, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
53✔
3538
                                if (r < 0)
53✔
3539
                                        return r;
3540
                                if (r == 0)
53✔
3541
                                        break;
3542

3543
                                p = tuple;
5✔
3544
                                r = extract_many_words(&p,
5✔
3545
                                                       ":",
3546
                                                       EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS,
3547
                                                       &partition,
3548
                                                       &opts);
3549
                                if (r < 0)
5✔
3550
                                        return r;
3551
                                if (r == 0)
5✔
3552
                                        continue;
×
3553
                                if (r == 1) {
5✔
3554
                                        o = new(MountOptions, 1);
×
3555
                                        if (!o)
×
3556
                                                return log_oom_debug();
×
3557
                                        *o = (MountOptions) {
×
3558
                                                .partition_designator = PARTITION_ROOT,
3559
                                                .options = TAKE_PTR(partition),
×
3560
                                        };
3561
                                        LIST_APPEND(mount_options, options, o);
×
3562

3563
                                        continue;
×
3564
                                }
3565

3566
                                partition_designator = partition_designator_from_string(partition);
5✔
3567
                                if (partition_designator < 0)
5✔
3568
                                        continue;
×
3569

3570
                                o = new(MountOptions, 1);
5✔
3571
                                if (!o)
5✔
3572
                                        return log_oom_debug();
×
3573
                                *o = (MountOptions) {
5✔
3574
                                        .partition_designator = partition_designator,
3575
                                        .options = TAKE_PTR(opts),
5✔
3576
                                };
3577
                                LIST_APPEND(mount_options, options, o);
5✔
3578
                        }
3579

3580
                        r = mount_image_add(&c->mount_images, &c->n_mount_images,
96✔
3581
                                        &(MountImage) {
48✔
3582
                                                .source = s,
3583
                                                .destination = destination,
3584
                                                .mount_options = options,
3585
                                                .ignore_enoent = permissive,
3586
                                                .type = MOUNT_IMAGE_DISCRETE,
3587
                                        });
3588
                        if (r < 0)
48✔
3589
                                return log_oom_debug();
×
3590
                } else if ((val = startswith(l, "exec-context-extension-image="))) {
8,017✔
3591
                        _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
×
3592
                        _cleanup_free_ char *source = NULL;
9✔
3593
                        bool permissive = false;
9✔
3594
                        char *s;
9✔
3595

3596
                        r = extract_first_word(&val,
9✔
3597
                                               &source,
3598
                                               NULL,
3599
                                               EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS);
3600
                        if (r < 0)
9✔
3601
                                return r;
3602
                        if (r == 0)
9✔
3603
                                return -EINVAL;
3604

3605
                        s = source;
9✔
3606
                        if (s[0] == '-') {
9✔
3607
                                permissive = true;
3✔
3608
                                s++;
3✔
3609
                        }
3610

3611
                        for (;;) {
9✔
3612
                                _cleanup_free_ char *tuple = NULL, *partition = NULL, *opts = NULL;
×
3613
                                PartitionDesignator partition_designator;
9✔
3614
                                MountOptions *o = NULL;
9✔
3615
                                const char *p;
9✔
3616

3617
                                r = extract_first_word(&val, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
9✔
3618
                                if (r < 0)
9✔
3619
                                        return r;
3620
                                if (r == 0)
9✔
3621
                                        break;
3622

3623
                                p = tuple;
×
3624
                                r = extract_many_words(&p,
×
3625
                                                       ":",
3626
                                                       EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS,
3627
                                                       &partition,
3628
                                                       &opts);
3629
                                if (r < 0)
×
3630
                                        return r;
3631
                                if (r == 0)
×
3632
                                        continue;
×
3633
                                if (r == 1) {
×
3634
                                        o = new(MountOptions, 1);
×
3635
                                        if (!o)
×
3636
                                                return log_oom_debug();
×
3637
                                        *o = (MountOptions) {
×
3638
                                                .partition_designator = PARTITION_ROOT,
3639
                                                .options = TAKE_PTR(partition),
×
3640
                                        };
3641
                                        LIST_APPEND(mount_options, options, o);
×
3642

3643
                                        continue;
×
3644
                                }
3645

3646
                                partition_designator = partition_designator_from_string(partition);
×
3647
                                if (partition_designator < 0)
×
3648
                                        continue;
×
3649

3650
                                o = new(MountOptions, 1);
×
3651
                                if (!o)
×
3652
                                        return log_oom_debug();
×
3653
                                *o = (MountOptions) {
×
3654
                                        .partition_designator = partition_designator,
3655
                                        .options = TAKE_PTR(opts),
×
3656
                                };
3657
                                LIST_APPEND(mount_options, options, o);
×
3658
                        }
3659

3660
                        r = mount_image_add(&c->extension_images, &c->n_extension_images,
18✔
3661
                                        &(MountImage) {
9✔
3662
                                                .source = s,
3663
                                                .mount_options = options,
3664
                                                .ignore_enoent = permissive,
3665
                                                .type = MOUNT_IMAGE_EXTENSION,
3666
                                        });
3667
                        if (r < 0)
9✔
3668
                                return log_oom_debug();
×
3669
                } else if ((val = startswith(l, "exec-context-extension-directories="))) {
8,008✔
3670
                        r = deserialize_strv(val, &c->extension_directories);
8✔
3671
                        if (r < 0)
8✔
3672
                                return r;
3673
                } else if ((val = startswith(l, "exec-context-set-credentials="))) {
8,000✔
3674
                        _cleanup_free_ char *id = NULL, *data = NULL, *encrypted = NULL;
×
3675

3676
                        r = extract_many_words(&val, " ", EXTRACT_DONT_COALESCE_SEPARATORS, &id, &data, &encrypted);
186✔
3677
                        if (r < 0)
186✔
3678
                                return r;
3679
                        if (r != 3)
186✔
3680
                                return -EINVAL;
3681

3682
                        r = parse_boolean(encrypted);
186✔
3683
                        if (r < 0)
186✔
3684
                                return r;
3685
                        bool e = r;
186✔
3686

3687
                        _cleanup_free_ void *d = NULL;
186✔
3688
                        size_t size;
186✔
3689

3690
                        r = unbase64mem_full(data, SIZE_MAX, /* secure = */ true, &d, &size);
186✔
3691
                        if (r < 0)
186✔
3692
                                return r;
3693

3694
                        r = exec_context_put_set_credential(c, id, TAKE_PTR(d), size, e);
186✔
3695
                        if (r < 0)
186✔
3696
                                return r;
3697
                } else if ((val = startswith(l, "exec-context-load-credentials="))) {
7,814✔
3698
                        _cleanup_free_ char *id = NULL, *path = NULL, *encrypted = NULL;
61✔
3699

3700
                        r = extract_many_words(&val, " ", EXTRACT_DONT_COALESCE_SEPARATORS, &id, &path, &encrypted);
61✔
3701
                        if (r < 0)
61✔
3702
                                return r;
3703
                        if (r != 3)
61✔
3704
                                return -EINVAL;
3705

3706
                        r = parse_boolean(encrypted);
61✔
3707
                        if (r < 0)
61✔
3708
                                return r;
3709

3710
                        r = exec_context_put_load_credential(c, id, path, r > 0);
61✔
3711
                        if (r < 0)
61✔
3712
                                return r;
3713
                } else if ((val = startswith(l, "exec-context-import-credentials="))) {
7,753✔
3714
                        _cleanup_free_ char *glob = NULL, *rename = NULL;
7,749✔
3715

3716
                        r = extract_many_words(&val, " ", EXTRACT_DONT_COALESCE_SEPARATORS, &glob, &rename);
7,749✔
3717
                        if (r < 0)
7,749✔
3718
                                return r;
3719
                        if (r == 0)
7,749✔
3720
                                return -EINVAL;
3721

3722
                        r = exec_context_put_import_credential(c, glob, rename);
7,749✔
3723
                        if (r < 0)
7,749✔
3724
                                return r;
3725
                } else if ((val = startswith(l, "exec-context-root-image-policy="))) {
4✔
3726
                        if (c->root_image_policy)
4✔
3727
                                return -EINVAL; /* duplicated */
3728

3729
                        r = image_policy_from_string(val, &c->root_image_policy);
4✔
3730
                        if (r < 0)
4✔
3731
                                return r;
3732
                } else if ((val = startswith(l, "exec-context-mount-image-policy="))) {
×
3733
                        if (c->mount_image_policy)
×
3734
                                return -EINVAL; /* duplicated */
3735

3736
                        r = image_policy_from_string(val, &c->mount_image_policy);
×
3737
                        if (r < 0)
×
3738
                                return r;
3739
                } else if ((val = startswith(l, "exec-context-extension-image-policy="))) {
×
3740
                        if (c->extension_image_policy)
×
3741
                                return -EINVAL; /* duplicated */
3742

3743
                        r = image_policy_from_string(val, &c->extension_image_policy);
×
3744
                        if (r < 0)
×
3745
                                return r;
3746
                } else
3747
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
3748
        }
3749

3750
        return 0;
11,925✔
3751
}
3752

3753
static int exec_command_serialize(const ExecCommand *c, FILE *f) {
2,310✔
3754
        int r;
2,310✔
3755

3756
        assert(c);
2,310✔
3757
        assert(f);
2,310✔
3758

3759
        r = serialize_item(f, "exec-command-path", c->path);
2,310✔
3760
        if (r < 0)
2,310✔
3761
                return r;
3762

3763
        r = serialize_strv(f, "exec-command-argv", c->argv);
2,310✔
3764
        if (r < 0)
2,310✔
3765
                return r;
3766

3767
        r = serialize_item_format(f, "exec-command-flags", "%d", (int) c->flags);
2,310✔
3768
        if (r < 0)
2,310✔
3769
                return r;
3770

3771
        fputc('\n', f); /* End marker */
2,310✔
3772

3773
        return 0;
2,310✔
3774
}
3775

3776
static int exec_command_deserialize(ExecCommand *c, FILE *f) {
11,925✔
3777
        int r;
11,925✔
3778

3779
        assert(c);
11,925✔
3780
        assert(f);
11,925✔
3781

3782
        for (;;) {
127,783✔
3783
                _cleanup_free_ char *l = NULL;
57,929✔
3784
                const char *val;
69,854✔
3785

3786
                r = deserialize_read_line(f, &l);
69,854✔
3787
                if (r < 0)
69,854✔
3788
                        return r;
3789
                if (r == 0) /* eof or end marker */
69,854✔
3790
                        break;
3791

3792
                if ((val = startswith(l, "exec-command-path="))) {
57,929✔
3793
                        r = free_and_strdup(&c->path, val);
11,925✔
3794
                        if (r < 0)
11,925✔
3795
                                return r;
3796
                } else if ((val = startswith(l, "exec-command-argv="))) {
46,004✔
3797
                        r = deserialize_strv(val, &c->argv);
34,079✔
3798
                        if (r < 0)
34,079✔
3799
                                return r;
3800
                } else if ((val = startswith(l, "exec-command-flags="))) {
11,925✔
3801
                        r = safe_atoi(val, &c->flags);
11,925✔
3802
                        if (r < 0)
11,925✔
3803
                                return r;
3804
                } else
3805
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
3806

3807
        }
3808

3809
        return 0;
11,925✔
3810
}
3811

3812
int exec_serialize_invocation(
2,310✔
3813
                FILE *f,
3814
                FDSet *fds,
3815
                const ExecContext *ctx,
3816
                const ExecCommand *cmd,
3817
                const ExecParameters *p,
3818
                const ExecRuntime *rt,
3819
                const CGroupContext *cg) {
3820

3821
        int r;
2,310✔
3822

3823
        assert(f);
2,310✔
3824
        assert(fds);
2,310✔
3825

3826
        r = exec_context_serialize(ctx, f);
2,310✔
3827
        if (r < 0)
2,310✔
3828
                return log_debug_errno(r, "Failed to serialize context: %m");
×
3829

3830
        r = exec_command_serialize(cmd, f);
2,310✔
3831
        if (r < 0)
2,310✔
3832
                return log_debug_errno(r, "Failed to serialize command: %m");
×
3833

3834
        r = exec_parameters_serialize(p, ctx, f, fds);
2,310✔
3835
        if (r < 0)
2,310✔
3836
                return log_debug_errno(r, "Failed to serialize parameters: %m");
×
3837

3838
        r = exec_runtime_serialize(rt, f, fds);
2,310✔
3839
        if (r < 0)
2,310✔
3840
                return log_debug_errno(r, "Failed to serialize runtime: %m");
×
3841

3842
        r = exec_cgroup_context_serialize(cg, f);
2,310✔
3843
        if (r < 0)
2,310✔
3844
                return log_debug_errno(r, "Failed to serialize cgroup context: %m");
×
3845

3846
        return 0;
3847
}
3848

3849
int exec_deserialize_invocation(
11,925✔
3850
                FILE *f,
3851
                FDSet *fds,
3852
                ExecContext *ctx,
3853
                ExecCommand *cmd,
3854
                ExecParameters *p,
3855
                ExecRuntime *rt,
3856
                CGroupContext *cg) {
3857

3858
        int r;
11,925✔
3859

3860
        assert(f);
11,925✔
3861
        assert(fds);
11,925✔
3862

3863
        r = exec_context_deserialize(ctx, f);
11,925✔
3864
        if (r < 0)
11,925✔
3865
                return log_debug_errno(r, "Failed to deserialize context: %m");
×
3866

3867
        r = exec_command_deserialize(cmd, f);
11,925✔
3868
        if (r < 0)
11,925✔
3869
                return log_debug_errno(r, "Failed to deserialize command: %m");
×
3870

3871
        r = exec_parameters_deserialize(p, f, fds);
11,925✔
3872
        if (r < 0)
11,925✔
3873
                return log_debug_errno(r, "Failed to deserialize parameters: %m");
×
3874

3875
        r = exec_runtime_deserialize(rt, f, fds);
11,925✔
3876
        if (r < 0)
11,925✔
3877
                return log_debug_errno(r, "Failed to deserialize runtime: %m");
×
3878

3879
        r = exec_cgroup_context_deserialize(cg, f);
11,925✔
3880
        if (r < 0)
11,925✔
3881
                return log_debug_errno(r, "Failed to deserialize cgroup context: %m");
×
3882

3883
        return 0;
3884
}
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