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

systemd / systemd / 18988181302

31 Oct 2025 09:30PM UTC coverage: 72.241% (+0.2%) from 72.046%
18988181302

push

github

web-flow
core: Add RootDirectoryFileDescriptor= (#39480)

RootDirectory= but via a open_tree() file descriptor. This allows
setting up the execution environment for a service by the client in a
mount namespace and then starting a transient unit in that execution
environment using the new property.

We also add --root-directory= and --same-root-dir= to systemd-run to
have it run services within the given root directory. As systemd-run
might be invoked from a different mount namespace than what systemd is
running in, systemd-run opens the given path with open_tree() and then
sends it to systemd using the new RootDirectoryFileDescriptor= property.

45 of 76 new or added lines in 8 files covered. (59.21%)

2101 existing lines in 44 files now uncovered.

305020 of 422226 relevant lines covered (72.24%)

1081585.12 hits per line

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

70.84
/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,123✔
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,123✔
38
        char *iface;
2,123✔
39
        struct in_addr_prefix *iaai;
2,123✔
40
        int r;
2,123✔
41

42
        assert(f);
2,123✔
43

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

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

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

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

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

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

67
        if (c->cpu_weight != CGROUP_WEIGHT_INVALID) {
2,123✔
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,123✔
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,123✔
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,123✔
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,123✔
92
        if (!cpuset_cpus)
2,123✔
93
                return log_oom_debug();
×
94

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

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

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

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

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

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

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

123
        if (c->io_weight != CGROUP_WEIGHT_INVALID) {
2,123✔
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,123✔
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,123✔
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,123✔
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,123✔
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,123✔
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,123✔
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,123✔
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,123✔
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,123✔
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,123✔
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,123✔
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,123✔
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,123✔
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,123✔
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,123✔
214
        if (r < 0)
2,123✔
215
                return r;
216

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

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

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

233
        r = serialize_bool_elide(f, "exec-cgroup-context-default-memory-low-set", c->default_memory_low_set);
2,123✔
234
        if (r < 0)
2,123✔
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,123✔
238
        if (r < 0)
2,123✔
239
                return r;
240

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

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

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

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

257
        r = serialize_bool_elide(f, "exec-cgroup-context-startup-memory-max-set", c->startup_memory_max_set);
2,123✔
258
        if (r < 0)
2,123✔
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,123✔
262
        if (r < 0)
2,123✔
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,123✔
266
        if (r < 0)
2,123✔
267
                return r;
268

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

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

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

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

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

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

293
        r = serialize_item(f, "exec-cgroup-context-managed-oom-swap", managed_oom_mode_to_string(c->moom_swap));
2,123✔
294
        if (r < 0)
2,123✔
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,123✔
298
        if (r < 0)
2,123✔
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,123✔
302
        if (r < 0)
2,123✔
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,123✔
306
        if (r < 0)
2,123✔
307
                return r;
308

309
        r = serialize_item(f, "exec-cgroup-context-managed-oom-preference", managed_oom_preference_to_string(c->moom_preference));
2,123✔
310
        if (r < 0)
2,123✔
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,123✔
314
        if (r < 0)
2,123✔
315
                return r;
316

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

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

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

335
        LIST_FOREACH(device_weights, iw, c->io_device_weights) {
2,123✔
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,123✔
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,123✔
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,123✔
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,375✔
375
                r = serialize_item(f,
252✔
376
                                   "exec-cgroup-context-ip-address-deny",
377
                                   IN_ADDR_PREFIX_TO_STRING(iaai->family, &iaai->address, iaai->prefixlen));
252✔
378
                if (r < 0)
252✔
379
                        return r;
×
380
        }
381

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

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

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

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

398
        LIST_FOREACH(programs, p, c->bpf_foreign_programs) {
2,123✔
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,123✔
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,123✔
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,123✔
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,246✔
425
                        f,
426
                        "exec-cgroup-context-restrict-network-interfaces-is-allow-list",
427
                        c->restrict_network_interfaces_is_allow_list);
2,123✔
428
        if (r < 0)
2,123✔
429
                return r;
430

431
        fputc('\n', f); /* End marker */
2,123✔
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,813✔
445
                _cleanup_free_ char *l = NULL;
217,444✔
446
                const char *val;
229,369✔
447

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

454
                if ((val = startswith(l, "exec-cgroup-context-io-accounting="))) {
217,444✔
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,442✔
460
                        r = parse_boolean(val);
11,603✔
461
                        if (r < 0)
11,603✔
462
                                return r;
463
                        c->memory_accounting = r;
11,603✔
464
                } else if ((val = startswith(l, "exec-cgroup-context-tasks-accounting="))) {
205,839✔
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,914✔
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,914✔
475
                        r = parse_boolean(val);
2✔
476
                        if (r < 0)
2✔
477
                                return r;
478
                        c->memory_oom_group = r;
2✔
479
                } else if ((val = startswith(l, "exec-cgroup-context-cpu-weight="))) {
193,912✔
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,911✔
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,911✔
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,911✔
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,911✔
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,986✔
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="))) {
170,061✔
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="))) {
158,136✔
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="))) {
146,211✔
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="))) {
146,211✔
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="))) {
146,211✔
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="))) {
146,211✔
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="))) {
146,211✔
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="))) {
146,210✔
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="))) {
146,209✔
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="))) {
146,209✔
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="))) {
146,199✔
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="))) {
146,199✔
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="))) {
146,197✔
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="))) {
146,197✔
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="))) {
146,196✔
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="))) {
146,196✔
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="))) {
146,195✔
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="))) {
146,195✔
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="))) {
134,270✔
589
                        r = safe_atou64(val, &c->tasks_max.value);
11,625✔
590
                        if (r < 0)
11,625✔
591
                                return r;
592
                } else if ((val = startswith(l, "exec-cgroup-context-tasks-max-scale="))) {
122,645✔
593
                        r = safe_atou64(val, &c->tasks_max.scale);
11,584✔
594
                        if (r < 0)
11,584✔
595
                                return r;
596
                } else if ((val = startswith(l, "exec-cgroup-context-default-memory-min-set="))) {
111,061✔
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="))) {
111,061✔
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="))) {
111,061✔
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="))) {
111,061✔
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="))) {
111,060✔
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="))) {
111,059✔
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="))) {
111,059✔
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="))) {
111,059✔
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="))) {
111,059✔
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="))) {
111,059✔
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="))) {
111,059✔
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="))) {
99,134✔
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="))) {
99,134✔
655
                        r = cg_mask_from_string(val, &c->delegate_controllers);
581✔
656
                        if (r < 0)
581✔
657
                                return r;
658
                } else if ((val = startswith(l, "exec-cgroup-context-delegate="))) {
98,553✔
659
                        r = parse_boolean(val);
694✔
660
                        if (r < 0)
694✔
661
                                return r;
662
                        c->delegate = r;
694✔
663
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-swap="))) {
97,859✔
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,934✔
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="))) {
74,009✔
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="))) {
62,084✔
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="))) {
50,159✔
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="))) {
50,158✔
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="))) {
38,233✔
688
                        r = free_and_strdup(&c->delegate_subgroup, val);
350✔
689
                        if (r < 0)
350✔
690
                                return r;
691
                } else if ((val = startswith(l, "exec-cgroup-context-memory-pressure-threshold-usec="))) {
37,883✔
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,958✔
696
                        _cleanup_free_ char *path = NULL, *rwm = NULL;
4,644✔
697
                        CGroupDevicePermissions p;
4,644✔
698

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

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

709
                        r = cgroup_context_add_or_update_device_allow(c, path, p);
4,644✔
710
                        if (r < 0)
4,644✔
711
                                return r;
712
                } else if ((val = startswith(l, "exec-cgroup-context-io-device-weight="))) {
21,314✔
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,314✔
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,314✔
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,314✔
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,314✔
817
                        struct in_addr_prefix a;
1,604✔
818

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

823
                        r = in_addr_prefix_add(&c->ip_address_deny, &a);
1,604✔
824
                        if (r < 0)
1,604✔
825
                                return r;
826
                } else if ((val = startswith(l, "exec-cgroup-context-ip-address-allow-reduced="))) {
19,710✔
827
                        r = parse_boolean(val);
9,843✔
828
                        if (r < 0)
9,843✔
829
                                return r;
830
                        c->ip_address_allow_reduced = r;
9,843✔
831
                } else if ((val = startswith(l, "exec-cgroup-context-ip-address-deny-reduced="))) {
9,867✔
832
                        r = parse_boolean(val);
9,843✔
833
                        if (r < 0)
9,843✔
834
                                return r;
835
                        c->ip_address_deny_reduced = r;
9,843✔
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,123✔
918
        int r;
2,123✔
919

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

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

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

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

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

941
                if (rt->shared->netns_storage_socket[0] >= 0 && rt->shared->netns_storage_socket[1] >= 0) {
70✔
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) {
70✔
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) {
71✔
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) {
71✔
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) {
70✔
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);
71✔
971
        if (r < 0)
71✔
972
                return r;
973

974
        if (rt->ephemeral_storage_socket[0] >= 0 && rt->ephemeral_storage_socket[1] >= 0) {
71✔
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 */
71✔
981

982
        return 0;
71✔
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,155✔
995
                _cleanup_free_ char *l = NULL;
1,230✔
996
                const char *val;
13,155✔
997

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

1004
                if ((val = startswith(l, "exec-runtime-id="))) {
1,230✔
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="))) {
872✔
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="))) {
534✔
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="))) {
196✔
1017

1018
                        r = deserialize_fd_many(fds, val, 2, rt->shared->netns_storage_socket);
66✔
1019
                        if (r < 0)
66✔
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,123✔
1060
        assert(p);
2,123✔
1061

1062
        return p->idle_pipe &&
2,151✔
1063
                p->idle_pipe[0] >= 0 &&
28✔
1064
                p->idle_pipe[1] >= 0 &&
26✔
1065
                p->idle_pipe[2] >= 0 &&
2,149✔
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,123✔
1070
        int r;
2,123✔
1071

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

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

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

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

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

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

1099
                r = serialize_fd_many(f, fds, "exec-parameters-fds", p->fds, p->n_socket_fds + p->n_stashed_fds);
425✔
1100
                if (r < 0)
425✔
1101
                        return r;
1102

1103
                r = serialize_strv(f, "exec-parameters-fd-names", p->fd_names);
425✔
1104
                if (r < 0)
425✔
1105
                        return r;
1106
        }
1107

1108
        if (p->flags != 0) {
2,123✔
1109
                r = serialize_item_format(f, "exec-parameters-flags", "%u", (unsigned) p->flags);
2,123✔
1110
                if (r < 0)
2,123✔
1111
                        return r;
1112
        }
1113

1114
        r = serialize_bool_elide(f, "exec-parameters-selinux-context-net", p->selinux_context_net);
2,123✔
1115
        if (r < 0)
2,123✔
1116
                return r;
1117

1118
        r = serialize_item(f, "exec-parameters-cgroup-path", p->cgroup_path);
2,123✔
1119
        if (r < 0)
2,123✔
1120
                return r;
1121

1122
        r = serialize_item_format(f, "exec-parameters-cgroup-id", "%" PRIu64, p->cgroup_id);
2,123✔
1123
        if (r < 0)
2,123✔
1124
                return r;
1125

1126
        for (ExecDirectoryType dt = 0; dt < _EXEC_DIRECTORY_TYPE_MAX; dt++) {
12,738✔
1127
                _cleanup_free_ char *key = NULL;
10,615✔
1128

1129
                key = strjoin("exec-parameters-prefix-directories-", exec_directory_type_to_string(dt));
10,615✔
1130
                if (!key)
10,615✔
1131
                        return log_oom_debug();
×
1132

1133
                /* Always serialize, even an empty prefix, as this is a fixed array and we always expect
1134
                 * to have all elements (unless fuzzing is happening, hence the NULL check). */
1135
                r = serialize_item(f, key, strempty(p->prefix ? p->prefix[dt] : NULL));
10,615✔
1136
                if (r < 0)
10,615✔
1137
                        return r;
1138
        }
1139

1140
        r = serialize_item(f, "exec-parameters-received-credentials-directory", p->received_credentials_directory);
2,123✔
1141
        if (r < 0)
2,123✔
1142
                return r;
1143

1144
        r = serialize_item(f, "exec-parameters-received-encrypted-credentials-directory", p->received_encrypted_credentials_directory);
2,123✔
1145
        if (r < 0)
2,123✔
1146
                return r;
1147

1148
        r = serialize_item(f, "exec-parameters-confirm-spawn", p->confirm_spawn);
2,123✔
1149
        if (r < 0)
2,123✔
1150
                return r;
1151

1152
        r = serialize_bool_elide(f, "exec-parameters-shall-confirm-spawn", p->shall_confirm_spawn);
2,123✔
1153
        if (r < 0)
2,123✔
1154
                return r;
1155

1156
        if (p->watchdog_usec > 0) {
2,123✔
1157
                r = serialize_usec(f, "exec-parameters-watchdog-usec", p->watchdog_usec);
210✔
1158
                if (r < 0)
210✔
1159
                        return r;
1160
        }
1161

1162
        if (exec_parameters_is_idle_pipe_set(p)) {
2,123✔
1163
                r = serialize_fd_many(f, fds, "exec-parameters-idle-pipe", p->idle_pipe, 4);
26✔
1164
                if (r < 0)
26✔
1165
                        return r;
1166
        }
1167

1168
        r = serialize_fd(f, fds, "exec-parameters-stdin-fd", p->stdin_fd);
2,123✔
1169
        if (r < 0)
2,123✔
1170
                return r;
1171

1172
        r = serialize_fd(f, fds, "exec-parameters-stdout-fd", p->stdout_fd);
2,123✔
1173
        if (r < 0)
2,123✔
1174
                return r;
1175

1176
        r = serialize_fd(f, fds, "exec-parameters-stderr-fd", p->stderr_fd);
2,123✔
1177
        if (r < 0)
2,123✔
1178
                return r;
1179

1180
        r = serialize_fd(f, fds, "exec-parameters-root-directory-fd", p->root_directory_fd);
2,123✔
1181
        if (r < 0)
2,123✔
1182
                return r;
1183

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

1188
        r = serialize_fd(f, fds, "exec-parameters-handoff-timestamp-fd", p->handoff_timestamp_fd);
2,123✔
1189
        if (r < 0)
2,123✔
1190
                return r;
1191

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

1196
        if (c && exec_context_restrict_filesystems_set(c)) {
2,123✔
1197
                r = serialize_fd(f, fds, "exec-parameters-bpf-outer-map-fd", p->bpf_restrict_fs_map_fd);
×
1198
                if (r < 0)
×
1199
                        return r;
1200
        }
1201

1202
        r = serialize_item(f, "exec-parameters-notify-socket", p->notify_socket);
2,123✔
1203
        if (r < 0)
2,123✔
1204
                return r;
1205

1206
        LIST_FOREACH(open_files, file, p->open_files) {
2,123✔
1207
                _cleanup_free_ char *ofs = NULL;
×
1208

1209
                r = open_file_to_string(file, &ofs);
×
1210
                if (r < 0)
×
1211
                        return r;
1212

1213
                r = serialize_item(f, "exec-parameters-open-file", ofs);
×
1214
                if (r < 0)
×
1215
                        return r;
1216
        }
1217

1218
        r = serialize_item(f, "exec-parameters-fallback-smack-process-label", p->fallback_smack_process_label);
2,123✔
1219
        if (r < 0)
2,123✔
1220
                return r;
1221

1222
        r = serialize_fd(f, fds, "exec-parameters-user-lookup-fd", p->user_lookup_fd);
2,123✔
1223
        if (r < 0)
2,123✔
1224
                return r;
1225

1226
        r = serialize_strv(f, "exec-parameters-files-env", p->files_env);
2,123✔
1227
        if (r < 0)
2,123✔
1228
                return r;
1229

1230
        r = serialize_item(f, "exec-parameters-unit-id", p->unit_id);
2,123✔
1231
        if (r < 0)
2,123✔
1232
                return r;
1233

1234
        r = serialize_item(f, "exec-parameters-invocation-id-string", p->invocation_id_string);
2,123✔
1235
        if (r < 0)
2,123✔
1236
                return r;
1237

1238
        r = serialize_bool_elide(f, "exec-parameters-debug-invocation", p->debug_invocation);
2,123✔
1239
        if (r < 0)
2,123✔
1240
                return r;
1241

1242
        fputc('\n', f); /* End marker */
2,123✔
1243

1244
        return 0;
2,123✔
1245
}
1246

1247
static int exec_parameters_deserialize(ExecParameters *p, FILE *f, FDSet *fds) {
11,925✔
1248
        int r;
11,925✔
1249

1250
        assert(p);
11,925✔
1251
        assert(f);
11,925✔
1252
        assert(fds);
11,925✔
1253

1254
        unsigned nr_open = MAX(read_nr_open(), NR_OPEN_MINIMUM);
11,925✔
1255

1256
        for (;;) {
254,955✔
1257
                _cleanup_free_ char *l = NULL;
243,030✔
1258
                const char *val;
254,955✔
1259

1260
                r = deserialize_read_line(f, &l);
254,955✔
1261
                if (r < 0)
254,955✔
1262
                        return r;
1263
                if (r == 0) /* eof or end marker */
254,955✔
1264
                        break;
1265

1266
                if ((val = startswith(l, "exec-parameters-runtime-scope="))) {
243,030✔
1267
                        p->runtime_scope = runtime_scope_from_string(val);
11,925✔
1268
                        if (p->runtime_scope < 0)
11,925✔
1269
                                return p->runtime_scope;
1270
                } else if ((val = startswith(l, "exec-parameters-environment="))) {
231,105✔
1271
                        r = deserialize_strv(val, &p->environment);
48,733✔
1272
                        if (r < 0)
48,733✔
1273
                                return r;
1274
                } else if ((val = startswith(l, "exec-parameters-n-socket-fds="))) {
182,372✔
1275
                        if (p->fds)
2,449✔
1276
                                return -EINVAL; /* Already received */
1277

1278
                        r = safe_atozu(val, &p->n_socket_fds);
2,449✔
1279
                        if (r < 0)
2,449✔
1280
                                return r;
1281

1282
                        if (p->n_socket_fds > nr_open)
2,449✔
1283
                                return -EINVAL; /* too many, someone is playing games with us */
1284
                } else if ((val = startswith(l, "exec-parameters-n-stashed-fds="))) {
179,923✔
1285
                        if (p->fds)
147✔
1286
                                return -EINVAL; /* Already received */
1287

1288
                        r = safe_atozu(val, &p->n_stashed_fds);
147✔
1289
                        if (r < 0)
147✔
1290
                                return r;
1291

1292
                        if (p->n_stashed_fds > nr_open)
147✔
1293
                                return -EINVAL; /* too many, someone is playing games with us */
1294
                } else if ((val = startswith(l, "exec-parameters-fds="))) {
179,776✔
1295
                        if (p->n_socket_fds + p->n_stashed_fds == 0)
2,454✔
1296
                                return log_warning_errno(
×
1297
                                                SYNTHETIC_ERRNO(EINVAL),
1298
                                                "Got exec-parameters-fds= without "
1299
                                                "prior exec-parameters-n-socket-fds= or exec-parameters-n-stashed-fds=");
1300
                        if (p->n_socket_fds + p->n_stashed_fds > nr_open)
2,454✔
1301
                                return -EINVAL; /* too many, someone is playing games with us */
1302

1303
                        if (p->fds)
2,454✔
1304
                                return -EINVAL; /* duplicated */
1305

1306
                        p->fds = new(int, p->n_socket_fds + p->n_stashed_fds);
2,454✔
1307
                        if (!p->fds)
2,454✔
1308
                                return log_oom_debug();
×
1309

1310
                        /* Ensure we don't leave any FD uninitialized on error, it makes the fuzzer sad */
1311
                        FOREACH_ARRAY(i, p->fds, p->n_socket_fds + p->n_stashed_fds)
7,447✔
1312
                                *i = -EBADF;
4,993✔
1313

1314
                        r = deserialize_fd_many(fds, val, p->n_socket_fds + p->n_stashed_fds, p->fds);
2,454✔
1315
                        if (r < 0)
2,454✔
1316
                                continue;
×
1317

1318
                } else if ((val = startswith(l, "exec-parameters-fd-names="))) {
177,322✔
1319
                        r = deserialize_strv(val, &p->fd_names);
4,993✔
1320
                        if (r < 0)
4,993✔
1321
                                return r;
1322
                } else if ((val = startswith(l, "exec-parameters-flags="))) {
172,329✔
1323
                        unsigned flags;
11,925✔
1324

1325
                        r = safe_atou(val, &flags);
11,925✔
1326
                        if (r < 0)
11,925✔
1327
                                return r;
×
1328
                        p->flags = flags;
11,925✔
1329
                } else if ((val = startswith(l, "exec-parameters-selinux-context-net="))) {
160,404✔
1330
                        r = parse_boolean(val);
×
1331
                        if (r < 0)
×
1332
                                return r;
1333

1334
                        p->selinux_context_net = r;
×
1335
                } else if ((val = startswith(l, "exec-parameters-cgroup-path="))) {
160,404✔
1336
                        r = free_and_strdup(&p->cgroup_path, val);
11,925✔
1337
                        if (r < 0)
11,925✔
1338
                                return r;
1339
                } else if ((val = startswith(l, "exec-parameters-cgroup-id="))) {
148,479✔
1340
                        r = safe_atou64(val, &p->cgroup_id);
11,925✔
1341
                        if (r < 0)
11,925✔
1342
                                return r;
1343
                } else if ((val = startswith(l, "exec-parameters-prefix-directories-"))) {
136,554✔
1344
                        _cleanup_free_ char *type = NULL, *prefix = NULL;
59,625✔
1345
                        ExecDirectoryType dt;
59,625✔
1346

1347
                        r = extract_many_words(&val, "= ", 0, &type, &prefix);
59,625✔
1348
                        if (r < 0)
59,625✔
1349
                                return r;
1350
                        if (r == 0)
59,625✔
1351
                                return -EINVAL;
1352

1353
                        dt = exec_directory_type_from_string(type);
59,625✔
1354
                        if (dt < 0)
59,625✔
1355
                                return -EINVAL;
1356

1357
                        if (!p->prefix) {
59,625✔
1358
                                p->prefix = new0(char*, _EXEC_DIRECTORY_TYPE_MAX+1);
11,925✔
1359
                                if (!p->prefix)
11,925✔
1360
                                        return log_oom_debug();
×
1361
                        }
1362

1363
                        if (isempty(prefix))
59,625✔
1364
                                p->prefix[dt] = mfree(p->prefix[dt]);
×
1365
                        else
1366
                                free_and_replace(p->prefix[dt], prefix);
59,625✔
1367
                } else if ((val = startswith(l, "exec-parameters-received-credentials-directory="))) {
76,929✔
1368
                        r = free_and_strdup(&p->received_credentials_directory, val);
11,250✔
1369
                        if (r < 0)
11,250✔
1370
                                return r;
1371
                } else if ((val = startswith(l, "exec-parameters-received-encrypted-credentials-directory="))) {
65,679✔
1372
                        r = free_and_strdup(&p->received_encrypted_credentials_directory, val);
×
1373
                        if (r < 0)
×
1374
                                return r;
1375
                } else if ((val = startswith(l, "exec-parameters-confirm-spawn="))) {
65,679✔
1376
                        r = free_and_strdup(&p->confirm_spawn, val);
×
1377
                        if (r < 0)
×
1378
                                return r;
1379
                } else if ((val = startswith(l, "exec-parameters-shall-confirm-spawn="))) {
65,679✔
1380
                        r = parse_boolean(val);
×
1381
                        if (r < 0)
×
1382
                                return r;
1383

1384
                        p->shall_confirm_spawn = r;
×
1385
                } else if ((val = startswith(l, "exec-parameters-watchdog-usec="))) {
65,679✔
1386
                        r = deserialize_usec(val, &p->watchdog_usec);
2,192✔
1387
                        if (r < 0)
2,192✔
1388
                                return r;
1389
                } else if ((val = startswith(l, "exec-parameters-idle-pipe="))) {
63,487✔
1390
                        if (p->idle_pipe)
171✔
1391
                                return -EINVAL; /* duplicated */
1392

1393
                        p->idle_pipe = new(int, 4);
171✔
1394
                        if (!p->idle_pipe)
171✔
1395
                                return log_oom_debug();
×
1396

1397
                        p->idle_pipe[0] = p->idle_pipe[1] = p->idle_pipe[2] = p->idle_pipe[3] = -EBADF;
171✔
1398

1399
                        r = deserialize_fd_many(fds, val, 4, p->idle_pipe);
171✔
1400
                        if (r < 0)
171✔
1401
                                continue;
×
1402

1403
                } else if ((val = startswith(l, "exec-parameters-stdin-fd="))) {
63,316✔
1404
                        int fd;
588✔
1405

1406
                        fd = deserialize_fd(fds, val);
588✔
1407
                        if (fd < 0)
588✔
1408
                                continue;
×
1409

1410
                        close_and_replace(p->stdin_fd, fd);
588✔
1411

1412
                } else if ((val = startswith(l, "exec-parameters-stdout-fd="))) {
62,728✔
1413
                        int fd;
588✔
1414

1415
                        fd = deserialize_fd(fds, val);
588✔
1416
                        if (fd < 0)
588✔
1417
                                continue;
×
1418

1419
                        close_and_replace(p->stdout_fd, fd);
588✔
1420

1421
                } else if ((val = startswith(l, "exec-parameters-stderr-fd="))) {
62,140✔
1422
                        int fd;
588✔
1423

1424
                        fd = deserialize_fd(fds, val);
588✔
1425
                        if (fd < 0)
588✔
1426
                                continue;
×
1427

1428
                        close_and_replace(p->stderr_fd, fd);
588✔
1429

1430
                } else if ((val = startswith(l, "exec-parameters-root-directory-fd="))) {
61,552✔
NEW
1431
                        int fd;
×
1432

NEW
1433
                        fd = deserialize_fd(fds, val);
×
NEW
1434
                        if (fd < 0)
×
NEW
1435
                                continue;
×
1436

NEW
1437
                        close_and_replace(p->root_directory_fd, fd);
×
1438

1439
                } else if ((val = startswith(l, "exec-parameters-exec-fd="))) {
61,552✔
1440
                        int fd;
471✔
1441

1442
                        fd = deserialize_fd(fds, val);
471✔
1443
                        if (fd < 0)
471✔
1444
                                continue;
×
1445

1446
                        close_and_replace(p->exec_fd, fd);
471✔
1447
                } else if ((val = startswith(l, "exec-parameters-handoff-timestamp-fd="))) {
61,081✔
1448
                        int fd;
11,925✔
1449

1450
                        fd = deserialize_fd(fds, val);
11,925✔
1451
                        if (fd < 0)
11,925✔
1452
                                continue;
×
1453

1454
                        close_and_replace(p->handoff_timestamp_fd, fd);
11,925✔
1455
                } else if ((val = startswith(l, "exec-parameters-pidref-transport-fd="))) {
49,156✔
1456
                        int fd;
10,777✔
1457

1458
                        fd = deserialize_fd(fds, val);
10,777✔
1459
                        if (fd < 0)
10,777✔
1460
                                continue;
×
1461

1462
                        close_and_replace(p->pidref_transport_fd, fd);
10,777✔
1463
                } else if ((val = startswith(l, "exec-parameters-bpf-outer-map-fd="))) {
38,379✔
1464
                        int fd;
×
1465

1466
                        fd = deserialize_fd(fds, val);
×
1467
                        if (fd < 0)
×
1468
                                continue;
×
1469

1470
                        close_and_replace(p->bpf_restrict_fs_map_fd, fd);
×
1471
                } else if ((val = startswith(l, "exec-parameters-notify-socket="))) {
38,379✔
1472
                        r = free_and_strdup(&p->notify_socket, val);
2,595✔
1473
                        if (r < 0)
2,595✔
1474
                                return r;
1475
                } else if ((val = startswith(l, "exec-parameters-open-file="))) {
35,784✔
1476
                        OpenFile *of;
5✔
1477

1478
                        r = open_file_parse(val, &of);
5✔
1479
                        if (r < 0)
5✔
1480
                                return r;
×
1481

1482
                        LIST_APPEND(open_files, p->open_files, of);
5✔
1483
                } else if ((val = startswith(l, "exec-parameters-fallback-smack-process-label="))) {
35,779✔
1484
                        r = free_and_strdup(&p->fallback_smack_process_label, val);
×
1485
                        if (r < 0)
×
1486
                                return r;
1487
                } else if ((val = startswith(l, "exec-parameters-user-lookup-fd="))) {
35,779✔
1488
                        int fd;
11,925✔
1489

1490
                        fd = deserialize_fd(fds, val);
11,925✔
1491
                        if (fd < 0)
11,925✔
1492
                                continue;
×
1493

1494
                        close_and_replace(p->user_lookup_fd, fd);
11,925✔
1495
                } else if ((val = startswith(l, "exec-parameters-files-env="))) {
23,854✔
1496
                        r = deserialize_strv(val, &p->files_env);
2✔
1497
                        if (r < 0)
2✔
1498
                                return r;
1499
                } else if ((val = startswith(l, "exec-parameters-unit-id="))) {
23,852✔
1500
                        r = free_and_strdup(&p->unit_id, val);
11,925✔
1501
                        if (r < 0)
11,925✔
1502
                                return r;
1503
                } else if ((val = startswith(l, "exec-parameters-invocation-id-string="))) {
11,927✔
1504
                        if (strlen(val) > SD_ID128_STRING_MAX - 1)
11,925✔
1505
                                return -EINVAL;
1506

1507
                        r = sd_id128_from_string(val, &p->invocation_id);
11,925✔
1508
                        if (r < 0)
11,925✔
1509
                                return r;
1510

1511
                        sd_id128_to_string(p->invocation_id, p->invocation_id_string);
11,925✔
1512
                } else if ((val = startswith(l, "exec-parameters-debug-invocation="))) {
2✔
1513
                        r = parse_boolean(val);
2✔
1514
                        if (r < 0)
2✔
1515
                                return r;
1516

1517
                        p->debug_invocation = r;
2✔
1518
                } else
1519
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
1520
        }
1521

1522
        /* Bail out if we got exec-parameters-n-{socket/stashed}-fds= but no corresponding
1523
         * exec-parameters-fds= */
1524
        if (p->n_socket_fds + p->n_stashed_fds > 0 && !p->fds)
11,925✔
1525
                return -EINVAL;
×
1526

1527
        return 0;
1528
}
1529

1530
static int serialize_std_out_err(const ExecContext *c, FILE *f, int fileno) {
4,246✔
1531
        char *key, *value;
4,246✔
1532
        const char *type;
4,246✔
1533

1534
        assert(c);
4,246✔
1535
        assert(f);
4,246✔
1536
        assert(IN_SET(fileno, STDOUT_FILENO, STDERR_FILENO));
4,246✔
1537

1538
        type = fileno == STDOUT_FILENO ? "output" : "error";
4,246✔
1539

1540
        switch (fileno == STDOUT_FILENO ? c->std_output : c->std_error) {
4,246✔
1541
        case EXEC_OUTPUT_NAMED_FD:
×
1542
                key = strjoina("exec-context-std-", type, "-fd-name");
×
1543
                value = c->stdio_fdname[fileno];
×
1544

1545
                break;
×
1546

1547
        case EXEC_OUTPUT_FILE:
2✔
1548
                key = strjoina("exec-context-std-", type, "-file");
14✔
1549
                value = c->stdio_file[fileno];
2✔
1550

1551
                break;
2✔
1552

1553
        case EXEC_OUTPUT_FILE_APPEND:
×
1554
                key = strjoina("exec-context-std-", type, "-file-append");
×
1555
                value = c->stdio_file[fileno];
×
1556

1557
                break;
×
1558

1559
        case EXEC_OUTPUT_FILE_TRUNCATE:
×
1560
                key = strjoina("exec-context-std-", type, "-file-truncate");
×
1561
                value = c->stdio_file[fileno];
×
1562

1563
                break;
×
1564

1565
        default:
1566
                return 0;
1567
        }
1568

1569
        return serialize_item(f, key, value);
2✔
1570
}
1571

1572
static int exec_context_serialize(const ExecContext *c, FILE *f) {
2,123✔
1573
        int r;
2,123✔
1574

1575
        assert(f);
2,123✔
1576

1577
        if (!c)
2,123✔
1578
                return 0;
2,123✔
1579

1580
        r = serialize_strv(f, "exec-context-environment", c->environment);
2,123✔
1581
        if (r < 0)
2,123✔
1582
                return r;
1583

1584
        r = serialize_strv(f, "exec-context-environment-files", c->environment_files);
2,123✔
1585
        if (r < 0)
2,123✔
1586
                return r;
1587

1588
        r = serialize_strv(f, "exec-context-pass-environment", c->pass_environment);
2,123✔
1589
        if (r < 0)
2,123✔
1590
                return r;
1591

1592
        r = serialize_strv(f, "exec-context-unset-environment", c->unset_environment);
2,123✔
1593
        if (r < 0)
2,123✔
1594
                return r;
1595

1596
        r = serialize_item_escaped(f, "exec-context-working-directory", c->working_directory);
2,123✔
1597
        if (r < 0)
2,123✔
1598
                return r;
1599

1600
        r = serialize_bool_elide(f, "exec-context-working-directory-missing-ok", c->working_directory_missing_ok);
2,123✔
1601
        if (r < 0)
2,123✔
1602
                return r;
1603

1604
        r = serialize_bool_elide(f, "exec-context-working-directory-home", c->working_directory_home);
2,123✔
1605
        if (r < 0)
2,123✔
1606
                return r;
1607

1608
        r = serialize_item_escaped(f, "exec-context-root-directory", c->root_directory);
2,123✔
1609
        if (r < 0)
2,123✔
1610
                return r;
1611

1612
        r = serialize_item_escaped(f, "exec-context-root-image", c->root_image);
2,123✔
1613
        if (r < 0)
2,123✔
1614
                return r;
1615

1616
        if (c->root_image_options) {
2,123✔
1617
                _cleanup_free_ char *options = NULL;
×
1618

1619
                LIST_FOREACH(mount_options, o, c->root_image_options) {
×
1620
                        if (isempty(o->options))
×
1621
                                continue;
×
1622

1623
                        _cleanup_free_ char *escaped = NULL;
×
1624
                        escaped = shell_escape(o->options, ":");
×
1625
                        if (!escaped)
×
1626
                                return log_oom_debug();
×
1627

1628
                        if (!strextend(&options,
×
1629
                                        " ",
1630
                                        partition_designator_to_string(o->partition_designator),
1631
                                               ":",
1632
                                               escaped))
1633
                                        return log_oom_debug();
×
1634
                }
1635

1636
                r = serialize_item(f, "exec-context-root-image-options", options);
×
1637
                if (r < 0)
×
1638
                        return r;
1639
        }
1640

1641
        r = serialize_item(f, "exec-context-root-verity", c->root_verity);
2,123✔
1642
        if (r < 0)
2,123✔
1643
                return r;
1644

1645
        r = serialize_item(f, "exec-context-root-hash-path", c->root_hash_path);
2,123✔
1646
        if (r < 0)
2,123✔
1647
                return r;
1648

1649
        r = serialize_item(f, "exec-context-root-hash-sig-path", c->root_hash_sig_path);
2,123✔
1650
        if (r < 0)
2,123✔
1651
                return r;
1652

1653
        r = serialize_item_hexmem(f, "exec-context-root-hash", c->root_hash, c->root_hash_size);
2,123✔
1654
        if (r < 0)
2,123✔
1655
                return r;
1656

1657
        r = serialize_item_base64mem(f, "exec-context-root-hash-sig", c->root_hash_sig, c->root_hash_sig_size);
2,123✔
1658
        if (r < 0)
2,123✔
1659
                return r;
1660

1661
        r = serialize_bool_elide(f, "exec-context-root-ephemeral", c->root_ephemeral);
2,123✔
1662
        if (r < 0)
2,123✔
1663
                return r;
1664

1665
        r = serialize_item_format(f, "exec-context-umask", "%04o", c->umask);
2,123✔
1666
        if (r < 0)
2,123✔
1667
                return r;
1668

1669
        r = serialize_bool_elide(f, "exec-context-non-blocking", c->non_blocking);
2,123✔
1670
        if (r < 0)
2,123✔
1671
                return r;
1672

1673
        r = serialize_item_tristate(f, "exec-context-private-mounts", c->private_mounts);
2,123✔
1674
        if (r < 0)
27✔
1675
                return r;
1676

1677
        r = serialize_item_tristate(f, "exec-context-mount-api-vfs", c->mount_apivfs);
2,123✔
1678
        if (r < 0)
2✔
1679
                return r;
1680

1681
        r = serialize_item_tristate(f, "exec-context-bind-log-sockets", c->bind_log_sockets);
2,123✔
1682
        if (r < 0)
×
1683
                return r;
1684

1685
        r = serialize_item_tristate(f, "exec-context-memory-ksm", c->memory_ksm);
2,123✔
1686
        if (r < 0)
×
1687
                return r;
1688

1689
        r = serialize_item(f, "exec-context-private-tmp", private_tmp_to_string(c->private_tmp));
2,123✔
1690
        if (r < 0)
2,123✔
1691
                return r;
1692

1693
        /* This must be set in unit_patch_contexts() before executing a command. */
1694
        assert(c->private_var_tmp >= 0 && c->private_var_tmp < _PRIVATE_TMP_MAX);
2,123✔
1695
        r = serialize_item(f, "exec-context-private-var-tmp", private_tmp_to_string(c->private_var_tmp));
2,123✔
1696
        if (r < 0)
2,123✔
1697
                return r;
1698

1699
        r = serialize_bool_elide(f, "exec-context-private-devices", c->private_devices);
2,123✔
1700
        if (r < 0)
2,123✔
1701
                return r;
1702

1703
        r = serialize_bool_elide(f, "exec-context-protect-kernel-tunables", c->protect_kernel_tunables);
2,123✔
1704
        if (r < 0)
2,123✔
1705
                return r;
1706

1707
        r = serialize_bool_elide(f, "exec-context-protect-kernel-modules", c->protect_kernel_modules);
2,123✔
1708
        if (r < 0)
2,123✔
1709
                return r;
1710

1711
        r = serialize_bool_elide(f, "exec-context-protect-kernel-logs", c->protect_kernel_logs);
2,123✔
1712
        if (r < 0)
2,123✔
1713
                return r;
1714

1715
        r = serialize_bool_elide(f, "exec-context-protect-clock", c->protect_clock);
2,123✔
1716
        if (r < 0)
2,123✔
1717
                return r;
1718

1719
        r = serialize_item(f, "exec-context-protect-control-groups", protect_control_groups_to_string(c->protect_control_groups));
2,123✔
1720
        if (r < 0)
2,123✔
1721
                return r;
1722

1723
        r = serialize_bool_elide(f, "exec-context-private-network", c->private_network);
2,123✔
1724
        if (r < 0)
2,123✔
1725
                return r;
1726

1727
        r = serialize_item(f, "exec-context-private-users", private_users_to_string(c->private_users));
2,123✔
1728
        if (r < 0)
2,123✔
1729
                return r;
1730

1731
        r = serialize_bool_elide(f, "exec-context-private-ipc", c->private_ipc);
2,123✔
1732
        if (r < 0)
2,123✔
1733
                return r;
1734

1735
        r = serialize_item(f, "exec-context-private-pids", private_pids_to_string(c->private_pids));
2,123✔
1736
        if (r < 0)
2,123✔
1737
                return r;
1738

1739
        r = serialize_bool_elide(f, "exec-context-remove-ipc", c->remove_ipc);
2,123✔
1740
        if (r < 0)
2,123✔
1741
                return r;
1742

1743
        r = serialize_item(f, "exec-context-protect-home", protect_home_to_string(c->protect_home));
2,123✔
1744
        if (r < 0)
2,123✔
1745
                return r;
1746

1747
        r = serialize_item(f, "exec-context-protect-system", protect_system_to_string(c->protect_system));
2,123✔
1748
        if (r < 0)
2,123✔
1749
                return r;
1750

1751
        r = serialize_bool_elide(f, "exec-context-same-pgrp", c->same_pgrp);
2,123✔
1752
        if (r < 0)
2,123✔
1753
                return r;
1754

1755
        r = serialize_bool(f, "exec-context-ignore-sigpipe", c->ignore_sigpipe);
2,123✔
1756
        if (r < 0)
2,123✔
1757
                return r;
1758

1759
        r = serialize_bool_elide(f, "exec-context-memory-deny-write-execute", c->memory_deny_write_execute);
2,123✔
1760
        if (r < 0)
2,123✔
1761
                return r;
1762

1763
        r = serialize_bool_elide(f, "exec-context-restrict-realtime", c->restrict_realtime);
2,123✔
1764
        if (r < 0)
2,123✔
1765
                return r;
1766

1767
        r = serialize_bool_elide(f, "exec-context-restrict-suid-sgid", c->restrict_suid_sgid);
2,123✔
1768
        if (r < 0)
2,123✔
1769
                return r;
1770

1771
        r = serialize_item(f, "exec-context-keyring-mode", exec_keyring_mode_to_string(c->keyring_mode));
2,123✔
1772
        if (r < 0)
2,123✔
1773
                return r;
1774

1775
        r = serialize_item(f, "exec-context-protect-hostname", protect_hostname_to_string(c->protect_hostname));
2,123✔
1776
        if (r < 0)
2,123✔
1777
                return r;
1778

1779
        r = serialize_item(f, "exec-context-private-hostname", c->private_hostname);
2,123✔
1780
        if (r < 0)
2,123✔
1781
                return r;
1782

1783
        r = serialize_item(f, "exec-context-protect-proc", protect_proc_to_string(c->protect_proc));
2,123✔
1784
        if (r < 0)
2,123✔
1785
                return r;
1786

1787
        r = serialize_item(f, "exec-context-proc-subset", proc_subset_to_string(c->proc_subset));
2,123✔
1788
        if (r < 0)
2,123✔
1789
                return r;
1790

1791
        r = serialize_item(f, "exec-context-private-bpf", private_bpf_to_string(c->private_bpf));
2,123✔
1792
        if (r < 0)
2,123✔
1793
                return r;
1794

1795
        if (c->bpf_delegate_commands != 0) {
2,123✔
1796
                r = serialize_item_format(f, "exec-context-bpf-delegate-commands", "0x%"PRIx64, c->bpf_delegate_commands);
×
1797
                if (r < 0)
×
1798
                        return r;
1799
        }
1800

1801
        if (c->bpf_delegate_maps != 0) {
2,123✔
1802
                r = serialize_item_format(f, "exec-context-bpf-delegate-maps", "0x%"PRIx64, c->bpf_delegate_maps);
×
1803
                if (r < 0)
×
1804
                        return r;
1805
        }
1806

1807
        if (c->bpf_delegate_programs != 0) {
2,123✔
1808
                r = serialize_item_format(f, "exec-context-bpf-delegate-programs", "0x%"PRIx64, c->bpf_delegate_programs);
×
1809
                if (r < 0)
×
1810
                        return r;
1811
        }
1812

1813
        if (c->bpf_delegate_attachments != 0) {
2,123✔
1814
                r = serialize_item_format(f, "exec-context-bpf-delegate-attachments", "0x%"PRIx64, c->bpf_delegate_attachments);
×
1815
                if (r < 0)
×
1816
                        return r;
1817
        }
1818

1819
        r = serialize_item(f, "exec-context-runtime-directory-preserve-mode", exec_preserve_mode_to_string(c->runtime_directory_preserve_mode));
2,123✔
1820
        if (r < 0)
2,123✔
1821
                return r;
1822

1823
        for (ExecDirectoryType dt = 0; dt < _EXEC_DIRECTORY_TYPE_MAX; dt++) {
12,738✔
1824
                _cleanup_free_ char *key = NULL, *value = NULL;
10,615✔
1825

1826
                key = strjoin("exec-context-directories-", exec_directory_type_to_string(dt));
10,615✔
1827
                if (!key)
10,615✔
1828
                        return log_oom_debug();
×
1829

1830
                if (asprintf(&value, "%04o", c->directories[dt].mode) < 0)
10,615✔
1831
                        return log_oom_debug();
×
1832

1833
                FOREACH_ARRAY(i, c->directories[dt].items, c->directories[dt].n_items) {
11,020✔
1834
                        _cleanup_free_ char *path_escaped = NULL;
405✔
1835

1836
                        path_escaped = shell_escape(i->path, ":" WHITESPACE);
405✔
1837
                        if (!path_escaped)
405✔
1838
                                return log_oom_debug();
×
1839

1840
                        if (!strextend(&value, " ", path_escaped))
405✔
1841
                                return log_oom_debug();
×
1842

1843
                        if (!strextend(&value, ":", yes_no(FLAGS_SET(i->flags, EXEC_DIRECTORY_ONLY_CREATE))))
805✔
1844
                                return log_oom_debug();
×
1845

1846
                        if (!strextend(&value, ":", yes_no(FLAGS_SET(i->flags, EXEC_DIRECTORY_READ_ONLY))))
808✔
1847
                                return log_oom_debug();
×
1848

1849
                        STRV_FOREACH(d, i->symlinks) {
411✔
1850
                                _cleanup_free_ char *link_escaped = NULL;
6✔
1851

1852
                                link_escaped = shell_escape(*d, ":" WHITESPACE);
6✔
1853
                                if (!link_escaped)
6✔
1854
                                        return log_oom_debug();
×
1855

1856
                                if (!strextend(&value, ":", link_escaped))
6✔
1857
                                        return log_oom_debug();
×
1858
                        }
1859
                }
1860

1861
                r = serialize_item(f, key, value);
10,615✔
1862
                if (r < 0)
10,615✔
1863
                        return r;
1864

1865
                if (c->directories[dt].exec_quota.quota_enforce) {
10,615✔
1866
                        _cleanup_free_ char *key_quota = NULL;
×
1867
                        key_quota = strjoin("exec-context-quota-directories-", exec_directory_type_to_string(dt));
×
1868
                        if (!key_quota)
×
1869
                                return log_oom_debug();
×
1870

1871
                        r = serialize_item_format(f, key_quota, "%" PRIu64 " %" PRIu32, c->directories[dt].exec_quota.quota_absolute,
×
1872
                                                                                        c->directories[dt].exec_quota.quota_scale);
×
1873
                        if (r < 0)
×
1874
                                return r;
1875

1876
                } else if (c->directories[dt].exec_quota.quota_accounting) {
10,615✔
1877
                        _cleanup_free_ char *key_quota = NULL;
×
1878
                        key_quota = strjoin("exec-context-quota-accounting-directories-", exec_directory_type_to_string(dt));
×
1879
                        if (!key_quota)
×
1880
                                return log_oom_debug();
×
1881

1882
                        r = serialize_bool(f, key_quota, c->directories[dt].exec_quota.quota_accounting);
×
1883
                        if (r < 0)
×
1884
                                return r;
1885
                }
1886
        }
1887

1888
        r = serialize_usec(f, "exec-context-timeout-clean-usec", c->timeout_clean_usec);
2,123✔
1889
        if (r < 0)
2,123✔
1890
                return r;
1891

1892
        if (c->nice_set) {
2,123✔
1893
                r = serialize_item_format(f, "exec-context-nice", "%i", c->nice);
2✔
1894
                if (r < 0)
2✔
1895
                        return r;
1896
        }
1897

1898
        if (c->oom_score_adjust_set) {
2,123✔
1899
                r = serialize_item_format(f, "exec-context-oom-score-adjust", "%i", c->oom_score_adjust);
574✔
1900
                if (r < 0)
574✔
1901
                        return r;
1902
        }
1903

1904
        if (c->coredump_filter_set) {
2,123✔
1905
                r = serialize_item_format(f, "exec-context-coredump-filter", "%"PRIx64, c->coredump_filter);
×
1906
                if (r < 0)
×
1907
                        return r;
1908
        }
1909

1910
        for (unsigned i = 0; i < RLIM_NLIMITS; i++) {
36,091✔
1911
                _cleanup_free_ char *key = NULL, *limit = NULL;
4,239✔
1912

1913
                if (!c->rlimit[i])
33,968✔
1914
                        continue;
29,729✔
1915

1916
                key = strjoin("exec-context-limit-", rlimit_to_string(i));
4,239✔
1917
                if (!key)
4,239✔
1918
                        return log_oom_debug();
×
1919

1920
                r = rlimit_format(c->rlimit[i], &limit);
4,239✔
1921
                if (r < 0)
4,239✔
1922
                        return r;
1923

1924
                r = serialize_item(f, key, limit);
4,239✔
1925
                if (r < 0)
4,239✔
1926
                        return r;
1927
        }
1928

1929
        if (c->ioprio_is_set) {
2,123✔
1930
                r = serialize_item_format(f, "exec-context-ioprio", "%d", c->ioprio);
7✔
1931
                if (r < 0)
7✔
1932
                        return r;
1933
        }
1934

1935
        if (c->cpu_sched_set) {
2,123✔
1936
                _cleanup_free_ char *policy_str = NULL;
×
1937

1938
                r = sched_policy_to_string_alloc(c->cpu_sched_policy, &policy_str);
×
1939
                if (r < 0)
×
1940
                        return r;
1941

1942
                r = serialize_item(f, "exec-context-cpu-scheduling-policy", policy_str);
×
1943
                if (r < 0)
×
1944
                        return r;
1945

1946
                r = serialize_item_format(f, "exec-context-cpu-scheduling-priority", "%i", c->cpu_sched_priority);
×
1947
                if (r < 0)
×
1948
                        return r;
1949

1950
                r = serialize_bool_elide(f, "exec-context-cpu-scheduling-reset-on-fork", c->cpu_sched_reset_on_fork);
×
1951
                if (r < 0)
×
1952
                        return r;
1953
        }
1954

1955
        if (c->cpu_set.set) {
2,123✔
1956
                _cleanup_free_ char *affinity = NULL;
×
1957

1958
                affinity = cpu_set_to_range_string(&c->cpu_set);
×
1959
                if (!affinity)
×
1960
                        return log_oom_debug();
×
1961

1962
                r = serialize_item(f, "exec-context-cpu-affinity", affinity);
×
1963
                if (r < 0)
×
1964
                        return r;
1965
        }
1966

1967
        if (mpol_is_valid(numa_policy_get_type(&c->numa_policy))) {
2,123✔
1968
                _cleanup_free_ char *nodes = NULL;
×
1969

1970
                nodes = cpu_set_to_range_string(&c->numa_policy.nodes);
×
1971
                if (!nodes)
×
1972
                        return log_oom_debug();
×
1973

1974
                if (nodes) {
×
1975
                        r = serialize_item(f, "exec-context-numa-mask", nodes);
×
1976
                        if (r < 0)
×
1977
                                return r;
1978
                }
1979

1980
                r = serialize_item_format(f, "exec-context-numa-policy", "%d", c->numa_policy.type);
×
1981
                if (r < 0)
×
1982
                        return r;
1983
        }
1984

1985
        r = serialize_bool_elide(f, "exec-context-cpu-affinity-from-numa", c->cpu_affinity_from_numa);
2,123✔
1986
        if (r < 0)
2,123✔
1987
                return r;
1988

1989
        if (c->timer_slack_nsec != NSEC_INFINITY) {
2,123✔
1990
                r = serialize_item_format(f, "exec-context-timer-slack-nsec", NSEC_FMT, c->timer_slack_nsec);
×
1991
                if (r < 0)
×
1992
                        return r;
1993
        }
1994

1995
        r = serialize_item(f, "exec-context-std-input", exec_input_to_string(c->std_input));
2,123✔
1996
        if (r < 0)
2,123✔
1997
                return r;
1998

1999
        r = serialize_item(f, "exec-context-std-output", exec_output_to_string(c->std_output));
2,123✔
2000
        if (r < 0)
2,123✔
2001
                return r;
2002

2003
        r = serialize_item(f, "exec-context-std-error", exec_output_to_string(c->std_error));
2,123✔
2004
        if (r < 0)
2,123✔
2005
                return r;
2006

2007
        r = serialize_bool_elide(f, "exec-context-stdio-as-fds", c->stdio_as_fds);
2,123✔
2008
        if (r < 0)
2,123✔
2009
                return r;
2010

2011
        r = serialize_bool_elide(f, "exec-context-root-directory-as-fd", c->root_directory_as_fd);
2,123✔
2012
        if (r < 0)
2,123✔
2013
                return r;
2014

2015
        switch (c->std_input) {
2,123✔
2016
        case EXEC_INPUT_NAMED_FD:
×
2017
                r = serialize_item(f, "exec-context-std-input-fd-name", c->stdio_fdname[STDIN_FILENO]);
×
2018
                if (r < 0)
×
2019
                        return r;
2020
                break;
2021

2022
        case EXEC_INPUT_FILE:
×
2023
                r = serialize_item(f, "exec-context-std-input-file", c->stdio_file[STDIN_FILENO]);
×
2024
                if (r < 0)
×
2025
                        return r;
2026
                break;
2027

2028
        default:
2,123✔
2029
                ;
2,123✔
2030
        }
2031

2032
        r = serialize_std_out_err(c, f, STDOUT_FILENO);
2,123✔
2033
        if (r < 0)
2,123✔
2034
                return r;
2035

2036
        r = serialize_std_out_err(c, f, STDERR_FILENO);
2,123✔
2037
        if (r < 0)
2,123✔
2038
                return r;
2039

2040
        r = serialize_item_base64mem(f, "exec-context-stdin-data", c->stdin_data, c->stdin_data_size);
2,123✔
2041
        if (r < 0)
2,123✔
2042
                return r;
2043

2044
        r = serialize_item(f, "exec-context-tty-path", c->tty_path);
2,123✔
2045
        if (r < 0)
2,123✔
2046
                return r;
2047

2048
        r = serialize_bool_elide(f, "exec-context-tty-reset", c->tty_reset);
2,123✔
2049
        if (r < 0)
2,123✔
2050
                return r;
2051

2052
        r = serialize_bool_elide(f, "exec-context-tty-vhangup", c->tty_vhangup);
2,123✔
2053
        if (r < 0)
2,123✔
2054
                return r;
2055

2056
        r = serialize_bool_elide(f, "exec-context-tty-vt-disallocate", c->tty_vt_disallocate);
2,123✔
2057
        if (r < 0)
2,123✔
2058
                return r;
2059

2060
        r = serialize_item_format(f, "exec-context-tty-rows", "%u", c->tty_rows);
2,123✔
2061
        if (r < 0)
2,123✔
2062
                return r;
2063

2064
        r = serialize_item_format(f, "exec-context-tty-columns", "%u", c->tty_cols);
2,123✔
2065
        if (r < 0)
2,123✔
2066
                return r;
2067

2068
        r = serialize_item_format(f, "exec-context-syslog-priority", "%i", c->syslog_priority);
2,123✔
2069
        if (r < 0)
2,123✔
2070
                return r;
2071

2072
        r = serialize_bool(f, "exec-context-syslog-level-prefix", c->syslog_level_prefix);
2,123✔
2073
        if (r < 0)
2,123✔
2074
                return r;
2075

2076
        r = serialize_item(f, "exec-context-syslog-identifier", c->syslog_identifier);
2,123✔
2077
        if (r < 0)
2,123✔
2078
                return r;
2079

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

2086
        if (c->log_ratelimit.interval > 0) {
2,123✔
2087
                r = serialize_usec(f, "exec-context-log-ratelimit-interval-usec", c->log_ratelimit.interval);
×
2088
                if (r < 0)
×
2089
                        return r;
2090
        }
2091

2092
        if (c->log_ratelimit.burst > 0) {
2,123✔
2093
                r = serialize_item_format(f, "exec-context-log-ratelimit-burst", "%u", c->log_ratelimit.burst);
×
2094
                if (r < 0)
×
2095
                        return r;
2096
        }
2097

2098
        r = serialize_string_set(f, "exec-context-log-filter-allowed-patterns", c->log_filter_allowed_patterns);
2,123✔
2099
        if (r < 0)
2,123✔
2100
                return r;
2101

2102
        r = serialize_string_set(f, "exec-context-log-filter-denied-patterns", c->log_filter_denied_patterns);
2,123✔
2103
        if (r < 0)
2,123✔
2104
                return r;
2105

2106
        FOREACH_ARRAY(field, c->log_extra_fields, c->n_log_extra_fields) {
2,123✔
2107
                r = serialize_item(f, "exec-context-log-extra-fields", field->iov_base);
×
2108
                if (r < 0)
×
2109
                        return r;
2110
        }
2111

2112
        r = serialize_item(f, "exec-context-log-namespace", c->log_namespace);
2,123✔
2113
        if (r < 0)
2,123✔
2114
                return r;
2115

2116
        if (c->secure_bits != 0) {
2,123✔
2117
                r = serialize_item_format(f, "exec-context-secure-bits", "%d", c->secure_bits);
×
2118
                if (r < 0)
×
2119
                        return r;
2120
        }
2121

2122
        if (c->capability_bounding_set != CAP_MASK_UNSET) {
2,123✔
2123
                r = serialize_item_format(f, "exec-context-capability-bounding-set", "%" PRIu64, c->capability_bounding_set);
249✔
2124
                if (r < 0)
249✔
2125
                        return r;
2126
        }
2127

2128
        if (c->capability_ambient_set != 0) {
2,123✔
2129
                r = serialize_item_format(f, "exec-context-capability-ambient-set", "%" PRIu64, c->capability_ambient_set);
63✔
2130
                if (r < 0)
63✔
2131
                        return r;
2132
        }
2133

2134
        if (c->user) {
2,123✔
2135
                r = serialize_item(f, "exec-context-user", c->user);
145✔
2136
                if (r < 0)
145✔
2137
                        return r;
2138
        }
2139

2140
        r = serialize_item(f, "exec-context-group", c->group);
2,123✔
2141
        if (r < 0)
2,123✔
2142
                return r;
2143

2144
        r = serialize_bool_elide(f, "exec-context-dynamic-user", c->dynamic_user);
2,123✔
2145
        if (r < 0)
2,123✔
2146
                return r;
2147

2148
        r = serialize_strv(f, "exec-context-supplementary-groups", c->supplementary_groups);
2,123✔
2149
        if (r < 0)
2,123✔
2150
                return r;
2151

2152
        r = serialize_item_tristate(f, "exec-context-set-login-environment", c->set_login_environment);
2,123✔
2153
        if (r < 0)
×
2154
                return r;
2155

2156
        r = serialize_item(f, "exec-context-pam-name", c->pam_name);
2,123✔
2157
        if (r < 0)
2,123✔
2158
                return r;
2159

2160
        r = serialize_strv(f, "exec-context-read-write-paths", c->read_write_paths);
2,123✔
2161
        if (r < 0)
2,123✔
2162
                return r;
2163

2164
        r = serialize_strv(f, "exec-context-read-only-paths", c->read_only_paths);
2,123✔
2165
        if (r < 0)
2,123✔
2166
                return r;
2167

2168
        r = serialize_strv(f, "exec-context-inaccessible-paths", c->inaccessible_paths);
2,123✔
2169
        if (r < 0)
2,123✔
2170
                return r;
2171

2172
        r = serialize_strv(f, "exec-context-exec-paths", c->exec_paths);
2,123✔
2173
        if (r < 0)
2,123✔
2174
                return r;
2175

2176
        r = serialize_strv(f, "exec-context-no-exec-paths", c->no_exec_paths);
2,123✔
2177
        if (r < 0)
2,123✔
2178
                return r;
2179

2180
        r = serialize_strv(f, "exec-context-exec-search-path", c->exec_search_path);
2,123✔
2181
        if (r < 0)
2,123✔
2182
                return r;
2183

2184
        r = serialize_item_format(f, "exec-context-mount-propagation-flag", "%lu", c->mount_propagation_flag);
2,123✔
2185
        if (r < 0)
2,123✔
2186
                return r;
2187

2188
        FOREACH_ARRAY(mount, c->bind_mounts, c->n_bind_mounts) {
2,138✔
2189
                _cleanup_free_ char *src_escaped = NULL, *dst_escaped = NULL;
15✔
2190

2191
                src_escaped = shell_escape(mount->source, ":" WHITESPACE);
15✔
2192
                if (!src_escaped)
15✔
2193
                        return log_oom_debug();
×
2194

2195
                dst_escaped = shell_escape(mount->destination, ":" WHITESPACE);
15✔
2196
                if (!dst_escaped)
15✔
2197
                        return log_oom_debug();
×
2198

2199
                r = serialize_item_format(f,
15✔
2200
                                          mount->read_only ? "exec-context-bind-read-only-path" : "exec-context-bind-path",
15✔
2201
                                          "%s%s:%s:%s",
2202
                                          mount->ignore_enoent ? "-" : "",
15✔
2203
                                          src_escaped,
2204
                                          dst_escaped,
2205
                                          mount->recursive ? "rbind" : "norbind");
15✔
2206
                if (r < 0)
15✔
2207
                        return r;
2208
        }
2209

2210
        FOREACH_ARRAY(tmpfs, c->temporary_filesystems, c->n_temporary_filesystems) {
2,127✔
2211
                _cleanup_free_ char *escaped = NULL;
4✔
2212

2213
                if (!isempty(tmpfs->options)) {
4✔
2214
                        escaped = shell_escape(tmpfs->options, ":");
×
2215
                        if (!escaped)
×
2216
                                return log_oom_debug();
×
2217
                }
2218

2219
                r = serialize_item_format(f, "exec-context-temporary-filesystems", "%s%s%s",
×
2220
                                          tmpfs->path,
2221
                                          isempty(escaped) ? "" : ":",
4✔
2222
                                          strempty(escaped));
2223
                if (r < 0)
4✔
2224
                        return r;
2225
        }
2226

2227
        r = serialize_item(f, "exec-context-utmp-id", c->utmp_id);
2,123✔
2228
        if (r < 0)
2,123✔
2229
                return r;
2230

2231
        r = serialize_item(f, "exec-context-utmp-mode", exec_utmp_mode_to_string(c->utmp_mode));
2,123✔
2232
        if (r < 0)
2,123✔
2233
                return r;
2234

2235
        r = serialize_bool_elide(f, "exec-context-no-new-privileges", c->no_new_privileges);
2,123✔
2236
        if (r < 0)
2,123✔
2237
                return r;
2238

2239
        if (c->selinux_context) {
2,123✔
2240
                r = serialize_item_format(f, "exec-context-selinux-context",
×
2241
                                          "%s%s",
2242
                                          c->selinux_context_ignore ? "-" : "",
×
2243
                                          c->selinux_context);
2244
                if (r < 0)
×
2245
                        return r;
2246
        }
2247

2248
        if (c->apparmor_profile) {
2,123✔
2249
                r = serialize_item_format(f, "exec-context-apparmor-profile",
×
2250
                                          "%s%s",
2251
                                          c->apparmor_profile_ignore ? "-" : "",
×
2252
                                          c->apparmor_profile);
2253
                if (r < 0)
×
2254
                        return r;
2255
        }
2256

2257
        if (c->smack_process_label) {
2,123✔
2258
                r = serialize_item_format(f, "exec-context-smack-process-label",
×
2259
                                          "%s%s",
2260
                                          c->smack_process_label_ignore ? "-" : "",
×
2261
                                          c->smack_process_label);
2262
                if (r < 0)
×
2263
                        return r;
2264
        }
2265

2266
        if (c->personality != PERSONALITY_INVALID) {
2,123✔
2267
                r = serialize_item(f, "exec-context-personality", personality_to_string(c->personality));
×
2268
                if (r < 0)
×
2269
                        return r;
2270
        }
2271

2272
        r = serialize_bool_elide(f, "exec-context-lock-personality", c->lock_personality);
2,123✔
2273
        if (r < 0)
2,123✔
2274
                return r;
2275

2276
#if HAVE_SECCOMP
2277
        if (!hashmap_isempty(c->syscall_filter)) {
2,123✔
2278
                void *errno_num, *id;
211✔
2279
                HASHMAP_FOREACH_KEY(errno_num, id, c->syscall_filter) {
82,707✔
2280
                        r = serialize_item_format(f, "exec-context-syscall-filter", "%d %d", PTR_TO_INT(id) - 1, PTR_TO_INT(errno_num));
82,496✔
2281
                        if (r < 0)
82,496✔
2282
                                return r;
×
2283
                }
2284
        }
2285

2286
        if (!set_isempty(c->syscall_archs)) {
2,123✔
2287
                void *id;
211✔
2288
                SET_FOREACH(id, c->syscall_archs) {
422✔
2289
                        r = serialize_item_format(f, "exec-context-syscall-archs", "%u", PTR_TO_UINT(id) - 1);
211✔
2290
                        if (r < 0)
211✔
2291
                                return r;
×
2292
                }
2293
        }
2294

2295
        if (c->syscall_errno > 0) {
2,123✔
2296
                r = serialize_item_format(f, "exec-context-syscall-errno", "%d", c->syscall_errno);
2,123✔
2297
                if (r < 0)
2,123✔
2298
                        return r;
2299
        }
2300

2301
        r = serialize_bool_elide(f, "exec-context-syscall-allow-list", c->syscall_allow_list);
2,123✔
2302
        if (r < 0)
2,123✔
2303
                return r;
2304

2305
        if (!hashmap_isempty(c->syscall_log)) {
2,123✔
2306
                void *errno_num, *id;
×
2307
                HASHMAP_FOREACH_KEY(errno_num, id, c->syscall_log) {
×
2308
                        r = serialize_item_format(f, "exec-context-syscall-log", "%d %d", PTR_TO_INT(id) - 1, PTR_TO_INT(errno_num));
×
2309
                        if (r < 0)
×
2310
                                return r;
×
2311
                }
2312
        }
2313

2314
        r = serialize_bool_elide(f, "exec-context-syscall-log-allow-list", c->syscall_log_allow_list);
2,123✔
2315
        if (r < 0)
2,123✔
2316
                return r;
2317
#endif
2318

2319
        if (c->restrict_namespaces != NAMESPACE_FLAGS_INITIAL) {
2,123✔
2320
                r = serialize_item_format(f, "exec-context-restrict-namespaces", "%lu", c->restrict_namespaces);
167✔
2321
                if (r < 0)
167✔
2322
                        return r;
2323
        }
2324

2325
        if (c->delegate_namespaces != NAMESPACE_FLAGS_INITIAL) {
2,123✔
2326
                r = serialize_item_format(f, "exec-context-delegate-namespaces", "%lu", c->delegate_namespaces);
9✔
2327
                if (r < 0)
9✔
2328
                        return r;
2329
        }
2330

2331
#if HAVE_LIBBPF
2332
        if (exec_context_restrict_filesystems_set(c)) {
2,123✔
2333
                char *fs;
×
2334
                SET_FOREACH(fs, c->restrict_filesystems) {
×
2335
                        r = serialize_item(f, "exec-context-restrict-filesystems", fs);
×
2336
                        if (r < 0)
×
2337
                                return r;
×
2338
                }
2339
        }
2340

2341
        r = serialize_bool_elide(f, "exec-context-restrict-filesystems-allow-list", c->restrict_filesystems_allow_list);
2,123✔
2342
        if (r < 0)
2,123✔
2343
                return r;
2344
#endif
2345

2346
        if (!set_isempty(c->address_families)) {
2,123✔
2347
                void *afp;
211✔
2348

2349
                SET_FOREACH(afp, c->address_families) {
1,033✔
2350
                        int af = PTR_TO_INT(afp);
822✔
2351

2352
                        if (af <= 0 || af >= af_max())
822✔
2353
                                continue;
×
2354

2355
                        r = serialize_item_format(f, "exec-context-address-families", "%d", af);
822✔
2356
                        if (r < 0)
822✔
2357
                                return r;
×
2358
                }
2359
        }
2360

2361
        r = serialize_bool_elide(f, "exec-context-address-families-allow-list", c->address_families_allow_list);
2,123✔
2362
        if (r < 0)
2,123✔
2363
                return r;
2364

2365
        r = serialize_item(f, "exec-context-network-namespace-path", c->network_namespace_path);
2,123✔
2366
        if (r < 0)
2,123✔
2367
                return r;
2368

2369
        r = serialize_item(f, "exec-context-ipc-namespace-path", c->ipc_namespace_path);
2,123✔
2370
        if (r < 0)
2,123✔
2371
                return r;
2372

2373
        FOREACH_ARRAY(mount, c->mount_images, c->n_mount_images) {
2,123✔
2374
                _cleanup_free_ char *s = NULL, *source_escaped = NULL, *dest_escaped = NULL;
×
2375

2376
                source_escaped = shell_escape(mount->source, WHITESPACE);
×
2377
                if (!source_escaped)
×
2378
                        return log_oom_debug();
×
2379

2380
                dest_escaped = shell_escape(mount->destination, WHITESPACE);
×
2381
                if (!dest_escaped)
×
2382
                        return log_oom_debug();
×
2383

2384
                s = strjoin(mount->ignore_enoent ? "-" : "",
×
2385
                            source_escaped,
2386
                            " ",
2387
                            dest_escaped);
2388
                if (!s)
×
2389
                        return log_oom_debug();
×
2390

2391
                LIST_FOREACH(mount_options, o, mount->mount_options) {
×
2392
                        _cleanup_free_ char *escaped = NULL;
×
2393

2394
                        if (isempty(o->options))
×
2395
                                continue;
×
2396

2397
                        escaped = shell_escape(o->options, ":");
×
2398
                        if (!escaped)
×
2399
                                return log_oom_debug();
×
2400

2401
                        if (!strextend(&s,
×
2402
                                       " ",
2403
                                       partition_designator_to_string(o->partition_designator),
2404
                                       ":",
2405
                                       escaped))
2406
                                return log_oom_debug();
×
2407
                }
2408

2409
                r = serialize_item(f, "exec-context-mount-image", s);
×
2410
                if (r < 0)
×
2411
                        return r;
2412
        }
2413

2414
        FOREACH_ARRAY(mount, c->extension_images, c->n_extension_images) {
2,128✔
2415
                _cleanup_free_ char *s = NULL, *source_escaped = NULL;
5✔
2416

2417
                source_escaped = shell_escape(mount->source, ":" WHITESPACE);
5✔
2418
                if (!source_escaped)
5✔
2419
                        return log_oom_debug();
×
2420

2421
                s = strjoin(mount->ignore_enoent ? "-" : "",
10✔
2422
                            source_escaped);
2423
                if (!s)
5✔
2424
                        return log_oom_debug();
×
2425

2426
                LIST_FOREACH(mount_options, o, mount->mount_options) {
5✔
2427
                        _cleanup_free_ char *escaped = NULL;
×
2428

2429
                        if (isempty(o->options))
×
2430
                                continue;
×
2431

2432
                        escaped = shell_escape(o->options, ":");
×
2433
                        if (!escaped)
×
2434
                                return log_oom_debug();
×
2435

2436
                        if (!strextend(&s,
×
2437
                                       " ",
2438
                                       partition_designator_to_string(o->partition_designator),
2439
                                       ":",
2440
                                       escaped))
2441
                                return log_oom_debug();
×
2442
                }
2443

2444
                r = serialize_item(f, "exec-context-extension-image", s);
5✔
2445
                if (r < 0)
5✔
2446
                        return r;
2447
        }
2448

2449
        r = serialize_strv(f, "exec-context-extension-directories", c->extension_directories);
2,123✔
2450
        if (r < 0)
2,123✔
2451
                return r;
2452

2453
        ExecSetCredential *sc;
2,123✔
2454
        HASHMAP_FOREACH(sc, c->set_credentials) {
2,123✔
2455
                _cleanup_free_ char *data = NULL;
×
2456

2457
                if (base64mem(sc->data, sc->size, &data) < 0)
×
2458
                        return log_oom_debug();
×
2459

2460
                r = serialize_item_format(f, "exec-context-set-credentials", "%s %s %s", sc->id, data, yes_no(sc->encrypted));
×
2461
                if (r < 0)
×
2462
                        return r;
2463
        }
2464

2465
        ExecLoadCredential *lc;
2,123✔
2466
        HASHMAP_FOREACH(lc, c->load_credentials) {
2,131✔
2467
                r = serialize_item_format(f, "exec-context-load-credentials", "%s %s %s", lc->id, lc->path, yes_no(lc->encrypted));
15✔
2468
                if (r < 0)
8✔
2469
                        return r;
×
2470
        }
2471

2472
        ExecImportCredential *ic;
2,123✔
2473
        ORDERED_SET_FOREACH(ic, c->import_credentials) {
3,029✔
2474
                r = serialize_item_format(f, "exec-context-import-credentials", "%s%s%s",
1,764✔
2475
                                          ic->glob,
2476
                                          ic->rename ? " " : "",
2477
                                          strempty(ic->rename));
906✔
2478
                if (r < 0)
906✔
2479
                        return r;
×
2480
        }
2481

2482
        r = serialize_image_policy(f, "exec-context-root-image-policy", c->root_image_policy);
2,123✔
2483
        if (r < 0)
2,123✔
2484
                return r;
2485

2486
        r = serialize_image_policy(f, "exec-context-mount-image-policy", c->mount_image_policy);
2,123✔
2487
        if (r < 0)
2,123✔
2488
                return r;
2489

2490
        r = serialize_image_policy(f, "exec-context-extension-image-policy", c->extension_image_policy);
2,123✔
2491
        if (r < 0)
2,123✔
2492
                return r;
2493

2494
        fputc('\n', f); /* End marker */
2,123✔
2495

2496
        return 0;
2497
}
2498

2499
static int exec_context_deserialize(ExecContext *c, FILE *f) {
11,925✔
2500
        int r;
11,925✔
2501

2502
        assert(f);
11,925✔
2503

2504
        if (!c)
11,925✔
2505
                return 0;
2506

2507
        for (;;) {
1,310,919✔
2508
                _cleanup_free_ char *l = NULL;
1,298,994✔
2509
                const char *val;
1,310,919✔
2510

2511
                r = deserialize_read_line(f, &l);
1,310,919✔
2512
                if (r < 0)
1,310,919✔
2513
                        return r;
2514
                if (r == 0) /* eof or end marker */
1,310,919✔
2515
                        break;
2516

2517
                if ((val = startswith(l, "exec-context-environment="))) {
1,298,994✔
2518
                        r = deserialize_strv(val, &c->environment);
3,876✔
2519
                        if (r < 0)
3,876✔
2520
                                return r;
2521
                } else if ((val = startswith(l, "exec-context-environment-files="))) {
1,295,118✔
2522
                        r = deserialize_strv(val, &c->environment_files);
341✔
2523
                        if (r < 0)
341✔
2524
                                return r;
2525
                } else if ((val = startswith(l, "exec-context-pass-environment="))) {
1,294,777✔
2526
                        r = deserialize_strv(val, &c->pass_environment);
443✔
2527
                        if (r < 0)
443✔
2528
                                return r;
2529
                } else if ((val = startswith(l, "exec-context-unset-environment="))) {
1,294,334✔
2530
                        r = deserialize_strv(val, &c->unset_environment);
1,672✔
2531
                        if (r < 0)
1,672✔
2532
                                return r;
2533
                } else if ((val = startswith(l, "exec-context-working-directory="))) {
1,292,662✔
2534
                        ssize_t k;
740✔
2535
                        char *p;
740✔
2536

2537
                        k = cunescape(val, 0, &p);
740✔
2538
                        if (k < 0)
740✔
2539
                                return k;
×
2540
                        free_and_replace(c->working_directory, p);
740✔
2541
                } else if ((val = startswith(l, "exec-context-root-directory="))) {
1,291,922✔
2542
                        ssize_t k;
7✔
2543
                        char *p;
7✔
2544

2545
                        k = cunescape(val, 0, &p);
7✔
2546
                        if (k < 0)
7✔
2547
                                return k;
×
2548
                        free_and_replace(c->root_directory, p);
7✔
2549
                } else if ((val = startswith(l, "exec-context-root-image="))) {
1,291,915✔
2550
                        ssize_t k;
9✔
2551
                        char *p;
9✔
2552

2553
                        k = cunescape(val, 0, &p);
9✔
2554
                        if (k < 0)
9✔
2555
                                return k;
×
2556
                        free_and_replace(c->root_image, p);
9✔
2557
                } else if ((val = startswith(l, "exec-context-root-image-options="))) {
1,291,906✔
2558
                        for (;;) {
×
2559
                                _cleanup_free_ char *word = NULL, *mount_options = NULL, *partition = NULL;
×
2560
                                PartitionDesignator partition_designator;
×
2561
                                MountOptions *o = NULL;
×
2562
                                const char *p;
×
2563

2564
                                r = extract_first_word(&val, &word, NULL, 0);
×
2565
                                if (r < 0)
×
2566
                                        return r;
2567
                                if (r == 0)
×
2568
                                        break;
2569

2570
                                p = word;
×
2571
                                r = extract_many_words(&p, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &partition, &mount_options);
×
2572
                                if (r < 0)
×
2573
                                        return r;
2574
                                if (r == 0)
×
2575
                                        continue;
×
2576

2577
                                partition_designator = partition_designator_from_string(partition);
×
2578
                                if (partition_designator < 0)
×
2579
                                        return -EINVAL;
2580

2581
                                o = new(MountOptions, 1);
×
2582
                                if (!o)
×
2583
                                        return log_oom_debug();
×
2584
                                *o = (MountOptions) {
×
2585
                                        .partition_designator = partition_designator,
2586
                                        .options = TAKE_PTR(mount_options),
×
2587
                                };
2588
                                LIST_APPEND(mount_options, c->root_image_options, o);
×
2589
                        }
2590
                } else if ((val = startswith(l, "exec-context-root-verity="))) {
1,291,906✔
2591
                        r = free_and_strdup(&c->root_verity, val);
×
2592
                        if (r < 0)
×
2593
                                return r;
2594
                } else if ((val = startswith(l, "exec-context-root-hash-path="))) {
1,291,906✔
2595
                        r = free_and_strdup(&c->root_hash_path, val);
×
2596
                        if (r < 0)
×
2597
                                return r;
2598
                } else if ((val = startswith(l, "exec-context-root-hash-sig-path="))) {
1,291,906✔
2599
                        r = free_and_strdup(&c->root_hash_sig_path, val);
×
2600
                        if (r < 0)
×
2601
                                return r;
2602
                } else if ((val = startswith(l, "exec-context-root-hash="))) {
1,291,906✔
2603
                        c->root_hash = mfree(c->root_hash);
4✔
2604
                        r = unhexmem(val, &c->root_hash, &c->root_hash_size);
4✔
2605
                        if (r < 0)
4✔
2606
                                return r;
2607
                } else if ((val = startswith(l, "exec-context-root-hash-sig="))) {
1,291,902✔
2608
                        c->root_hash_sig = mfree(c->root_hash_sig);
×
2609
                        r= unbase64mem(val, &c->root_hash_sig, &c->root_hash_sig_size);
×
2610
                        if (r < 0)
×
2611
                                return r;
2612
                } else if ((val = startswith(l, "exec-context-root-ephemeral="))) {
1,291,902✔
2613
                        r = parse_boolean(val);
×
2614
                        if (r < 0)
×
2615
                                return r;
2616
                        c->root_ephemeral = r;
×
2617
                } else if ((val = startswith(l, "exec-context-umask="))) {
1,291,902✔
2618
                        r = parse_mode(val, &c->umask);
11,925✔
2619
                        if (r < 0)
11,925✔
2620
                                return r;
2621
                } else if ((val = startswith(l, "exec-context-private-non-blocking="))) {
1,279,977✔
2622
                        r = parse_boolean(val);
×
2623
                        if (r < 0)
×
2624
                                return r;
2625
                        c->non_blocking = r;
×
2626
                } else if ((val = startswith(l, "exec-context-private-mounts="))) {
1,279,977✔
2627
                        r = safe_atoi(val, &c->private_mounts);
135✔
2628
                        if (r < 0)
135✔
2629
                                return r;
2630
                } else if ((val = startswith(l, "exec-context-mount-api-vfs="))) {
1,279,842✔
2631
                        r = safe_atoi(val, &c->mount_apivfs);
29✔
2632
                        if (r < 0)
29✔
2633
                                return r;
2634
                } else if ((val = startswith(l, "exec-context-bind-log-sockets="))) {
1,279,813✔
2635
                        r = safe_atoi(val, &c->bind_log_sockets);
2✔
2636
                        if (r < 0)
2✔
2637
                                return r;
2638
                } else if ((val = startswith(l, "exec-context-memory-ksm="))) {
1,279,811✔
2639
                        r = safe_atoi(val, &c->memory_ksm);
×
2640
                        if (r < 0)
×
2641
                                return r;
2642
                } else if ((val = startswith(l, "exec-context-private-tmp="))) {
1,279,811✔
2643
                        c->private_tmp = private_tmp_from_string(val);
11,925✔
2644
                        if (c->private_tmp < 0)
11,925✔
2645
                                return c->private_tmp;
2646
                } else if ((val = startswith(l, "exec-context-private-var-tmp="))) {
1,267,886✔
2647
                        c->private_var_tmp = private_tmp_from_string(val);
11,925✔
2648
                        if (c->private_var_tmp < 0)
11,925✔
2649
                                return c->private_var_tmp;
2650
                } else if ((val = startswith(l, "exec-context-private-devices="))) {
1,255,961✔
2651
                        r = parse_boolean(val);
659✔
2652
                        if (r < 0)
659✔
2653
                                return r;
2654
                        c->private_devices = r;
659✔
2655
                } else if ((val = startswith(l, "exec-context-protect-kernel-tunables="))) {
1,255,302✔
2656
                        r = parse_boolean(val);
475✔
2657
                        if (r < 0)
475✔
2658
                                return r;
2659
                        c->protect_kernel_tunables = r;
475✔
2660
                } else if ((val = startswith(l, "exec-context-protect-kernel-modules="))) {
1,254,827✔
2661
                        r = parse_boolean(val);
1,694✔
2662
                        if (r < 0)
1,694✔
2663
                                return r;
2664
                        c->protect_kernel_modules = r;
1,694✔
2665
                } else if ((val = startswith(l, "exec-context-protect-kernel-logs="))) {
1,253,133✔
2666
                        r = parse_boolean(val);
1,694✔
2667
                        if (r < 0)
1,694✔
2668
                                return r;
2669
                        c->protect_kernel_logs = r;
1,694✔
2670
                } else if ((val = startswith(l, "exec-context-protect-clock="))) {
1,251,439✔
2671
                        r = parse_boolean(val);
1,611✔
2672
                        if (r < 0)
1,611✔
2673
                                return r;
2674
                        c->protect_clock = r;
1,611✔
2675
                } else if ((val = startswith(l, "exec-context-protect-control-groups="))) {
1,249,828✔
2676
                        r = protect_control_groups_from_string(val);
11,925✔
2677
                        if (r < 0)
11,925✔
2678
                                return r;
2679
                        c->protect_control_groups = r;
11,925✔
2680
                } else if ((val = startswith(l, "exec-context-private-network="))) {
1,237,903✔
2681
                        r = parse_boolean(val);
66✔
2682
                        if (r < 0)
66✔
2683
                                return r;
2684
                        c->private_network = r;
66✔
2685
                } else if ((val = startswith(l, "exec-context-private-users="))) {
1,237,837✔
2686
                        c->private_users = private_users_from_string(val);
11,925✔
2687
                        if (c->private_users < 0)
11,925✔
2688
                                return -EINVAL;
2689
                } else if ((val = startswith(l, "exec-context-private-ipc="))) {
1,225,912✔
2690
                        r = parse_boolean(val);
6✔
2691
                        if (r < 0)
6✔
2692
                                return r;
2693
                        c->private_ipc = r;
6✔
2694
                } else if ((val = startswith(l, "exec-context-private-pids="))) {
1,225,906✔
2695
                        c->private_pids = private_pids_from_string(val);
11,925✔
2696
                        if (c->private_pids < 0)
11,925✔
2697
                                return -EINVAL;
2698
                } else if ((val = startswith(l, "exec-context-remove-ipc="))) {
1,213,981✔
2699
                        r = parse_boolean(val);
70✔
2700
                        if (r < 0)
70✔
2701
                                return r;
2702
                        c->remove_ipc = r;
70✔
2703
                } else if ((val = startswith(l, "exec-context-protect-home="))) {
1,213,911✔
2704
                        c->protect_home = protect_home_from_string(val);
11,925✔
2705
                        if (c->protect_home < 0)
11,925✔
2706
                                return -EINVAL;
2707
                } else if ((val = startswith(l, "exec-context-protect-system="))) {
1,201,986✔
2708
                        c->protect_system = protect_system_from_string(val);
11,925✔
2709
                        if (c->protect_system < 0)
11,925✔
2710
                                return -EINVAL;
2711
                } else if ((val = startswith(l, "exec-context-same-pgrp="))) {
1,190,061✔
2712
                        r = parse_boolean(val);
828✔
2713
                        if (r < 0)
828✔
2714
                                return r;
2715
                        c->same_pgrp = r;
828✔
2716
                } else if ((val = startswith(l, "exec-context-non-blocking="))) {
1,189,233✔
2717
                        r = parse_boolean(val);
×
2718
                        if (r < 0)
×
2719
                                return r;
2720
                        c->non_blocking = r;
×
2721
                } else if ((val = startswith(l, "exec-context-ignore-sigpipe="))) {
1,189,233✔
2722
                        r = parse_boolean(val);
11,925✔
2723
                        if (r < 0)
11,925✔
2724
                                return r;
2725
                        c->ignore_sigpipe = r;
11,925✔
2726
                } else if ((val = startswith(l, "exec-context-memory-deny-write-execute="))) {
1,177,308✔
2727
                        r = parse_boolean(val);
2,177✔
2728
                        if (r < 0)
2,177✔
2729
                                return r;
2730
                        c->memory_deny_write_execute = r;
2,177✔
2731
                } else if ((val = startswith(l, "exec-context-restrict-realtime="))) {
1,175,131✔
2732
                        r = parse_boolean(val);
2,179✔
2733
                        if (r < 0)
2,179✔
2734
                                return r;
2735
                        c->restrict_realtime = r;
2,179✔
2736
                } else if ((val = startswith(l, "exec-context-restrict-suid-sgid="))) {
1,172,952✔
2737
                        r = parse_boolean(val);
2,098✔
2738
                        if (r < 0)
2,098✔
2739
                                return r;
2740
                        c->restrict_suid_sgid = r;
2,098✔
2741
                } else if ((val = startswith(l, "exec-context-keyring-mode="))) {
1,170,854✔
2742
                        c->keyring_mode = exec_keyring_mode_from_string(val);
11,925✔
2743
                        if (c->keyring_mode < 0)
11,925✔
2744
                                return -EINVAL;
2745
                } else if ((val = startswith(l, "exec-context-protect-hostname="))) {
1,158,929✔
2746
                        c->protect_hostname = protect_hostname_from_string(val);
11,925✔
2747
                        if (c->protect_hostname < 0)
11,925✔
2748
                                return -EINVAL;
2749
                } else if ((val = startswith(l, "exec-context-private-hostname="))) {
1,147,004✔
2750
                        r = free_and_strdup(&c->private_hostname, val);
5✔
2751
                        if (r < 0)
5✔
2752
                                return r;
2753
                } else if ((val = startswith(l, "exec-context-protect-proc="))) {
1,146,999✔
2754
                        c->protect_proc = protect_proc_from_string(val);
11,925✔
2755
                        if (c->protect_proc < 0)
11,925✔
2756
                                return -EINVAL;
2757
                } else if ((val = startswith(l, "exec-context-proc-subset="))) {
1,135,074✔
2758
                        c->proc_subset = proc_subset_from_string(val);
11,925✔
2759
                        if (c->proc_subset < 0)
11,925✔
2760
                                return -EINVAL;
2761
                } else if ((val = startswith(l, "exec-context-private-bpf="))) {
1,123,149✔
2762
                        c->private_bpf = private_bpf_from_string(val);
11,925✔
2763
                        if (c->private_bpf < 0)
11,925✔
2764
                                return -EINVAL;
2765
                } else if ((val = startswith(l, "exec-context-bpf-delegate-commands="))) {
1,111,224✔
2766
                        r = safe_atoux64(val, &c->bpf_delegate_commands);
2✔
2767
                        if (r < 0)
2✔
2768
                                return r;
2769
                } else if ((val = startswith(l, "exec-context-bpf-delegate-maps="))) {
1,111,222✔
2770
                        r = safe_atoux64(val, &c->bpf_delegate_maps);
1✔
2771
                        if (r < 0)
1✔
2772
                                return r;
2773
                } else if ((val = startswith(l, "exec-context-bpf-delegate-programs="))) {
1,111,221✔
2774
                        r = safe_atoux64(val, &c->bpf_delegate_programs);
1✔
2775
                        if (r < 0)
1✔
2776
                                return r;
2777
                } else if ((val = startswith(l, "exec-context-bpf-delegate-attachments="))) {
1,111,220✔
2778
                        r = safe_atoux64(val, &c->bpf_delegate_attachments);
1✔
2779
                        if (r < 0)
1✔
2780
                                return r;
2781
                } else if ((val = startswith(l, "exec-context-runtime-directory-preserve-mode="))) {
1,111,219✔
2782
                        c->runtime_directory_preserve_mode = exec_preserve_mode_from_string(val);
11,925✔
2783
                        if (c->runtime_directory_preserve_mode < 0)
11,925✔
2784
                                return -EINVAL;
2785
                } else if ((val = startswith(l, "exec-context-directories-"))) {
1,099,294✔
2786
                        _cleanup_free_ char *type = NULL, *mode = NULL;
×
2787
                        ExecDirectoryType dt;
59,625✔
2788

2789
                        r = extract_many_words(&val, "= ", 0, &type, &mode);
59,625✔
2790
                        if (r < 0)
59,625✔
2791
                                return r;
2792
                        if (r == 0 || !mode)
59,625✔
2793
                                return -EINVAL;
2794

2795
                        dt = exec_directory_type_from_string(type);
59,625✔
2796
                        if (dt < 0)
59,625✔
2797
                                return dt;
2798

2799
                        r = parse_mode(mode, &c->directories[dt].mode);
59,625✔
2800
                        if (r < 0)
59,625✔
2801
                                return r;
2802

2803
                        for (;;) {
63,269✔
2804
                                _cleanup_free_ char *tuple = NULL, *path = NULL, *only_create = NULL, *read_only = NULL;
63,162✔
2805
                                ExecDirectoryFlags exec_directory_flags = 0;
63,269✔
2806
                                const char *p;
63,269✔
2807

2808
                                /* Use EXTRACT_UNESCAPE_RELAX here, as we unescape the colons in subsequent calls */
2809
                                r = extract_first_word(&val, &tuple, WHITESPACE, EXTRACT_UNESCAPE_SEPARATORS|EXTRACT_UNESCAPE_RELAX);
63,269✔
2810
                                if (r < 0)
63,269✔
2811
                                        return r;
2812
                                if (r == 0)
63,269✔
2813
                                        break;
2814

2815
                                p = tuple;
3,644✔
2816
                                r = extract_many_words(&p, ":", EXTRACT_UNESCAPE_SEPARATORS, &path, &only_create, &read_only);
3,644✔
2817
                                if (r < 0)
3,644✔
2818
                                        return r;
2819
                                if (r < 2)
3,644✔
2820
                                        continue;
×
2821

2822
                                r = parse_boolean(only_create);
3,644✔
2823
                                if (r < 0)
3,644✔
2824
                                        return r;
2825
                                if (r > 0)
3,644✔
2826
                                        exec_directory_flags |= EXEC_DIRECTORY_ONLY_CREATE;
5✔
2827

2828
                                r = parse_boolean(read_only);
3,644✔
2829
                                if (r < 0)
3,644✔
2830
                                        return r;
2831
                                if (r > 0)
3,644✔
2832
                                        exec_directory_flags |= EXEC_DIRECTORY_READ_ONLY;
50✔
2833

2834
                                r = exec_directory_add(&c->directories[dt], path, /* symlink= */ NULL, exec_directory_flags);
3,644✔
2835
                                if (r < 0)
3,644✔
2836
                                        return r;
2837

2838
                                if (isempty(p))
3,644✔
2839
                                        continue;
3,537✔
2840

2841
                                for (;;) {
385✔
2842
                                        _cleanup_free_ char *link = NULL;
246✔
2843

2844
                                        r = extract_first_word(&p, &link, ":", EXTRACT_UNESCAPE_SEPARATORS);
246✔
2845
                                        if (r < 0)
246✔
2846
                                                return r;
2847
                                        if (r == 0)
246✔
2848
                                                break;
2849

2850
                                        r = strv_consume(&c->directories[dt].items[c->directories[dt].n_items - 1].symlinks, TAKE_PTR(link));
139✔
2851
                                        if (r < 0)
139✔
2852
                                                return r;
2853
                                }
2854
                        }
2855
                } else if ((val = startswith(l, "exec-context-quota-accounting-directories-"))) {
1,039,669✔
2856
                        _cleanup_free_ char *type = NULL, *quota_accounting = NULL;
×
2857
                        ExecDirectoryType dt;
×
2858

2859
                        r = split_pair(val, "=", &type, &quota_accounting);
×
2860
                        if (r < 0)
×
2861
                                return r;
2862

2863
                        dt = exec_directory_type_from_string(type);
×
2864
                        if (dt < 0)
×
2865
                                return dt;
2866

2867
                        r = parse_boolean(quota_accounting);
×
2868
                        if (r < 0)
×
2869
                                return r;
2870

2871
                        c->directories[dt].exec_quota.quota_accounting = r;
×
2872
                } else if ((val = startswith(l, "exec-context-quota-directories-"))) {
1,039,669✔
2873
                        _cleanup_free_ char *type = NULL, *quota_info = NULL, *quota_absolute = NULL, *quota_scale = NULL;
×
2874
                        ExecDirectoryType dt;
×
2875

2876
                        r = split_pair(val, "=", &type, &quota_info);
×
2877
                        if (r < 0)
×
2878
                                return r;
2879

2880
                        r = split_pair(quota_info, " ", &quota_absolute, &quota_scale);
×
2881
                        if (r < 0)
×
2882
                                return r;
2883

2884
                        dt = exec_directory_type_from_string(type);
×
2885
                        if (dt < 0)
×
2886
                                return dt;
2887

2888
                        r = safe_atou64(quota_absolute, &c->directories[dt].exec_quota.quota_absolute);
×
2889
                        if (r < 0)
×
2890
                               return r;
2891

2892
                        r = safe_atou32(quota_scale, &c->directories[dt].exec_quota.quota_scale);
×
2893
                        if (r < 0)
×
2894
                               return r;
2895

2896
                        c->directories[dt].exec_quota.quota_enforce = true;
×
2897
                } else if ((val = startswith(l, "exec-context-timeout-clean-usec="))) {
1,039,669✔
2898
                        r = deserialize_usec(val, &c->timeout_clean_usec);
×
2899
                        if (r < 0)
×
2900
                                return r;
2901
                } else if ((val = startswith(l, "exec-context-nice="))) {
1,039,669✔
2902
                        r = safe_atoi(val, &c->nice);
19✔
2903
                        if (r < 0)
19✔
2904
                                return r;
2905
                        c->nice_set = true;
19✔
2906
                } else if ((val = startswith(l, "exec-context-working-directory-missing-ok="))) {
1,039,650✔
2907
                        r = parse_boolean(val);
680✔
2908
                        if (r < 0)
680✔
2909
                                return r;
2910
                        c->working_directory_missing_ok = r;
680✔
2911
                } else if ((val = startswith(l, "exec-context-working-directory-home="))) {
1,038,970✔
2912
                        r = parse_boolean(val);
173✔
2913
                        if (r < 0)
173✔
2914
                                return r;
2915
                        c->working_directory_home = r;
173✔
2916
                } else if ((val = startswith(l, "exec-context-oom-score-adjust="))) {
1,038,797✔
2917
                        r = safe_atoi(val, &c->oom_score_adjust);
1,220✔
2918
                        if (r < 0)
1,220✔
2919
                                return r;
2920
                        c->oom_score_adjust_set = true;
1,220✔
2921
                } else if ((val = startswith(l, "exec-context-coredump-filter="))) {
1,037,577✔
2922
                        r = safe_atoux64(val, &c->coredump_filter);
2✔
2923
                        if (r < 0)
2✔
2924
                                return r;
2925
                        c->coredump_filter_set = true;
2✔
2926
                } else if ((val = startswith(l, "exec-context-limit-"))) {
1,037,575✔
2927
                        _cleanup_free_ struct rlimit *rlimit = NULL;
×
2928
                        _cleanup_free_ char *limit = NULL;
23,845✔
2929
                        int type;
23,845✔
2930

2931
                        r = extract_first_word(&val, &limit, "=", 0);
23,845✔
2932
                        if (r < 0)
23,845✔
2933
                                return r;
2934
                        if (r == 0 || !val)
23,845✔
2935
                                return -EINVAL;
2936

2937
                        type = rlimit_from_string(limit);
23,845✔
2938
                        if (type < 0)
23,845✔
2939
                                return -EINVAL;
2940

2941
                        if (!c->rlimit[type]) {
23,845✔
2942
                                rlimit = new0(struct rlimit, 1);
23,845✔
2943
                                if (!rlimit)
23,845✔
2944
                                        return log_oom_debug();
×
2945

2946
                                r = rlimit_parse(type, val, rlimit);
23,845✔
2947
                                if (r < 0)
23,845✔
2948
                                        return r;
2949

2950
                                c->rlimit[type] = TAKE_PTR(rlimit);
23,845✔
2951
                        } else {
2952
                                r = rlimit_parse(type, val, c->rlimit[type]);
×
2953
                                if (r < 0)
×
2954
                                        return r;
2955
                        }
2956
                } else if ((val = startswith(l, "exec-context-ioprio="))) {
1,013,730✔
2957
                        r = safe_atoi(val, &c->ioprio);
13✔
2958
                        if (r < 0)
13✔
2959
                                return r;
2960
                        c->ioprio_is_set = true;
13✔
2961
                } else if ((val = startswith(l, "exec-context-cpu-scheduling-policy="))) {
1,013,717✔
2962
                        c->cpu_sched_policy = sched_policy_from_string(val);
×
2963
                        if (c->cpu_sched_policy < 0)
×
2964
                                return -EINVAL;
2965
                        c->cpu_sched_set = true;
×
2966
                } else if ((val = startswith(l, "exec-context-cpu-scheduling-priority="))) {
1,013,717✔
2967
                        r = safe_atoi(val, &c->cpu_sched_priority);
×
2968
                        if (r < 0)
×
2969
                                return r;
2970
                        c->cpu_sched_set = true;
×
2971
                } else if ((val = startswith(l, "exec-context-cpu-scheduling-reset-on-fork="))) {
1,013,717✔
2972
                        r = parse_boolean(val);
×
2973
                        if (r < 0)
×
2974
                                return r;
2975
                        c->cpu_sched_reset_on_fork = r;
×
2976
                        c->cpu_sched_set = true;
×
2977
                } else if ((val = startswith(l, "exec-context-cpu-affinity="))) {
1,013,717✔
2978
                        if (c->cpu_set.set)
×
2979
                                return -EINVAL; /* duplicated */
2980

2981
                        r = parse_cpu_set(val, &c->cpu_set);
×
2982
                        if (r < 0)
×
2983
                                return r;
2984
                } else if ((val = startswith(l, "exec-context-numa-mask="))) {
1,013,717✔
2985
                        if (c->numa_policy.nodes.set)
19✔
2986
                                return -EINVAL; /* duplicated */
2987

2988
                        r = parse_cpu_set(val, &c->numa_policy.nodes);
19✔
2989
                        if (r < 0)
19✔
2990
                                return r;
2991
                } else if ((val = startswith(l, "exec-context-numa-policy="))) {
1,013,698✔
2992
                        r = safe_atoi(val, &c->numa_policy.type);
19✔
2993
                        if (r < 0)
19✔
2994
                                return r;
2995
                } else if ((val = startswith(l, "exec-context-cpu-affinity-from-numa="))) {
1,013,679✔
2996
                        r = parse_boolean(val);
2✔
2997
                        if (r < 0)
2✔
2998
                                return r;
2999
                        c->cpu_affinity_from_numa = r;
2✔
3000
                } else if ((val = startswith(l, "exec-context-timer-slack-nsec="))) {
1,013,677✔
3001
                        r = deserialize_usec(val, (usec_t *)&c->timer_slack_nsec);
×
3002
                        if (r < 0)
×
3003
                                return r;
3004
                } else if ((val = startswith(l, "exec-context-std-input="))) {
1,013,677✔
3005
                        c->std_input = exec_input_from_string(val);
11,925✔
3006
                        if (c->std_input < 0)
11,925✔
3007
                                return c->std_input;
3008
                } else if ((val = startswith(l, "exec-context-std-output="))) {
1,001,752✔
3009
                        c->std_output = exec_output_from_string(val);
11,925✔
3010
                        if (c->std_output < 0)
11,925✔
3011
                                return c->std_output;
3012
                } else if ((val = startswith(l, "exec-context-std-error="))) {
989,827✔
3013
                        c->std_error = exec_output_from_string(val);
11,925✔
3014
                        if (c->std_error < 0)
11,925✔
3015
                                return c->std_error;
3016
                } else if ((val = startswith(l, "exec-context-stdio-as-fds="))) {
977,902✔
3017
                        r = parse_boolean(val);
588✔
3018
                        if (r < 0)
588✔
3019
                                return r;
3020
                        c->stdio_as_fds = r;
588✔
3021
                } else if ((val = startswith(l, "exec-context-root-directory-as-fd="))) {
977,314✔
NEW
3022
                        r = parse_boolean(val);
×
NEW
3023
                        if (r < 0)
×
3024
                                return r;
NEW
3025
                        c->root_directory_as_fd = r;
×
3026
                } else if ((val = startswith(l, "exec-context-std-input-fd-name="))) {
977,314✔
3027
                        r = free_and_strdup(&c->stdio_fdname[STDIN_FILENO], val);
×
3028
                        if (r < 0)
×
3029
                                return r;
3030
                } else if ((val = startswith(l, "exec-context-std-output-fd-name="))) {
977,314✔
3031
                        r = free_and_strdup(&c->stdio_fdname[STDOUT_FILENO], val);
×
3032
                        if (r < 0)
×
3033
                                return r;
3034
                } else if ((val = startswith(l, "exec-context-std-error-fd-name="))) {
977,314✔
3035
                        r = free_and_strdup(&c->stdio_fdname[STDERR_FILENO], val);
×
3036
                        if (r < 0)
×
3037
                                return r;
3038
                } else if ((val = startswith(l, "exec-context-std-input-file="))) {
977,314✔
3039
                        r = free_and_strdup(&c->stdio_file[STDIN_FILENO], val);
×
3040
                        if (r < 0)
×
3041
                                return r;
3042
                } else if ((val = startswith(l, "exec-context-std-output-file="))) {
977,314✔
3043
                        r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], val);
50✔
3044
                        if (r < 0)
50✔
3045
                                return r;
3046
                } else if ((val = startswith(l, "exec-context-std-output-file-append="))) {
977,264✔
3047
                        r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], val);
1✔
3048
                        if (r < 0)
1✔
3049
                                return r;
3050
                } else if ((val = startswith(l, "exec-context-std-output-file-truncate="))) {
977,263✔
3051
                        r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], val);
2✔
3052
                        if (r < 0)
2✔
3053
                                return r;
3054
                } else if ((val = startswith(l, "exec-context-std-error-file="))) {
977,261✔
3055
                        r = free_and_strdup(&c->stdio_file[STDERR_FILENO], val);
47✔
3056
                        if (r < 0)
47✔
3057
                                return r;
3058
                } else if ((val = startswith(l, "exec-context-std-error-file-append="))) {
977,214✔
3059
                        r = free_and_strdup(&c->stdio_file[STDERR_FILENO], val);
1✔
3060
                        if (r < 0)
1✔
3061
                                return r;
3062
                } else if ((val = startswith(l, "exec-context-std-error-file-truncate="))) {
977,213✔
3063
                        r = free_and_strdup(&c->stdio_file[STDERR_FILENO], val);
1✔
3064
                        if (r < 0)
1✔
3065
                                return r;
3066
                } else if ((val = startswith(l, "exec-context-stdin-data="))) {
977,212✔
3067
                        if (c->stdin_data)
1✔
3068
                                return -EINVAL; /* duplicated */
3069

3070
                        r = unbase64mem(val, &c->stdin_data, &c->stdin_data_size);
1✔
3071
                        if (r < 0)
1✔
3072
                                return r;
3073
                } else if ((val = startswith(l, "exec-context-tty-path="))) {
977,211✔
3074
                        r = free_and_strdup(&c->tty_path, val);
190✔
3075
                        if (r < 0)
190✔
3076
                                return r;
3077
                } else if ((val = startswith(l, "exec-context-tty-reset="))) {
977,021✔
3078
                        r = parse_boolean(val);
380✔
3079
                        if (r < 0)
380✔
3080
                                return r;
3081
                        c->tty_reset = r;
380✔
3082
                } else if ((val = startswith(l, "exec-context-tty-vhangup="))) {
976,641✔
3083
                        r = parse_boolean(val);
169✔
3084
                        if (r < 0)
169✔
3085
                                return r;
3086
                        c->tty_vhangup = r;
169✔
3087
                } else if ((val = startswith(l, "exec-context-tty-vt-disallocate="))) {
976,472✔
3088
                        r = parse_boolean(val);
96✔
3089
                        if (r < 0)
96✔
3090
                                return r;
3091
                        c->tty_vt_disallocate = r;
96✔
3092
                } else if ((val = startswith(l, "exec-context-tty-rows="))) {
976,376✔
3093
                        r = safe_atou(val, &c->tty_rows);
11,925✔
3094
                        if (r < 0)
11,925✔
3095
                                return r;
3096
                } else if ((val = startswith(l, "exec-context-tty-columns="))) {
964,451✔
3097
                        r = safe_atou(val, &c->tty_cols);
11,925✔
3098
                        if (r < 0)
11,925✔
3099
                                return r;
3100
                } else if ((val = startswith(l, "exec-context-syslog-priority="))) {
952,526✔
3101
                        r = safe_atoi(val, &c->syslog_priority);
11,925✔
3102
                        if (r < 0)
11,925✔
3103
                                return r;
3104
                } else if ((val = startswith(l, "exec-context-syslog-level-prefix="))) {
940,601✔
3105
                        r = parse_boolean(val);
11,925✔
3106
                        if (r < 0)
11,925✔
3107
                                return r;
3108
                        c->syslog_level_prefix = r;
11,925✔
3109
                } else if ((val = startswith(l, "exec-context-syslog-identifier="))) {
928,676✔
3110
                        r = free_and_strdup(&c->syslog_identifier, val);
×
3111
                        if (r < 0)
×
3112
                                return r;
3113
                } else if ((val = startswith(l, "exec-context-log-level-max="))) {
928,676✔
3114
                        /* See comment in serialization. */
3115
                        r = safe_atoi(val, &c->log_level_max);
11,925✔
3116
                        if (r < 0)
11,925✔
3117
                                return r;
3118
                } else if ((val = startswith(l, "exec-context-log-ratelimit-interval-usec="))) {
916,751✔
3119
                        r = deserialize_usec(val, &c->log_ratelimit.interval);
×
3120
                        if (r < 0)
×
3121
                                return r;
3122
                } else if ((val = startswith(l, "exec-context-log-ratelimit-burst="))) {
916,751✔
3123
                        r = safe_atou(val, &c->log_ratelimit.burst);
×
3124
                        if (r < 0)
×
3125
                                return r;
3126
                } else if ((val = startswith(l, "exec-context-log-filter-allowed-patterns="))) {
916,751✔
3127
                        r = set_put_strdup(&c->log_filter_allowed_patterns, val);
20✔
3128
                        if (r < 0)
20✔
3129
                                return r;
3130
                } else if ((val = startswith(l, "exec-context-log-filter-denied-patterns="))) {
916,731✔
3131
                        r = set_put_strdup(&c->log_filter_denied_patterns, val);
13✔
3132
                        if (r < 0)
13✔
3133
                                return r;
3134
                } else if ((val = startswith(l, "exec-context-log-extra-fields="))) {
916,718✔
3135
                        if (!GREEDY_REALLOC(c->log_extra_fields, c->n_log_extra_fields + 1))
685✔
3136
                                return log_oom_debug();
×
3137

3138
                        c->log_extra_fields[c->n_log_extra_fields++].iov_base = strdup(val);
685✔
3139
                        if (!c->log_extra_fields[c->n_log_extra_fields-1].iov_base)
685✔
3140
                                return log_oom_debug();
×
3141
                } else if ((val = startswith(l, "exec-context-log-namespace="))) {
916,033✔
3142
                        r = free_and_strdup(&c->log_namespace, val);
2✔
3143
                        if (r < 0)
2✔
3144
                                return r;
3145
                } else if ((val = startswith(l, "exec-context-secure-bits="))) {
916,031✔
3146
                        r = safe_atoi(val, &c->secure_bits);
×
3147
                        if (r < 0)
×
3148
                                return r;
3149
                } else if ((val = startswith(l, "exec-context-capability-bounding-set="))) {
916,031✔
3150
                        r = safe_atou64(val, &c->capability_bounding_set);
2,310✔
3151
                        if (r < 0)
2,310✔
3152
                                return r;
3153
                } else if ((val = startswith(l, "exec-context-capability-ambient-set="))) {
913,721✔
3154
                        r = safe_atou64(val, &c->capability_ambient_set);
1,248✔
3155
                        if (r < 0)
1,248✔
3156
                                return r;
3157
                } else if ((val = startswith(l, "exec-context-user="))) {
912,473✔
3158
                        r = free_and_strdup(&c->user, val);
2,656✔
3159
                        if (r < 0)
2,656✔
3160
                                return r;
3161
                } else if ((val = startswith(l, "exec-context-group="))) {
909,817✔
3162
                        r = free_and_strdup(&c->group, val);
73✔
3163
                        if (r < 0)
73✔
3164
                                return r;
3165
                } else if ((val = startswith(l, "exec-context-dynamic-user="))) {
909,744✔
3166
                        r = parse_boolean(val);
62✔
3167
                        if (r < 0)
62✔
3168
                                return r;
3169
                        c->dynamic_user = r;
62✔
3170
                } else if ((val = startswith(l, "exec-context-supplementary-groups="))) {
909,682✔
3171
                        r = deserialize_strv(val, &c->supplementary_groups);
9✔
3172
                        if (r < 0)
9✔
3173
                                return r;
3174
                } else if ((val = startswith(l, "exec-context-set-login-environment="))) {
909,673✔
3175
                        r = safe_atoi(val, &c->set_login_environment);
×
3176
                        if (r < 0)
×
3177
                                return r;
3178
                } else if ((val = startswith(l, "exec-context-pam-name="))) {
909,673✔
3179
                        r = free_and_strdup(&c->pam_name, val);
499✔
3180
                        if (r < 0)
499✔
3181
                                return r;
3182
                } else if ((val = startswith(l, "exec-context-read-write-paths="))) {
909,174✔
3183
                        r = deserialize_strv(val, &c->read_write_paths);
841✔
3184
                        if (r < 0)
841✔
3185
                                return r;
3186
                } else if ((val = startswith(l, "exec-context-read-only-paths="))) {
908,333✔
3187
                        r = deserialize_strv(val, &c->read_only_paths);
2✔
3188
                        if (r < 0)
2✔
3189
                                return r;
3190
                } else if ((val = startswith(l, "exec-context-inaccessible-paths="))) {
908,331✔
3191
                        r = deserialize_strv(val, &c->inaccessible_paths);
5✔
3192
                        if (r < 0)
5✔
3193
                                return r;
3194
                } else if ((val = startswith(l, "exec-context-exec-paths="))) {
908,326✔
3195
                        r = deserialize_strv(val, &c->exec_paths);
1✔
3196
                        if (r < 0)
1✔
3197
                                return r;
3198
                } else if ((val = startswith(l, "exec-context-no-exec-paths="))) {
908,325✔
3199
                        r = deserialize_strv(val, &c->no_exec_paths);
1✔
3200
                        if (r < 0)
1✔
3201
                                return r;
3202
                } else if ((val = startswith(l, "exec-context-exec-search-path="))) {
908,324✔
3203
                        r = deserialize_strv(val, &c->exec_search_path);
×
3204
                        if (r < 0)
×
3205
                                return r;
3206
                } else if ((val = startswith(l, "exec-context-mount-propagation-flag="))) {
908,324✔
3207
                        r = safe_atolu(val, &c->mount_propagation_flag);
11,925✔
3208
                        if (r < 0)
11,925✔
3209
                                return r;
3210
                } else if ((val = startswith(l, "exec-context-bind-read-only-path="))) {
896,399✔
3211
                        _cleanup_free_ char *source = NULL, *destination = NULL;
7✔
3212
                        bool rbind = true, ignore_enoent = false;
7✔
3213
                        char *s = NULL, *d = NULL;
7✔
3214

3215
                        r = extract_first_word(&val,
7✔
3216
                                               &source,
3217
                                               ":" WHITESPACE,
3218
                                               EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3219
                        if (r < 0)
7✔
3220
                                return r;
3221
                        if (r == 0)
7✔
3222
                                return -EINVAL;
3223

3224
                        s = source;
7✔
3225
                        if (s[0] == '-') {
7✔
3226
                                ignore_enoent = true;
1✔
3227
                                s++;
1✔
3228
                        }
3229

3230
                        if (val && val[-1] == ':') {
7✔
3231
                                r = extract_first_word(&val,
7✔
3232
                                                       &destination,
3233
                                                       ":" WHITESPACE,
3234
                                                       EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3235
                                if (r < 0)
7✔
3236
                                        return r;
3237
                                if (r == 0)
7✔
3238
                                        continue;
×
3239

3240
                                d = destination;
7✔
3241

3242
                                if (val && val[-1] == ':') {
7✔
3243
                                        _cleanup_free_ char *options = NULL;
7✔
3244

3245
                                        r = extract_first_word(&val, &options, NULL, EXTRACT_UNQUOTE);
7✔
3246
                                        if (r < 0)
7✔
3247
                                                return -r;
×
3248

3249
                                        if (isempty(options) || streq(options, "rbind"))
15✔
3250
                                                rbind = true;
3251
                                        else if (streq(options, "norbind"))
1✔
3252
                                                rbind = false;
3253
                                        else
3254
                                                continue;
×
3255
                                }
3256
                        } else
3257
                                d = s;
3258

3259
                        r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts,
14✔
3260
                                        &(BindMount) {
7✔
3261
                                                .source = s,
3262
                                                .destination = d,
3263
                                                .read_only = true,
3264
                                                .recursive = rbind,
3265
                                                .ignore_enoent = ignore_enoent,
3266
                                        });
3267
                        if (r < 0)
7✔
3268
                                return log_oom_debug();
×
3269
                } else if ((val = startswith(l, "exec-context-bind-path="))) {
896,392✔
3270
                        _cleanup_free_ char *source = NULL, *destination = NULL;
20✔
3271
                        bool rbind = true, ignore_enoent = false;
20✔
3272
                        char *s = NULL, *d = NULL;
20✔
3273

3274
                        r = extract_first_word(&val,
20✔
3275
                                               &source,
3276
                                               ":" WHITESPACE,
3277
                                               EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3278
                        if (r < 0)
20✔
3279
                                return r;
3280
                        if (r == 0)
20✔
3281
                                return -EINVAL;
3282

3283
                        s = source;
20✔
3284
                        if (s[0] == '-') {
20✔
3285
                                ignore_enoent = true;
1✔
3286
                                s++;
1✔
3287
                        }
3288

3289
                        if (val && val[-1] == ':') {
20✔
3290
                                r = extract_first_word(&val,
20✔
3291
                                                       &destination,
3292
                                                       ":" WHITESPACE,
3293
                                                       EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3294
                                if (r < 0)
20✔
3295
                                        return r;
3296
                                if (r == 0)
20✔
3297
                                        continue;
×
3298

3299
                                d = destination;
20✔
3300

3301
                                if (val && val[-1] == ':') {
20✔
3302
                                        _cleanup_free_ char *options = NULL;
20✔
3303

3304
                                        r = extract_first_word(&val, &options, NULL, EXTRACT_UNQUOTE);
20✔
3305
                                        if (r < 0)
20✔
3306
                                                return -r;
×
3307

3308
                                        if (isempty(options) || streq(options, "rbind"))
43✔
3309
                                                rbind = true;
3310
                                        else if (streq(options, "norbind"))
3✔
3311
                                                rbind = false;
3312
                                        else
3313
                                                continue;
×
3314
                                }
3315
                        } else
3316
                                d = s;
3317

3318
                        r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts,
40✔
3319
                                        &(BindMount) {
20✔
3320
                                                .source = s,
3321
                                                .destination = d,
3322
                                                .read_only = false,
3323
                                                .recursive = rbind,
3324
                                                .ignore_enoent = ignore_enoent,
3325
                                        });
3326
                        if (r < 0)
20✔
3327
                                return log_oom_debug();
×
3328
                } else if ((val = startswith(l, "exec-context-temporary-filesystems="))) {
896,372✔
3329
                        _cleanup_free_ char *path = NULL, *options = NULL;
61✔
3330

3331
                        r = extract_many_words(&val, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &path, &options);
61✔
3332
                        if (r < 0)
61✔
3333
                                return r;
3334
                        if (r < 1)
61✔
3335
                                continue;
×
3336

3337
                        r = temporary_filesystem_add(&c->temporary_filesystems, &c->n_temporary_filesystems, path, options);
61✔
3338
                        if (r < 0)
61✔
3339
                                return log_oom_debug();
×
3340
                } else if ((val = startswith(l, "exec-context-utmp-id="))) {
896,311✔
3341
                        r = free_and_strdup(&c->utmp_id, val);
176✔
3342
                        if (r < 0)
176✔
3343
                                return r;
3344
                } else if ((val = startswith(l, "exec-context-utmp-mode="))) {
896,135✔
3345
                        c->utmp_mode = exec_utmp_mode_from_string(val);
11,925✔
3346
                        if (c->utmp_mode < 0)
11,925✔
3347
                                return c->utmp_mode;
3348
                } else if ((val = startswith(l, "exec-context-no-new-privileges="))) {
884,210✔
3349
                        r = parse_boolean(val);
2,126✔
3350
                        if (r < 0)
2,126✔
3351
                                return r;
3352
                        c->no_new_privileges = r;
2,126✔
3353
                } else if ((val = startswith(l, "exec-context-selinux-context="))) {
882,084✔
3354
                        if (val[0] == '-') {
×
3355
                                c->selinux_context_ignore = true;
×
3356
                                val++;
×
3357
                        } else
3358
                                c->selinux_context_ignore = false;
×
3359

3360
                        r = free_and_strdup(&c->selinux_context, val);
×
3361
                        if (r < 0)
×
3362
                                return r;
3363
                } else if ((val = startswith(l, "exec-context-apparmor-profile="))) {
882,084✔
3364
                        if (val[0] == '-') {
×
3365
                                c->apparmor_profile_ignore = true;
×
3366
                                val++;
×
3367
                        } else
3368
                                c->apparmor_profile_ignore = false;
×
3369

3370
                        r = free_and_strdup(&c->apparmor_profile, val);
×
3371
                        if (r < 0)
×
3372
                                return r;
3373
                } else if ((val = startswith(l, "exec-context-smack-process-label="))) {
882,084✔
3374
                        if (val[0] == '-') {
×
3375
                                c->smack_process_label_ignore = true;
×
3376
                                val++;
×
3377
                        } else
3378
                                c->smack_process_label_ignore = false;
×
3379

3380
                        r = free_and_strdup(&c->smack_process_label, val);
×
3381
                        if (r < 0)
×
3382
                                return r;
3383
                } else if ((val = startswith(l, "exec-context-personality="))) {
882,084✔
3384
                        c->personality = personality_from_string(val);
×
3385
                        if (c->personality == PERSONALITY_INVALID)
×
3386
                                return -EINVAL;
3387
                } else if ((val = startswith(l, "exec-context-lock-personality="))) {
882,084✔
3388
                        r = parse_boolean(val);
2,182✔
3389
                        if (r < 0)
2,182✔
3390
                                return r;
3391
                        c->lock_personality = r;
2,182✔
3392
#if HAVE_SECCOMP
3393
                } else if ((val = startswith(l, "exec-context-syscall-filter="))) {
879,902✔
3394
                        _cleanup_free_ char *s_id = NULL, *s_errno_num = NULL;
842,137✔
3395
                        int id, errno_num;
842,137✔
3396

3397
                        r = extract_many_words(&val, NULL, 0, &s_id, &s_errno_num);
842,137✔
3398
                        if (r < 0)
842,137✔
3399
                                return r;
3400
                        if (r != 2)
842,137✔
3401
                                continue;
×
3402

3403
                        r = safe_atoi(s_id, &id);
842,137✔
3404
                        if (r < 0)
842,137✔
3405
                                return r;
3406

3407
                        r = safe_atoi(s_errno_num, &errno_num);
842,137✔
3408
                        if (r < 0)
842,137✔
3409
                                return r;
3410

3411
                        r = hashmap_ensure_put(&c->syscall_filter, NULL, INT_TO_PTR(id + 1), INT_TO_PTR(errno_num));
842,137✔
3412
                        if (r < 0)
842,137✔
3413
                                return r;
3414
                } else if ((val = startswith(l, "exec-context-syscall-archs="))) {
37,765✔
3415
                        unsigned id;
2,177✔
3416

3417
                        r = safe_atou(val, &id);
2,177✔
3418
                        if (r < 0)
2,177✔
3419
                                return r;
×
3420

3421
                        r = set_ensure_put(&c->syscall_archs, NULL, UINT_TO_PTR(id + 1));
2,177✔
3422
                        if (r < 0)
2,177✔
3423
                                return r;
3424
                } else if ((val = startswith(l, "exec-context-syscall-errno="))) {
35,588✔
3425
                        r = safe_atoi(val, &c->syscall_errno);
11,925✔
3426
                        if (r < 0)
11,925✔
3427
                                return r;
3428
                } else if ((val = startswith(l, "exec-context-syscall-allow-list="))) {
23,663✔
3429
                        r = parse_boolean(val);
2,159✔
3430
                        if (r < 0)
2,159✔
3431
                                return r;
3432
                        c->syscall_allow_list = r;
2,159✔
3433
                } else if ((val = startswith(l, "exec-context-syscall-log="))) {
21,504✔
3434
                        _cleanup_free_ char *s_id = NULL, *s_errno_num = NULL;
×
3435
                        int id, errno_num;
×
3436

3437
                        r = extract_many_words(&val, " ", 0, &s_id, &s_errno_num);
×
3438
                        if (r < 0)
×
3439
                                return r;
3440
                        if (r != 2)
×
3441
                                continue;
×
3442

3443
                        r = safe_atoi(s_id, &id);
×
3444
                        if (r < 0)
×
3445
                                return r;
3446

3447
                        r = safe_atoi(s_errno_num, &errno_num);
×
3448
                        if (r < 0)
×
3449
                                return r;
3450

3451
                        r = hashmap_ensure_put(&c->syscall_log, NULL, INT_TO_PTR(id + 1), INT_TO_PTR(errno_num));
×
3452
                        if (r < 0)
×
3453
                                return r;
3454
                } else if ((val = startswith(l, "exec-context-syscall-log-allow-list="))) {
21,504✔
3455
                        r = parse_boolean(val);
×
3456
                        if (r < 0)
×
3457
                                return r;
3458
                        c->syscall_log_allow_list = r;
×
3459
#endif
3460
                } else if ((val = startswith(l, "exec-context-restrict-namespaces="))) {
21,504✔
3461
                        r = safe_atolu(val, &c->restrict_namespaces);
1,927✔
3462
                        if (r < 0)
1,927✔
3463
                                return r;
3464
                } else if ((val = startswith(l, "exec-context-delegate-namespaces="))) {
19,577✔
3465
                        r = safe_atolu(val, &c->delegate_namespaces);
20✔
3466
                        if (r < 0)
20✔
3467
                                return r;
3468
                } else if ((val = startswith(l, "exec-context-restrict-filesystems="))) {
19,557✔
3469
                        r = set_put_strdup(&c->restrict_filesystems, val);
×
3470
                        if (r < 0)
×
3471
                                return r;
3472
                } else if ((val = startswith(l, "exec-context-restrict-filesystems-allow-list="))) {
19,557✔
3473
                        r = parse_boolean(val);
×
3474
                        if (r < 0)
×
3475
                                return r;
3476
                        c->restrict_filesystems_allow_list = r;
×
3477
                } else if ((val = startswith(l, "exec-context-address-families="))) {
19,557✔
3478
                        int af;
9,188✔
3479

3480
                        r = safe_atoi(val, &af);
9,188✔
3481
                        if (r < 0)
9,188✔
3482
                                return r;
×
3483

3484
                        r = set_ensure_put(&c->address_families, NULL, INT_TO_PTR(af));
9,188✔
3485
                        if (r < 0)
9,188✔
3486
                                return r;
3487
                } else if ((val = startswith(l, "exec-context-address-families-allow-list="))) {
10,369✔
3488
                        r = parse_boolean(val);
2,177✔
3489
                        if (r < 0)
2,177✔
3490
                                return r;
3491
                        c->address_families_allow_list = r;
2,177✔
3492
                } else if ((val = startswith(l, "exec-context-network-namespace-path="))) {
8,192✔
3493
                        r = free_and_strdup(&c->network_namespace_path, val);
×
3494
                        if (r < 0)
×
3495
                                return r;
3496
                } else if ((val = startswith(l, "exec-context-ipc-namespace-path="))) {
8,192✔
3497
                        r = free_and_strdup(&c->ipc_namespace_path, val);
×
3498
                        if (r < 0)
×
3499
                                return r;
3500
                } else if ((val = startswith(l, "exec-context-mount-image="))) {
8,192✔
3501
                        _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
×
3502
                        _cleanup_free_ char *source = NULL, *destination = NULL;
60✔
3503
                        bool permissive = false;
60✔
3504
                        char *s;
60✔
3505

3506
                        r = extract_many_words(&val,
60✔
3507
                                               NULL,
3508
                                               EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS,
3509
                                               &source,
3510
                                               &destination);
3511
                        if (r < 0)
60✔
3512
                                return r;
3513
                        if (r == 0)
60✔
3514
                                return -EINVAL;
3515

3516
                        s = source;
60✔
3517
                        if (s[0] == '-') {
60✔
3518
                                permissive = true;
×
3519
                                s++;
×
3520
                        }
3521

3522
                        if (isempty(destination))
60✔
3523
                                continue;
×
3524

3525
                        for (;;) {
65✔
3526
                                _cleanup_free_ char *tuple = NULL, *partition = NULL, *opts = NULL;
5✔
3527
                                PartitionDesignator partition_designator;
65✔
3528
                                MountOptions *o = NULL;
65✔
3529
                                const char *p;
65✔
3530

3531
                                r = extract_first_word(&val, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
65✔
3532
                                if (r < 0)
65✔
3533
                                        return r;
3534
                                if (r == 0)
65✔
3535
                                        break;
3536

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

3557
                                        continue;
×
3558
                                }
3559

3560
                                partition_designator = partition_designator_from_string(partition);
5✔
3561
                                if (partition_designator < 0)
5✔
3562
                                        continue;
×
3563

3564
                                o = new(MountOptions, 1);
5✔
3565
                                if (!o)
5✔
3566
                                        return log_oom_debug();
×
3567
                                *o = (MountOptions) {
5✔
3568
                                        .partition_designator = partition_designator,
3569
                                        .options = TAKE_PTR(opts),
5✔
3570
                                };
3571
                                LIST_APPEND(mount_options, options, o);
5✔
3572
                        }
3573

3574
                        r = mount_image_add(&c->mount_images, &c->n_mount_images,
120✔
3575
                                        &(MountImage) {
60✔
3576
                                                .source = s,
3577
                                                .destination = destination,
3578
                                                .mount_options = options,
3579
                                                .ignore_enoent = permissive,
3580
                                                .type = MOUNT_IMAGE_DISCRETE,
3581
                                        });
3582
                        if (r < 0)
60✔
3583
                                return log_oom_debug();
×
3584
                } else if ((val = startswith(l, "exec-context-extension-image="))) {
8,132✔
3585
                        _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
×
3586
                        _cleanup_free_ char *source = NULL;
13✔
3587
                        bool permissive = false;
13✔
3588
                        char *s;
13✔
3589

3590
                        r = extract_first_word(&val,
13✔
3591
                                               &source,
3592
                                               NULL,
3593
                                               EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS);
3594
                        if (r < 0)
13✔
3595
                                return r;
3596
                        if (r == 0)
13✔
3597
                                return -EINVAL;
3598

3599
                        s = source;
13✔
3600
                        if (s[0] == '-') {
13✔
3601
                                permissive = true;
3✔
3602
                                s++;
3✔
3603
                        }
3604

3605
                        for (;;) {
13✔
3606
                                _cleanup_free_ char *tuple = NULL, *partition = NULL, *opts = NULL;
×
3607
                                PartitionDesignator partition_designator;
13✔
3608
                                MountOptions *o = NULL;
13✔
3609
                                const char *p;
13✔
3610

3611
                                r = extract_first_word(&val, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
13✔
3612
                                if (r < 0)
13✔
3613
                                        return r;
3614
                                if (r == 0)
13✔
3615
                                        break;
3616

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

3637
                                        continue;
×
3638
                                }
3639

3640
                                partition_designator = partition_designator_from_string(partition);
×
3641
                                if (partition_designator < 0)
×
3642
                                        continue;
×
3643

3644
                                o = new(MountOptions, 1);
×
3645
                                if (!o)
×
3646
                                        return log_oom_debug();
×
3647
                                *o = (MountOptions) {
×
3648
                                        .partition_designator = partition_designator,
3649
                                        .options = TAKE_PTR(opts),
×
3650
                                };
3651
                                LIST_APPEND(mount_options, options, o);
×
3652
                        }
3653

3654
                        r = mount_image_add(&c->extension_images, &c->n_extension_images,
26✔
3655
                                        &(MountImage) {
13✔
3656
                                                .source = s,
3657
                                                .mount_options = options,
3658
                                                .ignore_enoent = permissive,
3659
                                                .type = MOUNT_IMAGE_EXTENSION,
3660
                                        });
3661
                        if (r < 0)
13✔
3662
                                return log_oom_debug();
×
3663
                } else if ((val = startswith(l, "exec-context-extension-directories="))) {
8,119✔
3664
                        r = deserialize_strv(val, &c->extension_directories);
8✔
3665
                        if (r < 0)
8✔
3666
                                return r;
3667
                } else if ((val = startswith(l, "exec-context-set-credentials="))) {
8,111✔
3668
                        _cleanup_free_ char *id = NULL, *data = NULL, *encrypted = NULL;
×
3669

3670
                        r = extract_many_words(&val, " ", EXTRACT_DONT_COALESCE_SEPARATORS, &id, &data, &encrypted);
186✔
3671
                        if (r < 0)
186✔
3672
                                return r;
3673
                        if (r != 3)
186✔
3674
                                return -EINVAL;
3675

3676
                        r = parse_boolean(encrypted);
186✔
3677
                        if (r < 0)
186✔
3678
                                return r;
3679
                        bool e = r;
186✔
3680

3681
                        _cleanup_free_ void *d = NULL;
186✔
3682
                        size_t size;
186✔
3683

3684
                        r = unbase64mem_full(data, SIZE_MAX, /* secure = */ true, &d, &size);
186✔
3685
                        if (r < 0)
186✔
3686
                                return r;
3687

3688
                        r = exec_context_put_set_credential(c, id, TAKE_PTR(d), size, e);
186✔
3689
                        if (r < 0)
186✔
3690
                                return r;
3691
                } else if ((val = startswith(l, "exec-context-load-credentials="))) {
7,925✔
3692
                        _cleanup_free_ char *id = NULL, *path = NULL, *encrypted = NULL;
61✔
3693

3694
                        r = extract_many_words(&val, " ", EXTRACT_DONT_COALESCE_SEPARATORS, &id, &path, &encrypted);
61✔
3695
                        if (r < 0)
61✔
3696
                                return r;
3697
                        if (r != 3)
61✔
3698
                                return -EINVAL;
3699

3700
                        r = parse_boolean(encrypted);
61✔
3701
                        if (r < 0)
61✔
3702
                                return r;
3703

3704
                        r = exec_context_put_load_credential(c, id, path, r > 0);
61✔
3705
                        if (r < 0)
61✔
3706
                                return r;
3707
                } else if ((val = startswith(l, "exec-context-import-credentials="))) {
7,864✔
3708
                        _cleanup_free_ char *glob = NULL, *rename = NULL;
7,858✔
3709

3710
                        r = extract_many_words(&val, " ", EXTRACT_DONT_COALESCE_SEPARATORS, &glob, &rename);
7,858✔
3711
                        if (r < 0)
7,858✔
3712
                                return r;
3713
                        if (r == 0)
7,858✔
3714
                                return -EINVAL;
3715

3716
                        r = exec_context_put_import_credential(c, glob, rename);
7,858✔
3717
                        if (r < 0)
7,858✔
3718
                                return r;
3719
                } else if ((val = startswith(l, "exec-context-root-image-policy="))) {
6✔
3720
                        if (c->root_image_policy)
4✔
3721
                                return -EINVAL; /* duplicated */
3722

3723
                        r = image_policy_from_string(val, &c->root_image_policy);
4✔
3724
                        if (r < 0)
4✔
3725
                                return r;
3726
                } else if ((val = startswith(l, "exec-context-mount-image-policy="))) {
2✔
3727
                        if (c->mount_image_policy)
×
3728
                                return -EINVAL; /* duplicated */
3729

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

3737
                        r = image_policy_from_string(val, &c->extension_image_policy);
2✔
3738
                        if (r < 0)
2✔
3739
                                return r;
3740
                } else
3741
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
3742
        }
3743

3744
        return 0;
11,925✔
3745
}
3746

3747
static int exec_command_serialize(const ExecCommand *c, FILE *f) {
2,123✔
3748
        int r;
2,123✔
3749

3750
        assert(c);
2,123✔
3751
        assert(f);
2,123✔
3752

3753
        r = serialize_item(f, "exec-command-path", c->path);
2,123✔
3754
        if (r < 0)
2,123✔
3755
                return r;
3756

3757
        r = serialize_strv(f, "exec-command-argv", c->argv);
2,123✔
3758
        if (r < 0)
2,123✔
3759
                return r;
3760

3761
        r = serialize_item_format(f, "exec-command-flags", "%d", (int) c->flags);
2,123✔
3762
        if (r < 0)
2,123✔
3763
                return r;
3764

3765
        fputc('\n', f); /* End marker */
2,123✔
3766

3767
        return 0;
2,123✔
3768
}
3769

3770
static int exec_command_deserialize(ExecCommand *c, FILE *f) {
11,925✔
3771
        int r;
11,925✔
3772

3773
        assert(c);
11,925✔
3774
        assert(f);
11,925✔
3775

3776
        for (;;) {
127,311✔
3777
                _cleanup_free_ char *l = NULL;
57,693✔
3778
                const char *val;
69,618✔
3779

3780
                r = deserialize_read_line(f, &l);
69,618✔
3781
                if (r < 0)
69,618✔
3782
                        return r;
3783
                if (r == 0) /* eof or end marker */
69,618✔
3784
                        break;
3785

3786
                if ((val = startswith(l, "exec-command-path="))) {
57,693✔
3787
                        r = free_and_strdup(&c->path, val);
11,925✔
3788
                        if (r < 0)
11,925✔
3789
                                return r;
3790
                } else if ((val = startswith(l, "exec-command-argv="))) {
45,768✔
3791
                        r = deserialize_strv(val, &c->argv);
33,843✔
3792
                        if (r < 0)
33,843✔
3793
                                return r;
3794
                } else if ((val = startswith(l, "exec-command-flags="))) {
11,925✔
3795
                        r = safe_atoi(val, &c->flags);
11,925✔
3796
                        if (r < 0)
11,925✔
3797
                                return r;
3798
                } else
3799
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
3800

3801
        }
3802

3803
        return 0;
11,925✔
3804
}
3805

3806
int exec_serialize_invocation(
2,123✔
3807
                FILE *f,
3808
                FDSet *fds,
3809
                const ExecContext *ctx,
3810
                const ExecCommand *cmd,
3811
                const ExecParameters *p,
3812
                const ExecRuntime *rt,
3813
                const CGroupContext *cg) {
3814

3815
        int r;
2,123✔
3816

3817
        assert(f);
2,123✔
3818
        assert(fds);
2,123✔
3819

3820
        r = exec_context_serialize(ctx, f);
2,123✔
3821
        if (r < 0)
2,123✔
3822
                return log_debug_errno(r, "Failed to serialize context: %m");
×
3823

3824
        r = exec_command_serialize(cmd, f);
2,123✔
3825
        if (r < 0)
2,123✔
3826
                return log_debug_errno(r, "Failed to serialize command: %m");
×
3827

3828
        r = exec_parameters_serialize(p, ctx, f, fds);
2,123✔
3829
        if (r < 0)
2,123✔
3830
                return log_debug_errno(r, "Failed to serialize parameters: %m");
×
3831

3832
        r = exec_runtime_serialize(rt, f, fds);
2,123✔
3833
        if (r < 0)
2,123✔
3834
                return log_debug_errno(r, "Failed to serialize runtime: %m");
×
3835

3836
        r = exec_cgroup_context_serialize(cg, f);
2,123✔
3837
        if (r < 0)
2,123✔
3838
                return log_debug_errno(r, "Failed to serialize cgroup context: %m");
×
3839

3840
        return 0;
3841
}
3842

3843
int exec_deserialize_invocation(
11,925✔
3844
                FILE *f,
3845
                FDSet *fds,
3846
                ExecContext *ctx,
3847
                ExecCommand *cmd,
3848
                ExecParameters *p,
3849
                ExecRuntime *rt,
3850
                CGroupContext *cg) {
3851

3852
        int r;
11,925✔
3853

3854
        assert(f);
11,925✔
3855
        assert(fds);
11,925✔
3856

3857
        r = exec_context_deserialize(ctx, f);
11,925✔
3858
        if (r < 0)
11,925✔
3859
                return log_debug_errno(r, "Failed to deserialize context: %m");
×
3860

3861
        r = exec_command_deserialize(cmd, f);
11,925✔
3862
        if (r < 0)
11,925✔
3863
                return log_debug_errno(r, "Failed to deserialize command: %m");
×
3864

3865
        r = exec_parameters_deserialize(p, f, fds);
11,925✔
3866
        if (r < 0)
11,925✔
3867
                return log_debug_errno(r, "Failed to deserialize parameters: %m");
×
3868

3869
        r = exec_runtime_deserialize(rt, f, fds);
11,925✔
3870
        if (r < 0)
11,925✔
3871
                return log_debug_errno(r, "Failed to deserialize runtime: %m");
×
3872

3873
        r = exec_cgroup_context_deserialize(cg, f);
11,925✔
3874
        if (r < 0)
11,925✔
3875
                return log_debug_errno(r, "Failed to deserialize cgroup context: %m");
×
3876

3877
        return 0;
3878
}
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