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

systemd / systemd / 15986406979

30 Jun 2025 05:03PM UTC coverage: 72.045% (-0.09%) from 72.13%
15986406979

push

github

bluca
man/systemd-sysext: list ephemeral/ephemeral-import in the list of options

ephemeral/ephemeral-import are described as possible '--mutable' options but
not present in the list. Note, "systemd-sysext --help" lists them correctly.

300514 of 417119 relevant lines covered (72.05%)

708586.28 hits per line

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

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

42
        assert(f);
2,234✔
43

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

433
        return 0;
434
}
435

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

439
        assert(f);
11,737✔
440

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

444
        for (;;) {
424,029✔
445
                _cleanup_free_ char *l = NULL;
206,146✔
446
                const char *val;
217,883✔
447

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

454
                if ((val = startswith(l, "exec-cgroup-context-io-accounting="))) {
206,146✔
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="))) {
206,144✔
460
                        r = parse_boolean(val);
11,511✔
461
                        if (r < 0)
11,511✔
462
                                return r;
463
                        c->memory_accounting = r;
11,511✔
464
                } else if ((val = startswith(l, "exec-cgroup-context-tasks-accounting="))) {
194,633✔
465
                        r = parse_boolean(val);
11,737✔
466
                        if (r < 0)
11,737✔
467
                                return r;
468
                        c->tasks_accounting = r;
11,737✔
469
                } else if ((val = startswith(l, "exec-cgroup-context-ip-accounting="))) {
182,896✔
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="))) {
182,896✔
475
                        r = parse_boolean(val);
×
476
                        if (r < 0)
×
477
                                return r;
478
                        c->memory_oom_group = r;
×
479
                } else if ((val = startswith(l, "exec-cgroup-context-cpu-weight="))) {
182,896✔
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="))) {
182,895✔
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="))) {
182,895✔
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="))) {
182,895✔
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="))) {
182,895✔
496
                        if (c->cpuset_cpus.set)
11,737✔
497
                                return -EINVAL; /* duplicated */
498

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

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

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

520
                        r = parse_cpu_set(val, &c->startup_cpuset_mems);
11,737✔
521
                        if (r < 0)
11,737✔
522
                                return r;
523
                } else if ((val = startswith(l, "exec-cgroup-context-io-weight="))) {
135,947✔
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="))) {
135,947✔
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="))) {
135,947✔
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="))) {
135,947✔
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="))) {
135,947✔
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="))) {
135,946✔
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="))) {
135,945✔
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="))) {
135,945✔
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="))) {
135,935✔
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="))) {
135,935✔
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="))) {
135,933✔
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="))) {
135,933✔
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="))) {
135,932✔
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="))) {
135,932✔
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="))) {
135,931✔
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="))) {
135,931✔
584
                        r = parse_boolean(val);
11,737✔
585
                        if (r < 0)
11,737✔
586
                                return r;
587
                        c->memory_zswap_writeback = r;
11,737✔
588
                } else if ((val = startswith(l, "exec-cgroup-context-tasks-max-value="))) {
124,194✔
589
                        r = safe_atou64(val, &c->tasks_max.value);
11,449✔
590
                        if (r < 0)
11,449✔
591
                                return r;
592
                } else if ((val = startswith(l, "exec-cgroup-context-tasks-max-scale="))) {
112,745✔
593
                        r = safe_atou64(val, &c->tasks_max.scale);
11,414✔
594
                        if (r < 0)
11,414✔
595
                                return r;
596
                } else if ((val = startswith(l, "exec-cgroup-context-default-memory-min-set="))) {
101,331✔
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="))) {
101,331✔
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="))) {
101,331✔
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="))) {
101,331✔
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="))) {
101,330✔
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="))) {
101,329✔
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="))) {
101,329✔
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="))) {
101,329✔
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="))) {
101,329✔
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="))) {
101,329✔
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="))) {
101,329✔
647
                        c->device_policy = cgroup_device_policy_from_string(val);
11,737✔
648
                        if (c->device_policy < 0)
11,737✔
649
                                return -EINVAL;
650
                } else if ((val = startswith(l, "exec-cgroup-context-disable-controllers="))) {
89,592✔
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="))) {
89,592✔
655
                        r = cg_mask_from_string(val, &c->delegate_controllers);
555✔
656
                        if (r < 0)
555✔
657
                                return r;
658
                } else if ((val = startswith(l, "exec-cgroup-context-delegate="))) {
89,037✔
659
                        r = parse_boolean(val);
672✔
660
                        if (r < 0)
672✔
661
                                return r;
662
                        c->delegate = r;
672✔
663
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-swap="))) {
88,365✔
664
                        c->moom_swap = managed_oom_mode_from_string(val);
11,737✔
665
                        if (c->moom_swap < 0)
11,737✔
666
                                return -EINVAL;
667
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-memory-pressure="))) {
76,628✔
668
                        c->moom_mem_pressure = managed_oom_mode_from_string(val);
11,737✔
669
                        if (c->moom_mem_pressure < 0)
11,737✔
670
                                return -EINVAL;
671
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-memory-pressure-limit="))) {
64,891✔
672
                        r = safe_atou32(val, &c->moom_mem_pressure_limit);
11,737✔
673
                        if (r < 0)
11,737✔
674
                                return r;
675
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-preference="))) {
53,154✔
676
                        c->moom_preference = managed_oom_preference_from_string(val);
11,737✔
677
                        if (c->moom_preference < 0)
11,737✔
678
                                return -EINVAL;
679
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-memory-pressure-duration-usec="))) {
41,417✔
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="))) {
41,416✔
684
                        c->memory_pressure_watch = cgroup_pressure_watch_from_string(val);
11,737✔
685
                        if (c->memory_pressure_watch < 0)
11,737✔
686
                                return -EINVAL;
687
                } else if ((val = startswith(l, "exec-cgroup-context-delegate-subgroup="))) {
29,679✔
688
                        r = free_and_strdup(&c->delegate_subgroup, val);
331✔
689
                        if (r < 0)
331✔
690
                                return r;
691
                } else if ((val = startswith(l, "exec-cgroup-context-memory-pressure-threshold-usec="))) {
29,348✔
692
                        r = deserialize_usec(val, &c->memory_pressure_threshold_usec);
11,737✔
693
                        if (r < 0)
11,737✔
694
                                return r;
695
                } else if ((val = startswith(l, "exec-cgroup-context-device-allow="))) {
17,611✔
696
                        _cleanup_free_ char *path = NULL, *rwm = NULL;
4,575✔
697
                        CGroupDevicePermissions p;
4,575✔
698

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

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

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

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

823
                        r = in_addr_prefix_add(&c->ip_address_deny, &a);
1,628✔
824
                        if (r < 0)
1,628✔
825
                                return r;
826
                } else if ((val = startswith(l, "exec-cgroup-context-ip-address-allow-reduced="))) {
11,408✔
827
                        r = parse_boolean(val);
5,692✔
828
                        if (r < 0)
5,692✔
829
                                return r;
830
                        c->ip_address_allow_reduced = r;
5,692✔
831
                } else if ((val = startswith(l, "exec-cgroup-context-ip-address-deny-reduced="))) {
5,716✔
832
                        r = parse_boolean(val);
5,692✔
833
                        if (r < 0)
5,692✔
834
                                return r;
835
                        c->ip_address_deny_reduced = r;
5,692✔
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,737✔
915
}
916

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

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

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

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

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

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

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

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

982
        return 0;
70✔
983
}
984

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

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

994
        for (;;) {
12,956✔
995
                _cleanup_free_ char *l = NULL;
1,219✔
996
                const char *val;
12,956✔
997

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

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

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

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

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

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

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

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

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

1056
        return 0;
11,737✔
1057
}
1058

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1252
        return 0;
2,234✔
1253
}
1254

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

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

1262
        nr_open = read_nr_open();
11,737✔
1263
        if (nr_open < 3)
11,737✔
1264
                nr_open = HIGH_RLIMIT_NOFILE;
×
1265
        assert(nr_open > 0); /* For compilers/static analyzers */
11,737✔
1266

1267
        for (;;) {
262,911✔
1268
                _cleanup_free_ char *l = NULL;
251,174✔
1269
                const char *val;
262,911✔
1270

1271
                r = deserialize_read_line(f, &l);
262,911✔
1272
                if (r < 0)
262,911✔
1273
                        return r;
1274
                if (r == 0) /* eof or end marker */
262,911✔
1275
                        break;
1276

1277
                if ((val = startswith(l, "exec-parameters-runtime-scope="))) {
251,174✔
1278
                        p->runtime_scope = runtime_scope_from_string(val);
11,737✔
1279
                        if (p->runtime_scope < 0)
11,737✔
1280
                                return p->runtime_scope;
1281
                } else if ((val = startswith(l, "exec-parameters-environment="))) {
239,437✔
1282
                        r = deserialize_strv(val, &p->environment);
49,356✔
1283
                        if (r < 0)
49,356✔
1284
                                return r;
1285
                } else if ((val = startswith(l, "exec-parameters-n-socket-fds="))) {
190,081✔
1286
                        if (p->fds)
2,297✔
1287
                                return -EINVAL; /* Already received */
1288

1289
                        r = safe_atozu(val, &p->n_socket_fds);
2,297✔
1290
                        if (r < 0)
2,297✔
1291
                                return r;
1292

1293
                        if (p->n_socket_fds > (size_t) nr_open)
2,297✔
1294
                                return -EINVAL; /* too many, someone is playing games with us */
1295
                } else if ((val = startswith(l, "exec-parameters-n-storage-fds="))) {
187,784✔
1296
                        if (p->fds)
143✔
1297
                                return -EINVAL; /* Already received */
1298

1299
                        r = safe_atozu(val, &p->n_storage_fds);
143✔
1300
                        if (r < 0)
143✔
1301
                                return r;
1302

1303
                        if (p->n_storage_fds > (size_t) nr_open)
143✔
1304
                                return -EINVAL; /* too many, someone is playing games with us */
1305
                } else if ((val = startswith(l, "exec-parameters-n-extra-fds="))) {
187,641✔
1306
                        if (p->fds)
2✔
1307
                                return -EINVAL; /* Already received */
1308

1309
                        r = safe_atozu(val, &p->n_extra_fds);
2✔
1310
                        if (r < 0)
2✔
1311
                                return r;
1312

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

1324
                        if (p->fds)
2,308✔
1325
                                return -EINVAL; /* duplicated */
1326

1327
                        p->fds = new(int, p->n_socket_fds + p->n_storage_fds + p->n_extra_fds);
2,308✔
1328
                        if (!p->fds)
2,308✔
1329
                                return log_oom_debug();
×
1330

1331
                        /* Ensure we don't leave any FD uninitialized on error, it makes the fuzzer sad */
1332
                        FOREACH_ARRAY(i, p->fds, p->n_socket_fds + p->n_storage_fds + p->n_extra_fds)
6,319✔
1333
                                *i = -EBADF;
4,011✔
1334

1335
                        r = deserialize_fd_many(fds, val, p->n_socket_fds + p->n_storage_fds + p->n_extra_fds, p->fds);
2,308✔
1336
                        if (r < 0)
2,308✔
1337
                                continue;
×
1338

1339
                } else if ((val = startswith(l, "exec-parameters-fd-names="))) {
185,331✔
1340
                        r = deserialize_strv(val, &p->fd_names);
4,011✔
1341
                        if (r < 0)
4,011✔
1342
                                return r;
1343
                } else if ((val = startswith(l, "exec-parameters-flags="))) {
181,320✔
1344
                        unsigned flags;
11,737✔
1345

1346
                        r = safe_atou(val, &flags);
11,737✔
1347
                        if (r < 0)
11,737✔
1348
                                return r;
×
1349
                        p->flags = flags;
11,737✔
1350
                } else if ((val = startswith(l, "exec-parameters-selinux-context-net="))) {
169,583✔
1351
                        r = parse_boolean(val);
×
1352
                        if (r < 0)
×
1353
                                return r;
1354

1355
                        p->selinux_context_net = r;
×
1356
                } else if ((val = startswith(l, "exec-parameters-cgroup-supported="))) {
169,583✔
1357
                        unsigned cgroup_supported;
11,726✔
1358

1359
                        r = safe_atou(val, &cgroup_supported);
11,726✔
1360
                        if (r < 0)
11,726✔
1361
                                return r;
×
1362
                        p->cgroup_supported = cgroup_supported;
11,726✔
1363
                } else if ((val = startswith(l, "exec-parameters-cgroup-path="))) {
157,857✔
1364
                        r = free_and_strdup(&p->cgroup_path, val);
11,737✔
1365
                        if (r < 0)
11,737✔
1366
                                return r;
1367
                } else if ((val = startswith(l, "exec-parameters-cgroup-id="))) {
146,120✔
1368
                        r = safe_atou64(val, &p->cgroup_id);
11,737✔
1369
                        if (r < 0)
11,737✔
1370
                                return r;
1371
                } else if ((val = startswith(l, "exec-parameters-prefix-directories-"))) {
134,383✔
1372
                        _cleanup_free_ char *type = NULL, *prefix = NULL;
58,685✔
1373
                        ExecDirectoryType dt;
58,685✔
1374

1375
                        r = extract_many_words(&val, "= ", 0, &type, &prefix);
58,685✔
1376
                        if (r < 0)
58,685✔
1377
                                return r;
1378
                        if (r == 0)
58,685✔
1379
                                return -EINVAL;
1380

1381
                        dt = exec_directory_type_from_string(type);
58,685✔
1382
                        if (dt < 0)
58,685✔
1383
                                return -EINVAL;
1384

1385
                        if (!p->prefix) {
58,685✔
1386
                                p->prefix = new0(char*, _EXEC_DIRECTORY_TYPE_MAX+1);
11,737✔
1387
                                if (!p->prefix)
11,737✔
1388
                                        return log_oom_debug();
×
1389
                        }
1390

1391
                        if (isempty(prefix))
58,685✔
1392
                                p->prefix[dt] = mfree(p->prefix[dt]);
×
1393
                        else
1394
                                free_and_replace(p->prefix[dt], prefix);
58,685✔
1395
                } else if ((val = startswith(l, "exec-parameters-received-credentials-directory="))) {
75,698✔
1396
                        r = free_and_strdup(&p->received_credentials_directory, val);
10,939✔
1397
                        if (r < 0)
10,939✔
1398
                                return r;
1399
                } else if ((val = startswith(l, "exec-parameters-received-encrypted-credentials-directory="))) {
64,759✔
1400
                        r = free_and_strdup(&p->received_encrypted_credentials_directory, val);
×
1401
                        if (r < 0)
×
1402
                                return r;
1403
                } else if ((val = startswith(l, "exec-parameters-confirm-spawn="))) {
64,759✔
1404
                        r = free_and_strdup(&p->confirm_spawn, val);
×
1405
                        if (r < 0)
×
1406
                                return r;
1407
                } else if ((val = startswith(l, "exec-parameters-shall-confirm-spawn="))) {
64,759✔
1408
                        r = parse_boolean(val);
×
1409
                        if (r < 0)
×
1410
                                return r;
1411

1412
                        p->shall_confirm_spawn = r;
×
1413
                } else if ((val = startswith(l, "exec-parameters-watchdog-usec="))) {
64,759✔
1414
                        r = deserialize_usec(val, &p->watchdog_usec);
2,264✔
1415
                        if (r < 0)
2,264✔
1416
                                return r;
1417
                } else if ((val = startswith(l, "exec-parameters-idle-pipe="))) {
62,495✔
1418
                        if (p->idle_pipe)
149✔
1419
                                return -EINVAL; /* duplicated */
1420

1421
                        p->idle_pipe = new(int, 4);
149✔
1422
                        if (!p->idle_pipe)
149✔
1423
                                return log_oom_debug();
×
1424

1425
                        p->idle_pipe[0] = p->idle_pipe[1] = p->idle_pipe[2] = p->idle_pipe[3] = -EBADF;
149✔
1426

1427
                        r = deserialize_fd_many(fds, val, 4, p->idle_pipe);
149✔
1428
                        if (r < 0)
149✔
1429
                                continue;
×
1430

1431
                } else if ((val = startswith(l, "exec-parameters-stdin-fd="))) {
62,346✔
1432
                        int fd;
550✔
1433

1434
                        fd = deserialize_fd(fds, val);
550✔
1435
                        if (fd < 0)
550✔
1436
                                continue;
×
1437

1438
                        close_and_replace(p->stdin_fd, fd);
550✔
1439

1440
                } else if ((val = startswith(l, "exec-parameters-stdout-fd="))) {
61,796✔
1441
                        int fd;
550✔
1442

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

1447
                        close_and_replace(p->stdout_fd, fd);
550✔
1448

1449
                } else if ((val = startswith(l, "exec-parameters-stderr-fd="))) {
61,246✔
1450
                        int fd;
550✔
1451

1452
                        fd = deserialize_fd(fds, val);
550✔
1453
                        if (fd < 0)
550✔
1454
                                continue;
×
1455

1456
                        close_and_replace(p->stderr_fd, fd);
550✔
1457
                } else if ((val = startswith(l, "exec-parameters-exec-fd="))) {
60,696✔
1458
                        int fd;
396✔
1459

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

1464
                        close_and_replace(p->exec_fd, fd);
396✔
1465
                } else if ((val = startswith(l, "exec-parameters-handoff-timestamp-fd="))) {
60,300✔
1466
                        int fd;
11,737✔
1467

1468
                        fd = deserialize_fd(fds, val);
11,737✔
1469
                        if (fd < 0)
11,737✔
1470
                                continue;
×
1471

1472
                        close_and_replace(p->handoff_timestamp_fd, fd);
11,737✔
1473
                } else if ((val = startswith(l, "exec-parameters-pidref-transport-fd="))) {
48,563✔
1474
                        int fd;
10,686✔
1475

1476
                        fd = deserialize_fd(fds, val);
10,686✔
1477
                        if (fd < 0)
10,686✔
1478
                                continue;
×
1479

1480
                        close_and_replace(p->pidref_transport_fd, fd);
10,686✔
1481
                } else if ((val = startswith(l, "exec-parameters-bpf-outer-map-fd="))) {
37,877✔
1482
                        int fd;
×
1483

1484
                        fd = deserialize_fd(fds, val);
×
1485
                        if (fd < 0)
×
1486
                                continue;
×
1487

1488
                        close_and_replace(p->bpf_restrict_fs_map_fd, fd);
×
1489
                } else if ((val = startswith(l, "exec-parameters-notify-socket="))) {
37,877✔
1490
                        r = free_and_strdup(&p->notify_socket, val);
2,657✔
1491
                        if (r < 0)
2,657✔
1492
                                return r;
1493
                } else if ((val = startswith(l, "exec-parameters-open-file="))) {
35,220✔
1494
                        OpenFile *of;
5✔
1495

1496
                        r = open_file_parse(val, &of);
5✔
1497
                        if (r < 0)
5✔
1498
                                return r;
×
1499

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

1508
                        fd = deserialize_fd(fds, val);
11,737✔
1509
                        if (fd < 0)
11,737✔
1510
                                continue;
×
1511

1512
                        close_and_replace(p->user_lookup_fd, fd);
11,737✔
1513
                } else if ((val = startswith(l, "exec-parameters-files-env="))) {
23,478✔
1514
                        r = deserialize_strv(val, &p->files_env);
2✔
1515
                        if (r < 0)
2✔
1516
                                return r;
1517
                } else if ((val = startswith(l, "exec-parameters-unit-id="))) {
23,476✔
1518
                        r = free_and_strdup(&p->unit_id, val);
11,737✔
1519
                        if (r < 0)
11,737✔
1520
                                return r;
1521
                } else if ((val = startswith(l, "exec-parameters-invocation-id-string="))) {
11,739✔
1522
                        if (strlen(val) > SD_ID128_STRING_MAX - 1)
11,737✔
1523
                                return -EINVAL;
1524

1525
                        r = sd_id128_from_string(val, &p->invocation_id);
11,737✔
1526
                        if (r < 0)
11,737✔
1527
                                return r;
1528

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

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

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

1545
        return 0;
1546
}
1547

1548
static int serialize_std_out_err(const ExecContext *c, FILE *f, int fileno) {
4,468✔
1549
        char *key, *value;
4,468✔
1550
        const char *type;
4,468✔
1551

1552
        assert(c);
4,468✔
1553
        assert(f);
4,468✔
1554
        assert(IN_SET(fileno, STDOUT_FILENO, STDERR_FILENO));
4,468✔
1555

1556
        type = fileno == STDOUT_FILENO ? "output" : "error";
4,468✔
1557

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

1563
                break;
×
1564

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

1569
                break;
2✔
1570

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

1575
                break;
×
1576

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

1581
                break;
×
1582

1583
        default:
1584
                return 0;
1585
        }
1586

1587
        return serialize_item(f, key, value);
2✔
1588
}
1589

1590
static int exec_context_serialize(const ExecContext *c, FILE *f) {
2,234✔
1591
        int r;
2,234✔
1592

1593
        assert(f);
2,234✔
1594

1595
        if (!c)
2,234✔
1596
                return 0;
2,234✔
1597

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

1602
        r = serialize_strv(f, "exec-context-environment-files", c->environment_files);
2,234✔
1603
        if (r < 0)
2,234✔
1604
                return r;
1605

1606
        r = serialize_strv(f, "exec-context-pass-environment", c->pass_environment);
2,234✔
1607
        if (r < 0)
2,234✔
1608
                return r;
1609

1610
        r = serialize_strv(f, "exec-context-unset-environment", c->unset_environment);
2,234✔
1611
        if (r < 0)
2,234✔
1612
                return r;
1613

1614
        r = serialize_item_escaped(f, "exec-context-working-directory", c->working_directory);
2,234✔
1615
        if (r < 0)
2,234✔
1616
                return r;
1617

1618
        r = serialize_bool_elide(f, "exec-context-working-directory-missing-ok", c->working_directory_missing_ok);
2,234✔
1619
        if (r < 0)
2,234✔
1620
                return r;
1621

1622
        r = serialize_bool_elide(f, "exec-context-working-directory-home", c->working_directory_home);
2,234✔
1623
        if (r < 0)
2,234✔
1624
                return r;
1625

1626
        r = serialize_item_escaped(f, "exec-context-root-directory", c->root_directory);
2,234✔
1627
        if (r < 0)
2,234✔
1628
                return r;
1629

1630
        r = serialize_item_escaped(f, "exec-context-root-image", c->root_image);
2,234✔
1631
        if (r < 0)
2,234✔
1632
                return r;
1633

1634
        if (c->root_image_options) {
2,234✔
1635
                _cleanup_free_ char *options = NULL;
×
1636

1637
                LIST_FOREACH(mount_options, o, c->root_image_options) {
×
1638
                        if (isempty(o->options))
×
1639
                                continue;
×
1640

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

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

1654
                r = serialize_item(f, "exec-context-root-image-options", options);
×
1655
                if (r < 0)
×
1656
                        return r;
1657
        }
1658

1659
        r = serialize_item(f, "exec-context-root-verity", c->root_verity);
2,234✔
1660
        if (r < 0)
2,234✔
1661
                return r;
1662

1663
        r = serialize_item(f, "exec-context-root-hash-path", c->root_hash_path);
2,234✔
1664
        if (r < 0)
2,234✔
1665
                return r;
1666

1667
        r = serialize_item(f, "exec-context-root-hash-sig-path", c->root_hash_sig_path);
2,234✔
1668
        if (r < 0)
2,234✔
1669
                return r;
1670

1671
        r = serialize_item_hexmem(f, "exec-context-root-hash", c->root_hash, c->root_hash_size);
2,234✔
1672
        if (r < 0)
2,234✔
1673
                return r;
1674

1675
        r = serialize_item_base64mem(f, "exec-context-root-hash-sig", c->root_hash_sig, c->root_hash_sig_size);
2,234✔
1676
        if (r < 0)
2,234✔
1677
                return r;
1678

1679
        r = serialize_bool_elide(f, "exec-context-root-ephemeral", c->root_ephemeral);
2,234✔
1680
        if (r < 0)
2,234✔
1681
                return r;
1682

1683
        r = serialize_item_format(f, "exec-context-umask", "%04o", c->umask);
2,234✔
1684
        if (r < 0)
2,234✔
1685
                return r;
1686

1687
        r = serialize_bool_elide(f, "exec-context-non-blocking", c->non_blocking);
2,234✔
1688
        if (r < 0)
2,234✔
1689
                return r;
1690

1691
        r = serialize_item_tristate(f, "exec-context-private-mounts", c->private_mounts);
2,234✔
1692
        if (r < 0)
25✔
1693
                return r;
1694

1695
        r = serialize_item_tristate(f, "exec-context-mount-api-vfs", c->mount_apivfs);
2,234✔
1696
        if (r < 0)
2✔
1697
                return r;
1698

1699
        r = serialize_item_tristate(f, "exec-context-bind-log-sockets", c->bind_log_sockets);
2,234✔
1700
        if (r < 0)
×
1701
                return r;
1702

1703
        r = serialize_item_tristate(f, "exec-context-memory-ksm", c->memory_ksm);
2,234✔
1704
        if (r < 0)
×
1705
                return r;
1706

1707
        r = serialize_item(f, "exec-context-private-tmp", private_tmp_to_string(c->private_tmp));
2,234✔
1708
        if (r < 0)
2,234✔
1709
                return r;
1710

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

1717
        r = serialize_bool_elide(f, "exec-context-private-devices", c->private_devices);
2,234✔
1718
        if (r < 0)
2,234✔
1719
                return r;
1720

1721
        r = serialize_bool_elide(f, "exec-context-protect-kernel-tunables", c->protect_kernel_tunables);
2,234✔
1722
        if (r < 0)
2,234✔
1723
                return r;
1724

1725
        r = serialize_bool_elide(f, "exec-context-protect-kernel-modules", c->protect_kernel_modules);
2,234✔
1726
        if (r < 0)
2,234✔
1727
                return r;
1728

1729
        r = serialize_bool_elide(f, "exec-context-protect-kernel-logs", c->protect_kernel_logs);
2,234✔
1730
        if (r < 0)
2,234✔
1731
                return r;
1732

1733
        r = serialize_bool_elide(f, "exec-context-protect-clock", c->protect_clock);
2,234✔
1734
        if (r < 0)
2,234✔
1735
                return r;
1736

1737
        r = serialize_item(f, "exec-context-protect-control-groups", protect_control_groups_to_string(c->protect_control_groups));
2,234✔
1738
        if (r < 0)
2,234✔
1739
                return r;
1740

1741
        r = serialize_bool_elide(f, "exec-context-private-network", c->private_network);
2,234✔
1742
        if (r < 0)
2,234✔
1743
                return r;
1744

1745
        r = serialize_item(f, "exec-context-private-users", private_users_to_string(c->private_users));
2,234✔
1746
        if (r < 0)
2,234✔
1747
                return r;
1748

1749
        r = serialize_bool_elide(f, "exec-context-private-ipc", c->private_ipc);
2,234✔
1750
        if (r < 0)
2,234✔
1751
                return r;
1752

1753
        r = serialize_item(f, "exec-context-private-pids", private_pids_to_string(c->private_pids));
2,234✔
1754
        if (r < 0)
2,234✔
1755
                return r;
1756

1757
        r = serialize_bool_elide(f, "exec-context-remove-ipc", c->remove_ipc);
2,234✔
1758
        if (r < 0)
2,234✔
1759
                return r;
1760

1761
        r = serialize_item(f, "exec-context-protect-home", protect_home_to_string(c->protect_home));
2,234✔
1762
        if (r < 0)
2,234✔
1763
                return r;
1764

1765
        r = serialize_item(f, "exec-context-protect-system", protect_system_to_string(c->protect_system));
2,234✔
1766
        if (r < 0)
2,234✔
1767
                return r;
1768

1769
        r = serialize_bool_elide(f, "exec-context-same-pgrp", c->same_pgrp);
2,234✔
1770
        if (r < 0)
2,234✔
1771
                return r;
1772

1773
        r = serialize_bool(f, "exec-context-ignore-sigpipe", c->ignore_sigpipe);
2,234✔
1774
        if (r < 0)
2,234✔
1775
                return r;
1776

1777
        r = serialize_bool_elide(f, "exec-context-memory-deny-write-execute", c->memory_deny_write_execute);
2,234✔
1778
        if (r < 0)
2,234✔
1779
                return r;
1780

1781
        r = serialize_bool_elide(f, "exec-context-restrict-realtime", c->restrict_realtime);
2,234✔
1782
        if (r < 0)
2,234✔
1783
                return r;
1784

1785
        r = serialize_bool_elide(f, "exec-context-restrict-suid-sgid", c->restrict_suid_sgid);
2,234✔
1786
        if (r < 0)
2,234✔
1787
                return r;
1788

1789
        r = serialize_item(f, "exec-context-keyring-mode", exec_keyring_mode_to_string(c->keyring_mode));
2,234✔
1790
        if (r < 0)
2,234✔
1791
                return r;
1792

1793
        r = serialize_item(f, "exec-context-protect-hostname", protect_hostname_to_string(c->protect_hostname));
2,234✔
1794
        if (r < 0)
2,234✔
1795
                return r;
1796

1797
        r = serialize_item(f, "exec-context-private-hostname", c->private_hostname);
2,234✔
1798
        if (r < 0)
2,234✔
1799
                return r;
1800

1801
        r = serialize_item(f, "exec-context-protect-proc", protect_proc_to_string(c->protect_proc));
2,234✔
1802
        if (r < 0)
2,234✔
1803
                return r;
1804

1805
        r = serialize_item(f, "exec-context-proc-subset", proc_subset_to_string(c->proc_subset));
2,234✔
1806
        if (r < 0)
2,234✔
1807
                return r;
1808

1809
        r = serialize_item(f, "exec-context-runtime-directory-preserve-mode", exec_preserve_mode_to_string(c->runtime_directory_preserve_mode));
2,234✔
1810
        if (r < 0)
2,234✔
1811
                return r;
1812

1813
        for (ExecDirectoryType dt = 0; dt < _EXEC_DIRECTORY_TYPE_MAX; dt++) {
13,404✔
1814
                _cleanup_free_ char *key = NULL, *value = NULL;
11,170✔
1815

1816
                key = strjoin("exec-context-directories-", exec_directory_type_to_string(dt));
11,170✔
1817
                if (!key)
11,170✔
1818
                        return log_oom_debug();
×
1819

1820
                if (asprintf(&value, "%04o", c->directories[dt].mode) < 0)
11,170✔
1821
                        return log_oom_debug();
×
1822

1823
                FOREACH_ARRAY(i, c->directories[dt].items, c->directories[dt].n_items) {
11,602✔
1824
                        _cleanup_free_ char *path_escaped = NULL;
432✔
1825

1826
                        path_escaped = shell_escape(i->path, ":" WHITESPACE);
432✔
1827
                        if (!path_escaped)
432✔
1828
                                return log_oom_debug();
×
1829

1830
                        if (!strextend(&value, " ", path_escaped))
432✔
1831
                                return log_oom_debug();
×
1832

1833
                        if (!strextend(&value, ":", yes_no(FLAGS_SET(i->flags, EXEC_DIRECTORY_ONLY_CREATE))))
859✔
1834
                                return log_oom_debug();
×
1835

1836
                        if (!strextend(&value, ":", yes_no(FLAGS_SET(i->flags, EXEC_DIRECTORY_READ_ONLY))))
862✔
1837
                                return log_oom_debug();
×
1838

1839
                        STRV_FOREACH(d, i->symlinks) {
438✔
1840
                                _cleanup_free_ char *link_escaped = NULL;
6✔
1841

1842
                                link_escaped = shell_escape(*d, ":" WHITESPACE);
6✔
1843
                                if (!link_escaped)
6✔
1844
                                        return log_oom_debug();
×
1845

1846
                                if (!strextend(&value, ":", link_escaped))
6✔
1847
                                        return log_oom_debug();
×
1848
                        }
1849
                }
1850

1851
                r = serialize_item(f, key, value);
11,170✔
1852
                if (r < 0)
11,170✔
1853
                        return r;
1854
        }
1855

1856
        r = serialize_usec(f, "exec-context-timeout-clean-usec", c->timeout_clean_usec);
2,234✔
1857
        if (r < 0)
2,234✔
1858
                return r;
1859

1860
        if (c->nice_set) {
2,234✔
1861
                r = serialize_item_format(f, "exec-context-nice", "%i", c->nice);
2✔
1862
                if (r < 0)
2✔
1863
                        return r;
1864
        }
1865

1866
        if (c->oom_score_adjust_set) {
2,234✔
1867
                r = serialize_item_format(f, "exec-context-oom-score-adjust", "%i", c->oom_score_adjust);
658✔
1868
                if (r < 0)
658✔
1869
                        return r;
1870
        }
1871

1872
        if (c->coredump_filter_set) {
2,234✔
1873
                r = serialize_item_format(f, "exec-context-coredump-filter", "%"PRIx64, c->coredump_filter);
×
1874
                if (r < 0)
×
1875
                        return r;
1876
        }
1877

1878
        for (unsigned i = 0; i < RLIM_NLIMITS; i++) {
37,978✔
1879
                _cleanup_free_ char *key = NULL, *limit = NULL;
4,461✔
1880

1881
                if (!c->rlimit[i])
35,744✔
1882
                        continue;
31,283✔
1883

1884
                key = strjoin("exec-context-limit-", rlimit_to_string(i));
4,461✔
1885
                if (!key)
4,461✔
1886
                        return log_oom_debug();
×
1887

1888
                r = rlimit_format(c->rlimit[i], &limit);
4,461✔
1889
                if (r < 0)
4,461✔
1890
                        return r;
1891

1892
                r = serialize_item(f, key, limit);
4,461✔
1893
                if (r < 0)
4,461✔
1894
                        return r;
1895
        }
1896

1897
        if (c->ioprio_set) {
2,234✔
1898
                r = serialize_item_format(f, "exec-context-ioprio", "%d", c->ioprio);
6✔
1899
                if (r < 0)
6✔
1900
                        return r;
1901
        }
1902

1903
        if (c->cpu_sched_set) {
2,234✔
1904
                _cleanup_free_ char *policy_str = NULL;
×
1905

1906
                r = sched_policy_to_string_alloc(c->cpu_sched_policy, &policy_str);
×
1907
                if (r < 0)
×
1908
                        return r;
1909

1910
                r = serialize_item(f, "exec-context-cpu-scheduling-policy", policy_str);
×
1911
                if (r < 0)
×
1912
                        return r;
1913

1914
                r = serialize_item_format(f, "exec-context-cpu-scheduling-priority", "%i", c->cpu_sched_priority);
×
1915
                if (r < 0)
×
1916
                        return r;
1917

1918
                r = serialize_bool_elide(f, "exec-context-cpu-scheduling-reset-on-fork", c->cpu_sched_reset_on_fork);
×
1919
                if (r < 0)
×
1920
                        return r;
1921
        }
1922

1923
        if (c->cpu_set.set) {
2,234✔
1924
                _cleanup_free_ char *affinity = NULL;
×
1925

1926
                affinity = cpu_set_to_range_string(&c->cpu_set);
×
1927
                if (!affinity)
×
1928
                        return log_oom_debug();
×
1929

1930
                r = serialize_item(f, "exec-context-cpu-affinity", affinity);
×
1931
                if (r < 0)
×
1932
                        return r;
1933
        }
1934

1935
        if (mpol_is_valid(numa_policy_get_type(&c->numa_policy))) {
2,234✔
1936
                _cleanup_free_ char *nodes = NULL;
×
1937

1938
                nodes = cpu_set_to_range_string(&c->numa_policy.nodes);
×
1939
                if (!nodes)
×
1940
                        return log_oom_debug();
×
1941

1942
                if (nodes) {
×
1943
                        r = serialize_item(f, "exec-context-numa-mask", nodes);
×
1944
                        if (r < 0)
×
1945
                                return r;
1946
                }
1947

1948
                r = serialize_item_format(f, "exec-context-numa-policy", "%d", c->numa_policy.type);
×
1949
                if (r < 0)
×
1950
                        return r;
1951
        }
1952

1953
        r = serialize_bool_elide(f, "exec-context-cpu-affinity-from-numa", c->cpu_affinity_from_numa);
2,234✔
1954
        if (r < 0)
2,234✔
1955
                return r;
1956

1957
        if (c->timer_slack_nsec != NSEC_INFINITY) {
2,234✔
1958
                r = serialize_item_format(f, "exec-context-timer-slack-nsec", NSEC_FMT, c->timer_slack_nsec);
×
1959
                if (r < 0)
×
1960
                        return r;
1961
        }
1962

1963
        r = serialize_item(f, "exec-context-std-input", exec_input_to_string(c->std_input));
2,234✔
1964
        if (r < 0)
2,234✔
1965
                return r;
1966

1967
        r = serialize_item(f, "exec-context-std-output", exec_output_to_string(c->std_output));
2,234✔
1968
        if (r < 0)
2,234✔
1969
                return r;
1970

1971
        r = serialize_item(f, "exec-context-std-error", exec_output_to_string(c->std_error));
2,234✔
1972
        if (r < 0)
2,234✔
1973
                return r;
1974

1975
        r = serialize_bool_elide(f, "exec-context-stdio-as-fds", c->stdio_as_fds);
2,234✔
1976
        if (r < 0)
2,234✔
1977
                return r;
1978

1979
        switch (c->std_input) {
2,234✔
1980
        case EXEC_INPUT_NAMED_FD:
×
1981
                r = serialize_item(f, "exec-context-std-input-fd-name", c->stdio_fdname[STDIN_FILENO]);
×
1982
                if (r < 0)
×
1983
                        return r;
1984
                break;
1985

1986
        case EXEC_INPUT_FILE:
×
1987
                r = serialize_item(f, "exec-context-std-input-file", c->stdio_file[STDIN_FILENO]);
×
1988
                if (r < 0)
×
1989
                        return r;
1990
                break;
1991

1992
        default:
2,234✔
1993
                ;
2,234✔
1994
        }
1995

1996
        r = serialize_std_out_err(c, f, STDOUT_FILENO);
2,234✔
1997
        if (r < 0)
2,234✔
1998
                return r;
1999

2000
        r = serialize_std_out_err(c, f, STDERR_FILENO);
2,234✔
2001
        if (r < 0)
2,234✔
2002
                return r;
2003

2004
        r = serialize_item_base64mem(f, "exec-context-stdin-data", c->stdin_data, c->stdin_data_size);
2,234✔
2005
        if (r < 0)
2,234✔
2006
                return r;
2007

2008
        r = serialize_item(f, "exec-context-tty-path", c->tty_path);
2,234✔
2009
        if (r < 0)
2,234✔
2010
                return r;
2011

2012
        r = serialize_bool_elide(f, "exec-context-tty-reset", c->tty_reset);
2,234✔
2013
        if (r < 0)
2,234✔
2014
                return r;
2015

2016
        r = serialize_bool_elide(f, "exec-context-tty-vhangup", c->tty_vhangup);
2,234✔
2017
        if (r < 0)
2,234✔
2018
                return r;
2019

2020
        r = serialize_bool_elide(f, "exec-context-tty-vt-disallocate", c->tty_vt_disallocate);
2,234✔
2021
        if (r < 0)
2,234✔
2022
                return r;
2023

2024
        r = serialize_item_format(f, "exec-context-tty-rows", "%u", c->tty_rows);
2,234✔
2025
        if (r < 0)
2,234✔
2026
                return r;
2027

2028
        r = serialize_item_format(f, "exec-context-tty-columns", "%u", c->tty_cols);
2,234✔
2029
        if (r < 0)
2,234✔
2030
                return r;
2031

2032
        r = serialize_item_format(f, "exec-context-syslog-priority", "%i", c->syslog_priority);
2,234✔
2033
        if (r < 0)
2,234✔
2034
                return r;
2035

2036
        r = serialize_bool(f, "exec-context-syslog-level-prefix", c->syslog_level_prefix);
2,234✔
2037
        if (r < 0)
2,234✔
2038
                return r;
2039

2040
        r = serialize_item(f, "exec-context-syslog-identifier", c->syslog_identifier);
2,234✔
2041
        if (r < 0)
2,234✔
2042
                return r;
2043

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

2050
        if (c->log_ratelimit.interval > 0) {
2,234✔
2051
                r = serialize_usec(f, "exec-context-log-ratelimit-interval-usec", c->log_ratelimit.interval);
×
2052
                if (r < 0)
×
2053
                        return r;
2054
        }
2055

2056
        if (c->log_ratelimit.burst > 0) {
2,234✔
2057
                r = serialize_item_format(f, "exec-context-log-ratelimit-burst", "%u", c->log_ratelimit.burst);
×
2058
                if (r < 0)
×
2059
                        return r;
2060
        }
2061

2062
        r = serialize_string_set(f, "exec-context-log-filter-allowed-patterns", c->log_filter_allowed_patterns);
2,234✔
2063
        if (r < 0)
2,234✔
2064
                return r;
2065

2066
        r = serialize_string_set(f, "exec-context-log-filter-denied-patterns", c->log_filter_denied_patterns);
2,234✔
2067
        if (r < 0)
2,234✔
2068
                return r;
2069

2070
        FOREACH_ARRAY(field, c->log_extra_fields, c->n_log_extra_fields) {
2,234✔
2071
                r = serialize_item(f, "exec-context-log-extra-fields", field->iov_base);
×
2072
                if (r < 0)
×
2073
                        return r;
2074
        }
2075

2076
        r = serialize_item(f, "exec-context-log-namespace", c->log_namespace);
2,234✔
2077
        if (r < 0)
2,234✔
2078
                return r;
2079

2080
        if (c->secure_bits != 0) {
2,234✔
2081
                r = serialize_item_format(f, "exec-context-secure-bits", "%d", c->secure_bits);
×
2082
                if (r < 0)
×
2083
                        return r;
2084
        }
2085

2086
        if (c->capability_bounding_set != CAP_MASK_UNSET) {
2,234✔
2087
                r = serialize_item_format(f, "exec-context-capability-bounding-set", "%" PRIu64, c->capability_bounding_set);
276✔
2088
                if (r < 0)
276✔
2089
                        return r;
2090
        }
2091

2092
        if (c->capability_ambient_set != 0) {
2,234✔
2093
                r = serialize_item_format(f, "exec-context-capability-ambient-set", "%" PRIu64, c->capability_ambient_set);
76✔
2094
                if (r < 0)
76✔
2095
                        return r;
2096
        }
2097

2098
        if (c->user) {
2,234✔
2099
                r = serialize_item(f, "exec-context-user", c->user);
157✔
2100
                if (r < 0)
157✔
2101
                        return r;
2102
        }
2103

2104
        r = serialize_item(f, "exec-context-group", c->group);
2,234✔
2105
        if (r < 0)
2,234✔
2106
                return r;
2107

2108
        r = serialize_bool_elide(f, "exec-context-dynamic-user", c->dynamic_user);
2,234✔
2109
        if (r < 0)
2,234✔
2110
                return r;
2111

2112
        r = serialize_strv(f, "exec-context-supplementary-groups", c->supplementary_groups);
2,234✔
2113
        if (r < 0)
2,234✔
2114
                return r;
2115

2116
        r = serialize_item_tristate(f, "exec-context-set-login-environment", c->set_login_environment);
2,234✔
2117
        if (r < 0)
×
2118
                return r;
2119

2120
        r = serialize_item(f, "exec-context-pam-name", c->pam_name);
2,234✔
2121
        if (r < 0)
2,234✔
2122
                return r;
2123

2124
        r = serialize_strv(f, "exec-context-read-write-paths", c->read_write_paths);
2,234✔
2125
        if (r < 0)
2,234✔
2126
                return r;
2127

2128
        r = serialize_strv(f, "exec-context-read-only-paths", c->read_only_paths);
2,234✔
2129
        if (r < 0)
2,234✔
2130
                return r;
2131

2132
        r = serialize_strv(f, "exec-context-inaccessible-paths", c->inaccessible_paths);
2,234✔
2133
        if (r < 0)
2,234✔
2134
                return r;
2135

2136
        r = serialize_strv(f, "exec-context-exec-paths", c->exec_paths);
2,234✔
2137
        if (r < 0)
2,234✔
2138
                return r;
2139

2140
        r = serialize_strv(f, "exec-context-no-exec-paths", c->no_exec_paths);
2,234✔
2141
        if (r < 0)
2,234✔
2142
                return r;
2143

2144
        r = serialize_strv(f, "exec-context-exec-search-path", c->exec_search_path);
2,234✔
2145
        if (r < 0)
2,234✔
2146
                return r;
2147

2148
        r = serialize_item_format(f, "exec-context-mount-propagation-flag", "%lu", c->mount_propagation_flag);
2,234✔
2149
        if (r < 0)
2,234✔
2150
                return r;
2151

2152
        FOREACH_ARRAY(mount, c->bind_mounts, c->n_bind_mounts) {
2,249✔
2153
                _cleanup_free_ char *src_escaped = NULL, *dst_escaped = NULL;
15✔
2154

2155
                src_escaped = shell_escape(mount->source, ":" WHITESPACE);
15✔
2156
                if (!src_escaped)
15✔
2157
                        return log_oom_debug();
×
2158

2159
                dst_escaped = shell_escape(mount->destination, ":" WHITESPACE);
15✔
2160
                if (!dst_escaped)
15✔
2161
                        return log_oom_debug();
×
2162

2163
                r = serialize_item_format(f,
15✔
2164
                                          mount->read_only ? "exec-context-bind-read-only-path" : "exec-context-bind-path",
15✔
2165
                                          "%s%s:%s:%s",
2166
                                          mount->ignore_enoent ? "-" : "",
15✔
2167
                                          src_escaped,
2168
                                          dst_escaped,
2169
                                          mount->recursive ? "rbind" : "norbind");
15✔
2170
                if (r < 0)
15✔
2171
                        return r;
2172
        }
2173

2174
        FOREACH_ARRAY(tmpfs, c->temporary_filesystems, c->n_temporary_filesystems) {
2,238✔
2175
                _cleanup_free_ char *escaped = NULL;
4✔
2176

2177
                if (!isempty(tmpfs->options)) {
4✔
2178
                        escaped = shell_escape(tmpfs->options, ":");
×
2179
                        if (!escaped)
×
2180
                                return log_oom_debug();
×
2181
                }
2182

2183
                r = serialize_item_format(f, "exec-context-temporary-filesystems", "%s%s%s",
×
2184
                                          tmpfs->path,
2185
                                          isempty(escaped) ? "" : ":",
4✔
2186
                                          strempty(escaped));
2187
                if (r < 0)
4✔
2188
                        return r;
2189
        }
2190

2191
        r = serialize_item(f, "exec-context-utmp-id", c->utmp_id);
2,234✔
2192
        if (r < 0)
2,234✔
2193
                return r;
2194

2195
        r = serialize_item(f, "exec-context-utmp-mode", exec_utmp_mode_to_string(c->utmp_mode));
2,234✔
2196
        if (r < 0)
2,234✔
2197
                return r;
2198

2199
        r = serialize_bool_elide(f, "exec-context-no-new-privileges", c->no_new_privileges);
2,234✔
2200
        if (r < 0)
2,234✔
2201
                return r;
2202

2203
        if (c->selinux_context) {
2,234✔
2204
                r = serialize_item_format(f, "exec-context-selinux-context",
×
2205
                                          "%s%s",
2206
                                          c->selinux_context_ignore ? "-" : "",
×
2207
                                          c->selinux_context);
2208
                if (r < 0)
×
2209
                        return r;
2210
        }
2211

2212
        if (c->apparmor_profile) {
2,234✔
2213
                r = serialize_item_format(f, "exec-context-apparmor-profile",
×
2214
                                          "%s%s",
2215
                                          c->apparmor_profile_ignore ? "-" : "",
×
2216
                                          c->apparmor_profile);
2217
                if (r < 0)
×
2218
                        return r;
2219
        }
2220

2221
        if (c->smack_process_label) {
2,234✔
2222
                r = serialize_item_format(f, "exec-context-smack-process-label",
×
2223
                                          "%s%s",
2224
                                          c->smack_process_label_ignore ? "-" : "",
×
2225
                                          c->smack_process_label);
2226
                if (r < 0)
×
2227
                        return r;
2228
        }
2229

2230
        if (c->personality != PERSONALITY_INVALID) {
2,234✔
2231
                r = serialize_item(f, "exec-context-personality", personality_to_string(c->personality));
×
2232
                if (r < 0)
×
2233
                        return r;
2234
        }
2235

2236
        r = serialize_bool_elide(f, "exec-context-lock-personality", c->lock_personality);
2,234✔
2237
        if (r < 0)
2,234✔
2238
                return r;
2239

2240
#if HAVE_SECCOMP
2241
        if (!hashmap_isempty(c->syscall_filter)) {
2,234✔
2242
                void *errno_num, *id;
238✔
2243
                HASHMAP_FOREACH_KEY(errno_num, id, c->syscall_filter) {
93,082✔
2244
                        r = serialize_item_format(f, "exec-context-syscall-filter", "%d %d", PTR_TO_INT(id) - 1, PTR_TO_INT(errno_num));
92,844✔
2245
                        if (r < 0)
92,844✔
2246
                                return r;
×
2247
                }
2248
        }
2249

2250
        if (!set_isempty(c->syscall_archs)) {
2,234✔
2251
                void *id;
238✔
2252
                SET_FOREACH(id, c->syscall_archs) {
476✔
2253
                        r = serialize_item_format(f, "exec-context-syscall-archs", "%u", PTR_TO_UINT(id) - 1);
238✔
2254
                        if (r < 0)
238✔
2255
                                return r;
×
2256
                }
2257
        }
2258

2259
        if (c->syscall_errno > 0) {
2,234✔
2260
                r = serialize_item_format(f, "exec-context-syscall-errno", "%d", c->syscall_errno);
2,234✔
2261
                if (r < 0)
2,234✔
2262
                        return r;
2263
        }
2264

2265
        r = serialize_bool_elide(f, "exec-context-syscall-allow-list", c->syscall_allow_list);
2,234✔
2266
        if (r < 0)
2,234✔
2267
                return r;
2268

2269
        if (!hashmap_isempty(c->syscall_log)) {
2,234✔
2270
                void *errno_num, *id;
×
2271
                HASHMAP_FOREACH_KEY(errno_num, id, c->syscall_log) {
×
2272
                        r = serialize_item_format(f, "exec-context-syscall-log", "%d %d", PTR_TO_INT(id) - 1, PTR_TO_INT(errno_num));
×
2273
                        if (r < 0)
×
2274
                                return r;
×
2275
                }
2276
        }
2277

2278
        r = serialize_bool_elide(f, "exec-context-syscall-log-allow-list", c->syscall_log_allow_list);
2,234✔
2279
        if (r < 0)
2,234✔
2280
                return r;
2281
#endif
2282

2283
        if (c->restrict_namespaces != NAMESPACE_FLAGS_INITIAL) {
2,234✔
2284
                r = serialize_item_format(f, "exec-context-restrict-namespaces", "%lu", c->restrict_namespaces);
188✔
2285
                if (r < 0)
188✔
2286
                        return r;
2287
        }
2288

2289
        if (c->delegate_namespaces != NAMESPACE_FLAGS_INITIAL) {
2,234✔
2290
                r = serialize_item_format(f, "exec-context-delegate-namespaces", "%lu", c->delegate_namespaces);
9✔
2291
                if (r < 0)
9✔
2292
                        return r;
2293
        }
2294

2295
#if HAVE_LIBBPF
2296
        if (exec_context_restrict_filesystems_set(c)) {
2,234✔
2297
                char *fs;
×
2298
                SET_FOREACH(fs, c->restrict_filesystems) {
×
2299
                        r = serialize_item(f, "exec-context-restrict-filesystems", fs);
×
2300
                        if (r < 0)
×
2301
                                return r;
×
2302
                }
2303
        }
2304

2305
        r = serialize_bool_elide(f, "exec-context-restrict-filesystems-allow-list", c->restrict_filesystems_allow_list);
2,234✔
2306
        if (r < 0)
2,234✔
2307
                return r;
2308
#endif
2309

2310
        if (!set_isempty(c->address_families)) {
2,234✔
2311
                void *afp;
238✔
2312

2313
                SET_FOREACH(afp, c->address_families) {
1,134✔
2314
                        int af = PTR_TO_INT(afp);
896✔
2315

2316
                        if (af <= 0 || af >= af_max())
896✔
2317
                                continue;
×
2318

2319
                        r = serialize_item_format(f, "exec-context-address-families", "%d", af);
896✔
2320
                        if (r < 0)
896✔
2321
                                return r;
×
2322
                }
2323
        }
2324

2325
        r = serialize_bool_elide(f, "exec-context-address-families-allow-list", c->address_families_allow_list);
2,234✔
2326
        if (r < 0)
2,234✔
2327
                return r;
2328

2329
        r = serialize_item(f, "exec-context-network-namespace-path", c->network_namespace_path);
2,234✔
2330
        if (r < 0)
2,234✔
2331
                return r;
2332

2333
        r = serialize_item(f, "exec-context-ipc-namespace-path", c->ipc_namespace_path);
2,234✔
2334
        if (r < 0)
2,234✔
2335
                return r;
2336

2337
        FOREACH_ARRAY(mount, c->mount_images, c->n_mount_images) {
2,234✔
2338
                _cleanup_free_ char *s = NULL, *source_escaped = NULL, *dest_escaped = NULL;
×
2339

2340
                source_escaped = shell_escape(mount->source, WHITESPACE);
×
2341
                if (!source_escaped)
×
2342
                        return log_oom_debug();
×
2343

2344
                dest_escaped = shell_escape(mount->destination, WHITESPACE);
×
2345
                if (!dest_escaped)
×
2346
                        return log_oom_debug();
×
2347

2348
                s = strjoin(mount->ignore_enoent ? "-" : "",
×
2349
                            source_escaped,
2350
                            " ",
2351
                            dest_escaped);
2352
                if (!s)
×
2353
                        return log_oom_debug();
×
2354

2355
                LIST_FOREACH(mount_options, o, mount->mount_options) {
×
2356
                        _cleanup_free_ char *escaped = NULL;
×
2357

2358
                        if (isempty(o->options))
×
2359
                                continue;
×
2360

2361
                        escaped = shell_escape(o->options, ":");
×
2362
                        if (!escaped)
×
2363
                                return log_oom_debug();
×
2364

2365
                        if (!strextend(&s,
×
2366
                                       " ",
2367
                                       partition_designator_to_string(o->partition_designator),
2368
                                       ":",
2369
                                       escaped))
2370
                                return log_oom_debug();
×
2371
                }
2372

2373
                r = serialize_item(f, "exec-context-mount-image", s);
×
2374
                if (r < 0)
×
2375
                        return r;
2376
        }
2377

2378
        FOREACH_ARRAY(mount, c->extension_images, c->n_extension_images) {
2,234✔
2379
                _cleanup_free_ char *s = NULL, *source_escaped = NULL;
×
2380

2381
                source_escaped = shell_escape(mount->source, ":" WHITESPACE);
×
2382
                if (!source_escaped)
×
2383
                        return log_oom_debug();
×
2384

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

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

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

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

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

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

2413
        r = serialize_strv(f, "exec-context-extension-directories", c->extension_directories);
2,234✔
2414
        if (r < 0)
2,234✔
2415
                return r;
2416

2417
        ExecSetCredential *sc;
2,234✔
2418
        HASHMAP_FOREACH(sc, c->set_credentials) {
2,234✔
2419
                _cleanup_free_ char *data = NULL;
×
2420

2421
                if (base64mem(sc->data, sc->size, &data) < 0)
×
2422
                        return log_oom_debug();
×
2423

2424
                r = serialize_item_format(f, "exec-context-set-credentials", "%s %s %s", sc->id, data, yes_no(sc->encrypted));
×
2425
                if (r < 0)
×
2426
                        return r;
2427
        }
2428

2429
        ExecLoadCredential *lc;
2,234✔
2430
        HASHMAP_FOREACH(lc, c->load_credentials) {
2,242✔
2431
                r = serialize_item_format(f, "exec-context-load-credentials", "%s %s %s", lc->id, lc->path, yes_no(lc->encrypted));
15✔
2432
                if (r < 0)
8✔
2433
                        return r;
×
2434
        }
2435

2436
        ExecImportCredential *ic;
2,234✔
2437
        ORDERED_SET_FOREACH(ic, c->import_credentials) {
3,043✔
2438
                r = serialize_item_format(f, "exec-context-import-credentials", "%s%s%s",
1,570✔
2439
                                          ic->glob,
2440
                                          ic->rename ? " " : "",
2441
                                          strempty(ic->rename));
809✔
2442
                if (r < 0)
809✔
2443
                        return r;
×
2444
        }
2445

2446
        r = serialize_image_policy(f, "exec-context-root-image-policy", c->root_image_policy);
2,234✔
2447
        if (r < 0)
2,234✔
2448
                return r;
2449

2450
        r = serialize_image_policy(f, "exec-context-mount-image-policy", c->mount_image_policy);
2,234✔
2451
        if (r < 0)
2,234✔
2452
                return r;
2453

2454
        r = serialize_image_policy(f, "exec-context-extension-image-policy", c->extension_image_policy);
2,234✔
2455
        if (r < 0)
2,234✔
2456
                return r;
2457

2458
        fputc('\n', f); /* End marker */
2,234✔
2459

2460
        return 0;
2461
}
2462

2463
static int exec_context_deserialize(ExecContext *c, FILE *f) {
11,737✔
2464
        int r;
11,737✔
2465

2466
        assert(f);
11,737✔
2467

2468
        if (!c)
11,737✔
2469
                return 0;
2470

2471
        for (;;) {
1,322,065✔
2472
                _cleanup_free_ char *l = NULL;
1,310,328✔
2473
                const char *val;
1,322,065✔
2474

2475
                r = deserialize_read_line(f, &l);
1,322,065✔
2476
                if (r < 0)
1,322,065✔
2477
                        return r;
2478
                if (r == 0) /* eof or end marker */
1,322,065✔
2479
                        break;
2480

2481
                if ((val = startswith(l, "exec-context-environment="))) {
1,310,328✔
2482
                        r = deserialize_strv(val, &c->environment);
3,910✔
2483
                        if (r < 0)
3,910✔
2484
                                return r;
2485
                } else if ((val = startswith(l, "exec-context-environment-files="))) {
1,306,418✔
2486
                        r = deserialize_strv(val, &c->environment_files);
338✔
2487
                        if (r < 0)
338✔
2488
                                return r;
2489
                } else if ((val = startswith(l, "exec-context-pass-environment="))) {
1,306,080✔
2490
                        r = deserialize_strv(val, &c->pass_environment);
435✔
2491
                        if (r < 0)
435✔
2492
                                return r;
2493
                } else if ((val = startswith(l, "exec-context-unset-environment="))) {
1,305,645✔
2494
                        r = deserialize_strv(val, &c->unset_environment);
1,392✔
2495
                        if (r < 0)
1,392✔
2496
                                return r;
2497
                } else if ((val = startswith(l, "exec-context-working-directory="))) {
1,304,253✔
2498
                        ssize_t k;
863✔
2499
                        char *p;
863✔
2500

2501
                        k = cunescape(val, 0, &p);
863✔
2502
                        if (k < 0)
863✔
2503
                                return k;
×
2504
                        free_and_replace(c->working_directory, p);
863✔
2505
                } else if ((val = startswith(l, "exec-context-root-directory="))) {
1,303,390✔
2506
                        ssize_t k;
7✔
2507
                        char *p;
7✔
2508

2509
                        k = cunescape(val, 0, &p);
7✔
2510
                        if (k < 0)
7✔
2511
                                return k;
×
2512
                        free_and_replace(c->root_directory, p);
7✔
2513
                } else if ((val = startswith(l, "exec-context-root-image="))) {
1,303,383✔
2514
                        ssize_t k;
8✔
2515
                        char *p;
8✔
2516

2517
                        k = cunescape(val, 0, &p);
8✔
2518
                        if (k < 0)
8✔
2519
                                return k;
×
2520
                        free_and_replace(c->root_image, p);
8✔
2521
                } else if ((val = startswith(l, "exec-context-root-image-options="))) {
1,303,375✔
2522
                        for (;;) {
×
2523
                                _cleanup_free_ char *word = NULL, *mount_options = NULL, *partition = NULL;
×
2524
                                PartitionDesignator partition_designator;
×
2525
                                MountOptions *o = NULL;
×
2526
                                const char *p;
×
2527

2528
                                r = extract_first_word(&val, &word, NULL, 0);
×
2529
                                if (r < 0)
×
2530
                                        return r;
2531
                                if (r == 0)
×
2532
                                        break;
2533

2534
                                p = word;
×
2535
                                r = extract_many_words(&p, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &partition, &mount_options);
×
2536
                                if (r < 0)
×
2537
                                        return r;
2538
                                if (r == 0)
×
2539
                                        continue;
×
2540

2541
                                partition_designator = partition_designator_from_string(partition);
×
2542
                                if (partition_designator < 0)
×
2543
                                        return -EINVAL;
2544

2545
                                o = new(MountOptions, 1);
×
2546
                                if (!o)
×
2547
                                        return log_oom_debug();
×
2548
                                *o = (MountOptions) {
×
2549
                                        .partition_designator = partition_designator,
2550
                                        .options = TAKE_PTR(mount_options),
×
2551
                                };
2552
                                LIST_APPEND(mount_options, c->root_image_options, o);
×
2553
                        }
2554
                } else if ((val = startswith(l, "exec-context-root-verity="))) {
1,303,375✔
2555
                        r = free_and_strdup(&c->root_verity, val);
×
2556
                        if (r < 0)
×
2557
                                return r;
2558
                } else if ((val = startswith(l, "exec-context-root-hash-path="))) {
1,303,375✔
2559
                        r = free_and_strdup(&c->root_hash_path, val);
×
2560
                        if (r < 0)
×
2561
                                return r;
2562
                } else if ((val = startswith(l, "exec-context-root-hash-sig-path="))) {
1,303,375✔
2563
                        r = free_and_strdup(&c->root_hash_sig_path, val);
×
2564
                        if (r < 0)
×
2565
                                return r;
2566
                } else if ((val = startswith(l, "exec-context-root-hash="))) {
1,303,375✔
2567
                        c->root_hash = mfree(c->root_hash);
4✔
2568
                        r = unhexmem(val, &c->root_hash, &c->root_hash_size);
4✔
2569
                        if (r < 0)
4✔
2570
                                return r;
2571
                } else if ((val = startswith(l, "exec-context-root-hash-sig="))) {
1,303,371✔
2572
                        c->root_hash_sig = mfree(c->root_hash_sig);
×
2573
                        r= unbase64mem(val, &c->root_hash_sig, &c->root_hash_sig_size);
×
2574
                        if (r < 0)
×
2575
                                return r;
2576
                } else if ((val = startswith(l, "exec-context-root-ephemeral="))) {
1,303,371✔
2577
                        r = parse_boolean(val);
×
2578
                        if (r < 0)
×
2579
                                return r;
2580
                        c->root_ephemeral = r;
×
2581
                } else if ((val = startswith(l, "exec-context-umask="))) {
1,303,371✔
2582
                        r = parse_mode(val, &c->umask);
11,737✔
2583
                        if (r < 0)
11,737✔
2584
                                return r;
2585
                } else if ((val = startswith(l, "exec-context-private-non-blocking="))) {
1,291,634✔
2586
                        r = parse_boolean(val);
×
2587
                        if (r < 0)
×
2588
                                return r;
2589
                        c->non_blocking = r;
×
2590
                } else if ((val = startswith(l, "exec-context-private-mounts="))) {
1,291,634✔
2591
                        r = safe_atoi(val, &c->private_mounts);
131✔
2592
                        if (r < 0)
131✔
2593
                                return r;
2594
                } else if ((val = startswith(l, "exec-context-mount-api-vfs="))) {
1,291,503✔
2595
                        r = safe_atoi(val, &c->mount_apivfs);
30✔
2596
                        if (r < 0)
30✔
2597
                                return r;
2598
                } else if ((val = startswith(l, "exec-context-bind-log-sockets="))) {
1,291,473✔
2599
                        r = safe_atoi(val, &c->bind_log_sockets);
2✔
2600
                        if (r < 0)
2✔
2601
                                return r;
2602
                } else if ((val = startswith(l, "exec-context-memory-ksm="))) {
1,291,471✔
2603
                        r = safe_atoi(val, &c->memory_ksm);
×
2604
                        if (r < 0)
×
2605
                                return r;
2606
                } else if ((val = startswith(l, "exec-context-private-tmp="))) {
1,291,471✔
2607
                        c->private_tmp = private_tmp_from_string(val);
11,737✔
2608
                        if (c->private_tmp < 0)
11,737✔
2609
                                return c->private_tmp;
2610
                } else if ((val = startswith(l, "exec-context-private-var-tmp="))) {
1,279,734✔
2611
                        c->private_var_tmp = private_tmp_from_string(val);
11,737✔
2612
                        if (c->private_var_tmp < 0)
11,737✔
2613
                                return c->private_var_tmp;
2614
                } else if ((val = startswith(l, "exec-context-private-devices="))) {
1,267,997✔
2615
                        r = parse_boolean(val);
735✔
2616
                        if (r < 0)
735✔
2617
                                return r;
2618
                        c->private_devices = r;
735✔
2619
                } else if ((val = startswith(l, "exec-context-protect-kernel-tunables="))) {
1,267,262✔
2620
                        r = parse_boolean(val);
542✔
2621
                        if (r < 0)
542✔
2622
                                return r;
2623
                        c->protect_kernel_tunables = r;
542✔
2624
                } else if ((val = startswith(l, "exec-context-protect-kernel-modules="))) {
1,266,720✔
2625
                        r = parse_boolean(val);
1,761✔
2626
                        if (r < 0)
1,761✔
2627
                                return r;
2628
                        c->protect_kernel_modules = r;
1,761✔
2629
                } else if ((val = startswith(l, "exec-context-protect-kernel-logs="))) {
1,264,959✔
2630
                        r = parse_boolean(val);
1,761✔
2631
                        if (r < 0)
1,761✔
2632
                                return r;
2633
                        c->protect_kernel_logs = r;
1,761✔
2634
                } else if ((val = startswith(l, "exec-context-protect-clock="))) {
1,263,198✔
2635
                        r = parse_boolean(val);
1,595✔
2636
                        if (r < 0)
1,595✔
2637
                                return r;
2638
                        c->protect_clock = r;
1,595✔
2639
                } else if ((val = startswith(l, "exec-context-protect-control-groups="))) {
1,261,603✔
2640
                        r = protect_control_groups_from_string(val);
11,737✔
2641
                        if (r < 0)
11,737✔
2642
                                return r;
2643
                        c->protect_control_groups = r;
11,737✔
2644
                } else if ((val = startswith(l, "exec-context-private-network="))) {
1,249,866✔
2645
                        r = parse_boolean(val);
64✔
2646
                        if (r < 0)
64✔
2647
                                return r;
2648
                        c->private_network = r;
64✔
2649
                } else if ((val = startswith(l, "exec-context-private-users="))) {
1,249,802✔
2650
                        c->private_users = private_users_from_string(val);
11,737✔
2651
                        if (c->private_users < 0)
11,737✔
2652
                                return -EINVAL;
2653
                } else if ((val = startswith(l, "exec-context-private-ipc="))) {
1,238,065✔
2654
                        r = parse_boolean(val);
6✔
2655
                        if (r < 0)
6✔
2656
                                return r;
2657
                        c->private_ipc = r;
6✔
2658
                } else if ((val = startswith(l, "exec-context-private-pids="))) {
1,238,059✔
2659
                        c->private_pids = private_pids_from_string(val);
11,737✔
2660
                        if (c->private_pids < 0)
11,737✔
2661
                                return -EINVAL;
2662
                } else if ((val = startswith(l, "exec-context-remove-ipc="))) {
1,226,322✔
2663
                        r = parse_boolean(val);
70✔
2664
                        if (r < 0)
70✔
2665
                                return r;
2666
                        c->remove_ipc = r;
70✔
2667
                } else if ((val = startswith(l, "exec-context-protect-home="))) {
1,226,252✔
2668
                        c->protect_home = protect_home_from_string(val);
11,737✔
2669
                        if (c->protect_home < 0)
11,737✔
2670
                                return -EINVAL;
2671
                } else if ((val = startswith(l, "exec-context-protect-system="))) {
1,214,515✔
2672
                        c->protect_system = protect_system_from_string(val);
11,737✔
2673
                        if (c->protect_system < 0)
11,737✔
2674
                                return -EINVAL;
2675
                } else if ((val = startswith(l, "exec-context-same-pgrp="))) {
1,202,778✔
2676
                        r = parse_boolean(val);
867✔
2677
                        if (r < 0)
867✔
2678
                                return r;
2679
                        c->same_pgrp = r;
867✔
2680
                } else if ((val = startswith(l, "exec-context-non-blocking="))) {
1,201,911✔
2681
                        r = parse_boolean(val);
×
2682
                        if (r < 0)
×
2683
                                return r;
2684
                        c->non_blocking = r;
×
2685
                } else if ((val = startswith(l, "exec-context-ignore-sigpipe="))) {
1,201,911✔
2686
                        r = parse_boolean(val);
11,737✔
2687
                        if (r < 0)
11,737✔
2688
                                return r;
2689
                        c->ignore_sigpipe = r;
11,737✔
2690
                } else if ((val = startswith(l, "exec-context-memory-deny-write-execute="))) {
1,190,174✔
2691
                        r = parse_boolean(val);
2,253✔
2692
                        if (r < 0)
2,253✔
2693
                                return r;
2694
                        c->memory_deny_write_execute = r;
2,253✔
2695
                } else if ((val = startswith(l, "exec-context-restrict-realtime="))) {
1,187,921✔
2696
                        r = parse_boolean(val);
2,253✔
2697
                        if (r < 0)
2,253✔
2698
                                return r;
2699
                        c->restrict_realtime = r;
2,253✔
2700
                } else if ((val = startswith(l, "exec-context-restrict-suid-sgid="))) {
1,185,668✔
2701
                        r = parse_boolean(val);
2,191✔
2702
                        if (r < 0)
2,191✔
2703
                                return r;
2704
                        c->restrict_suid_sgid = r;
2,191✔
2705
                } else if ((val = startswith(l, "exec-context-keyring-mode="))) {
1,183,477✔
2706
                        c->keyring_mode = exec_keyring_mode_from_string(val);
11,737✔
2707
                        if (c->keyring_mode < 0)
11,737✔
2708
                                return -EINVAL;
2709
                } else if ((val = startswith(l, "exec-context-protect-hostname="))) {
1,171,740✔
2710
                        c->protect_hostname = protect_hostname_from_string(val);
11,737✔
2711
                        if (c->protect_hostname < 0)
11,737✔
2712
                                return -EINVAL;
2713
                } else if ((val = startswith(l, "exec-context-private-hostname="))) {
1,160,003✔
2714
                        r = free_and_strdup(&c->private_hostname, val);
4✔
2715
                        if (r < 0)
4✔
2716
                                return r;
2717
                } else if ((val = startswith(l, "exec-context-protect-proc="))) {
1,159,999✔
2718
                        c->protect_proc = protect_proc_from_string(val);
11,737✔
2719
                        if (c->protect_proc < 0)
11,737✔
2720
                                return -EINVAL;
2721
                } else if ((val = startswith(l, "exec-context-proc-subset="))) {
1,148,262✔
2722
                        c->proc_subset = proc_subset_from_string(val);
11,737✔
2723
                        if (c->proc_subset < 0)
11,737✔
2724
                                return -EINVAL;
2725
                } else if ((val = startswith(l, "exec-context-runtime-directory-preserve-mode="))) {
1,136,525✔
2726
                        c->runtime_directory_preserve_mode = exec_preserve_mode_from_string(val);
11,737✔
2727
                        if (c->runtime_directory_preserve_mode < 0)
11,737✔
2728
                                return -EINVAL;
2729
                } else if ((val = startswith(l, "exec-context-directories-"))) {
1,124,788✔
2730
                        _cleanup_free_ char *type = NULL, *mode = NULL;
×
2731
                        ExecDirectoryType dt;
58,685✔
2732

2733
                        r = extract_many_words(&val, "= ", 0, &type, &mode);
58,685✔
2734
                        if (r < 0)
58,685✔
2735
                                return r;
2736
                        if (r == 0 || !mode)
58,685✔
2737
                                return -EINVAL;
2738

2739
                        dt = exec_directory_type_from_string(type);
58,685✔
2740
                        if (dt < 0)
58,685✔
2741
                                return -EINVAL;
2742

2743
                        r = parse_mode(mode, &c->directories[dt].mode);
58,685✔
2744
                        if (r < 0)
58,685✔
2745
                                return r;
2746

2747
                        for (;;) {
62,467✔
2748
                                _cleanup_free_ char *tuple = NULL, *path = NULL, *only_create = NULL, *read_only = NULL;
62,360✔
2749
                                ExecDirectoryFlags exec_directory_flags = 0;
62,467✔
2750
                                const char *p;
62,467✔
2751

2752
                                /* Use EXTRACT_UNESCAPE_RELAX here, as we unescape the colons in subsequent calls */
2753
                                r = extract_first_word(&val, &tuple, WHITESPACE, EXTRACT_UNESCAPE_SEPARATORS|EXTRACT_UNESCAPE_RELAX);
62,467✔
2754
                                if (r < 0)
62,467✔
2755
                                        return r;
2756
                                if (r == 0)
62,467✔
2757
                                        break;
2758

2759
                                p = tuple;
3,782✔
2760
                                r = extract_many_words(&p, ":", EXTRACT_UNESCAPE_SEPARATORS, &path, &only_create, &read_only);
3,782✔
2761
                                if (r < 0)
3,782✔
2762
                                        return r;
2763
                                if (r < 2)
3,782✔
2764
                                        continue;
×
2765

2766
                                r = parse_boolean(only_create);
3,782✔
2767
                                if (r < 0)
3,782✔
2768
                                        return r;
2769
                                if (r > 0)
3,782✔
2770
                                        exec_directory_flags |= EXEC_DIRECTORY_ONLY_CREATE;
5✔
2771

2772
                                r = parse_boolean(read_only);
3,782✔
2773
                                if (r < 0)
3,782✔
2774
                                        return r;
2775
                                if (r > 0)
3,782✔
2776
                                        exec_directory_flags |= EXEC_DIRECTORY_READ_ONLY;
50✔
2777

2778
                                r = exec_directory_add(&c->directories[dt], path, /* symlink= */ NULL, exec_directory_flags);
3,782✔
2779
                                if (r < 0)
3,782✔
2780
                                        return r;
2781

2782
                                if (isempty(p))
3,782✔
2783
                                        continue;
3,675✔
2784

2785
                                for (;;) {
385✔
2786
                                        _cleanup_free_ char *link = NULL;
246✔
2787

2788
                                        r = extract_first_word(&p, &link, ":", EXTRACT_UNESCAPE_SEPARATORS);
246✔
2789
                                        if (r < 0)
246✔
2790
                                                return r;
2791
                                        if (r == 0)
246✔
2792
                                                break;
2793

2794
                                        r = strv_consume(&c->directories[dt].items[c->directories[dt].n_items - 1].symlinks, TAKE_PTR(link));
139✔
2795
                                        if (r < 0)
139✔
2796
                                                return r;
2797
                                }
2798
                        }
2799
                } else if ((val = startswith(l, "exec-context-timeout-clean-usec="))) {
1,066,103✔
2800
                        r = deserialize_usec(val, &c->timeout_clean_usec);
×
2801
                        if (r < 0)
×
2802
                                return r;
2803
                } else if ((val = startswith(l, "exec-context-nice="))) {
1,066,103✔
2804
                        r = safe_atoi(val, &c->nice);
15✔
2805
                        if (r < 0)
15✔
2806
                                return r;
2807
                        c->nice_set = true;
15✔
2808
                } else if ((val = startswith(l, "exec-context-working-directory-missing-ok="))) {
1,066,088✔
2809
                        r = parse_boolean(val);
803✔
2810
                        if (r < 0)
803✔
2811
                                return r;
2812
                        c->working_directory_missing_ok = r;
803✔
2813
                } else if ((val = startswith(l, "exec-context-working-directory-home="))) {
1,065,285✔
2814
                        r = parse_boolean(val);
151✔
2815
                        if (r < 0)
151✔
2816
                                return r;
2817
                        c->working_directory_home = r;
151✔
2818
                } else if ((val = startswith(l, "exec-context-oom-score-adjust="))) {
1,065,134✔
2819
                        r = safe_atoi(val, &c->oom_score_adjust);
1,313✔
2820
                        if (r < 0)
1,313✔
2821
                                return r;
2822
                        c->oom_score_adjust_set = true;
1,313✔
2823
                } else if ((val = startswith(l, "exec-context-coredump-filter="))) {
1,063,821✔
2824
                        r = safe_atoux64(val, &c->coredump_filter);
2✔
2825
                        if (r < 0)
2✔
2826
                                return r;
2827
                        c->coredump_filter_set = true;
2✔
2828
                } else if ((val = startswith(l, "exec-context-limit-"))) {
1,063,819✔
2829
                        _cleanup_free_ struct rlimit *rlimit = NULL;
×
2830
                        _cleanup_free_ char *limit = NULL;
23,469✔
2831
                        int type;
23,469✔
2832

2833
                        r = extract_first_word(&val, &limit, "=", 0);
23,469✔
2834
                        if (r < 0)
23,469✔
2835
                                return r;
2836
                        if (r == 0 || !val)
23,469✔
2837
                                return -EINVAL;
2838

2839
                        type = rlimit_from_string(limit);
23,469✔
2840
                        if (type < 0)
23,469✔
2841
                                return -EINVAL;
2842

2843
                        if (!c->rlimit[type]) {
23,469✔
2844
                                rlimit = new0(struct rlimit, 1);
23,469✔
2845
                                if (!rlimit)
23,469✔
2846
                                        return log_oom_debug();
×
2847

2848
                                r = rlimit_parse(type, val, rlimit);
23,469✔
2849
                                if (r < 0)
23,469✔
2850
                                        return r;
2851

2852
                                c->rlimit[type] = TAKE_PTR(rlimit);
23,469✔
2853
                        } else {
2854
                                r = rlimit_parse(type, val, c->rlimit[type]);
×
2855
                                if (r < 0)
×
2856
                                        return r;
2857
                        }
2858
                } else if ((val = startswith(l, "exec-context-ioprio="))) {
1,040,350✔
2859
                        r = safe_atoi(val, &c->ioprio);
8✔
2860
                        if (r < 0)
8✔
2861
                                return r;
2862
                        c->ioprio_set = true;
8✔
2863
                } else if ((val = startswith(l, "exec-context-cpu-scheduling-policy="))) {
1,040,342✔
2864
                        c->cpu_sched_policy = sched_policy_from_string(val);
×
2865
                        if (c->cpu_sched_policy < 0)
×
2866
                                return -EINVAL;
2867
                        c->cpu_sched_set = true;
×
2868
                } else if ((val = startswith(l, "exec-context-cpu-scheduling-priority="))) {
1,040,342✔
2869
                        r = safe_atoi(val, &c->cpu_sched_priority);
×
2870
                        if (r < 0)
×
2871
                                return r;
2872
                        c->cpu_sched_set = true;
×
2873
                } else if ((val = startswith(l, "exec-context-cpu-scheduling-reset-on-fork="))) {
1,040,342✔
2874
                        r = parse_boolean(val);
×
2875
                        if (r < 0)
×
2876
                                return r;
2877
                        c->cpu_sched_reset_on_fork = r;
×
2878
                        c->cpu_sched_set = true;
×
2879
                } else if ((val = startswith(l, "exec-context-cpu-affinity="))) {
1,040,342✔
2880
                        if (c->cpu_set.set)
×
2881
                                return -EINVAL; /* duplicated */
2882

2883
                        r = parse_cpu_set(val, &c->cpu_set);
×
2884
                        if (r < 0)
×
2885
                                return r;
2886
                } else if ((val = startswith(l, "exec-context-numa-mask="))) {
1,040,342✔
2887
                        if (c->numa_policy.nodes.set)
19✔
2888
                                return -EINVAL; /* duplicated */
2889

2890
                        r = parse_cpu_set(val, &c->numa_policy.nodes);
19✔
2891
                        if (r < 0)
19✔
2892
                                return r;
2893
                } else if ((val = startswith(l, "exec-context-numa-policy="))) {
1,040,323✔
2894
                        r = safe_atoi(val, &c->numa_policy.type);
19✔
2895
                        if (r < 0)
19✔
2896
                                return r;
2897
                } else if ((val = startswith(l, "exec-context-cpu-affinity-from-numa="))) {
1,040,304✔
2898
                        r = parse_boolean(val);
2✔
2899
                        if (r < 0)
2✔
2900
                                return r;
2901
                        c->cpu_affinity_from_numa = r;
2✔
2902
                } else if ((val = startswith(l, "exec-context-timer-slack-nsec="))) {
1,040,302✔
2903
                        r = deserialize_usec(val, (usec_t *)&c->timer_slack_nsec);
×
2904
                        if (r < 0)
×
2905
                                return r;
2906
                } else if ((val = startswith(l, "exec-context-std-input="))) {
1,040,302✔
2907
                        c->std_input = exec_input_from_string(val);
11,737✔
2908
                        if (c->std_input < 0)
11,737✔
2909
                                return c->std_input;
2910
                } else if ((val = startswith(l, "exec-context-std-output="))) {
1,028,565✔
2911
                        c->std_output = exec_output_from_string(val);
11,737✔
2912
                        if (c->std_output < 0)
11,737✔
2913
                                return c->std_output;
2914
                } else if ((val = startswith(l, "exec-context-std-error="))) {
1,016,828✔
2915
                        c->std_error = exec_output_from_string(val);
11,737✔
2916
                        if (c->std_error < 0)
11,737✔
2917
                                return c->std_error;
2918
                } else if ((val = startswith(l, "exec-context-stdio-as-fds="))) {
1,005,091✔
2919
                        r = parse_boolean(val);
550✔
2920
                        if (r < 0)
550✔
2921
                                return r;
2922
                        c->stdio_as_fds = r;
550✔
2923
                } else if ((val = startswith(l, "exec-context-std-input-fd-name="))) {
1,004,541✔
2924
                        r = free_and_strdup(&c->stdio_fdname[STDIN_FILENO], val);
×
2925
                        if (r < 0)
×
2926
                                return r;
2927
                } else if ((val = startswith(l, "exec-context-std-output-fd-name="))) {
1,004,541✔
2928
                        r = free_and_strdup(&c->stdio_fdname[STDOUT_FILENO], val);
×
2929
                        if (r < 0)
×
2930
                                return r;
2931
                } else if ((val = startswith(l, "exec-context-std-error-fd-name="))) {
1,004,541✔
2932
                        r = free_and_strdup(&c->stdio_fdname[STDERR_FILENO], val);
×
2933
                        if (r < 0)
×
2934
                                return r;
2935
                } else if ((val = startswith(l, "exec-context-std-input-file="))) {
1,004,541✔
2936
                        r = free_and_strdup(&c->stdio_file[STDIN_FILENO], val);
×
2937
                        if (r < 0)
×
2938
                                return r;
2939
                } else if ((val = startswith(l, "exec-context-std-output-file="))) {
1,004,541✔
2940
                        r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], val);
4✔
2941
                        if (r < 0)
4✔
2942
                                return r;
2943
                } else if ((val = startswith(l, "exec-context-std-output-file-append="))) {
1,004,537✔
2944
                        r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], val);
1✔
2945
                        if (r < 0)
1✔
2946
                                return r;
2947
                } else if ((val = startswith(l, "exec-context-std-output-file-truncate="))) {
1,004,536✔
2948
                        r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], val);
2✔
2949
                        if (r < 0)
2✔
2950
                                return r;
2951
                } else if ((val = startswith(l, "exec-context-std-error-file="))) {
1,004,534✔
2952
                        r = free_and_strdup(&c->stdio_file[STDERR_FILENO], val);
2✔
2953
                        if (r < 0)
2✔
2954
                                return r;
2955
                } else if ((val = startswith(l, "exec-context-std-error-file-append="))) {
1,004,532✔
2956
                        r = free_and_strdup(&c->stdio_file[STDERR_FILENO], val);
1✔
2957
                        if (r < 0)
1✔
2958
                                return r;
2959
                } else if ((val = startswith(l, "exec-context-std-error-file-truncate="))) {
1,004,531✔
2960
                        r = free_and_strdup(&c->stdio_file[STDERR_FILENO], val);
1✔
2961
                        if (r < 0)
1✔
2962
                                return r;
2963
                } else if ((val = startswith(l, "exec-context-stdin-data="))) {
1,004,530✔
2964
                        if (c->stdin_data)
1✔
2965
                                return -EINVAL; /* duplicated */
2966

2967
                        r = unbase64mem(val, &c->stdin_data, &c->stdin_data_size);
1✔
2968
                        if (r < 0)
1✔
2969
                                return r;
2970
                } else if ((val = startswith(l, "exec-context-tty-path="))) {
1,004,529✔
2971
                        r = free_and_strdup(&c->tty_path, val);
163✔
2972
                        if (r < 0)
163✔
2973
                                return r;
2974
                } else if ((val = startswith(l, "exec-context-tty-reset="))) {
1,004,366✔
2975
                        r = parse_boolean(val);
152✔
2976
                        if (r < 0)
152✔
2977
                                return r;
2978
                        c->tty_reset = r;
152✔
2979
                } else if ((val = startswith(l, "exec-context-tty-vhangup="))) {
1,004,214✔
2980
                        r = parse_boolean(val);
147✔
2981
                        if (r < 0)
147✔
2982
                                return r;
2983
                        c->tty_vhangup = r;
147✔
2984
                } else if ((val = startswith(l, "exec-context-tty-vt-disallocate="))) {
1,004,067✔
2985
                        r = parse_boolean(val);
83✔
2986
                        if (r < 0)
83✔
2987
                                return r;
2988
                        c->tty_vt_disallocate = r;
83✔
2989
                } else if ((val = startswith(l, "exec-context-tty-rows="))) {
1,003,984✔
2990
                        r = safe_atou(val, &c->tty_rows);
11,737✔
2991
                        if (r < 0)
11,737✔
2992
                                return r;
2993
                } else if ((val = startswith(l, "exec-context-tty-columns="))) {
992,247✔
2994
                        r = safe_atou(val, &c->tty_cols);
11,737✔
2995
                        if (r < 0)
11,737✔
2996
                                return r;
2997
                } else if ((val = startswith(l, "exec-context-syslog-priority="))) {
980,510✔
2998
                        r = safe_atoi(val, &c->syslog_priority);
11,737✔
2999
                        if (r < 0)
11,737✔
3000
                                return r;
3001
                } else if ((val = startswith(l, "exec-context-syslog-level-prefix="))) {
968,773✔
3002
                        r = parse_boolean(val);
11,737✔
3003
                        if (r < 0)
11,737✔
3004
                                return r;
3005
                        c->syslog_level_prefix = r;
11,737✔
3006
                } else if ((val = startswith(l, "exec-context-syslog-identifier="))) {
957,036✔
3007
                        r = free_and_strdup(&c->syslog_identifier, val);
×
3008
                        if (r < 0)
×
3009
                                return r;
3010
                } else if ((val = startswith(l, "exec-context-log-level-max="))) {
957,036✔
3011
                        /* See comment in serialization. */
3012
                        r = safe_atoi(val, &c->log_level_max);
11,737✔
3013
                        if (r < 0)
11,737✔
3014
                                return r;
3015
                } else if ((val = startswith(l, "exec-context-log-ratelimit-interval-usec="))) {
945,299✔
3016
                        r = deserialize_usec(val, &c->log_ratelimit.interval);
×
3017
                        if (r < 0)
×
3018
                                return r;
3019
                } else if ((val = startswith(l, "exec-context-log-ratelimit-burst="))) {
945,299✔
3020
                        r = safe_atou(val, &c->log_ratelimit.burst);
×
3021
                        if (r < 0)
×
3022
                                return r;
3023
                } else if ((val = startswith(l, "exec-context-log-filter-allowed-patterns="))) {
945,299✔
3024
                        r = set_put_strdup(&c->log_filter_allowed_patterns, val);
9✔
3025
                        if (r < 0)
9✔
3026
                                return r;
3027
                } else if ((val = startswith(l, "exec-context-log-filter-denied-patterns="))) {
945,290✔
3028
                        r = set_put_strdup(&c->log_filter_denied_patterns, val);
5✔
3029
                        if (r < 0)
5✔
3030
                                return r;
3031
                } else if ((val = startswith(l, "exec-context-log-extra-fields="))) {
945,285✔
3032
                        if (!GREEDY_REALLOC(c->log_extra_fields, c->n_log_extra_fields + 1))
619✔
3033
                                return log_oom_debug();
×
3034

3035
                        c->log_extra_fields[c->n_log_extra_fields++].iov_base = strdup(val);
619✔
3036
                        if (!c->log_extra_fields[c->n_log_extra_fields-1].iov_base)
619✔
3037
                                return log_oom_debug();
×
3038
                } else if ((val = startswith(l, "exec-context-log-namespace="))) {
944,666✔
3039
                        r = free_and_strdup(&c->log_namespace, val);
2✔
3040
                        if (r < 0)
2✔
3041
                                return r;
3042
                } else if ((val = startswith(l, "exec-context-secure-bits="))) {
944,664✔
3043
                        r = safe_atoi(val, &c->secure_bits);
×
3044
                        if (r < 0)
×
3045
                                return r;
3046
                } else if ((val = startswith(l, "exec-context-capability-bounding-set="))) {
944,664✔
3047
                        r = safe_atou64(val, &c->capability_bounding_set);
2,386✔
3048
                        if (r < 0)
2,386✔
3049
                                return r;
3050
                } else if ((val = startswith(l, "exec-context-capability-ambient-set="))) {
942,278✔
3051
                        r = safe_atou64(val, &c->capability_ambient_set);
1,313✔
3052
                        if (r < 0)
1,313✔
3053
                                return r;
3054
                } else if ((val = startswith(l, "exec-context-user="))) {
940,965✔
3055
                        r = free_and_strdup(&c->user, val);
2,674✔
3056
                        if (r < 0)
2,674✔
3057
                                return r;
3058
                } else if ((val = startswith(l, "exec-context-group="))) {
938,291✔
3059
                        r = free_and_strdup(&c->group, val);
73✔
3060
                        if (r < 0)
73✔
3061
                                return r;
3062
                } else if ((val = startswith(l, "exec-context-dynamic-user="))) {
938,218✔
3063
                        r = parse_boolean(val);
62✔
3064
                        if (r < 0)
62✔
3065
                                return r;
3066
                        c->dynamic_user = r;
62✔
3067
                } else if ((val = startswith(l, "exec-context-supplementary-groups="))) {
938,156✔
3068
                        r = deserialize_strv(val, &c->supplementary_groups);
9✔
3069
                        if (r < 0)
9✔
3070
                                return r;
3071
                } else if ((val = startswith(l, "exec-context-set-login-environment="))) {
938,147✔
3072
                        r = safe_atoi(val, &c->set_login_environment);
×
3073
                        if (r < 0)
×
3074
                                return r;
3075
                } else if ((val = startswith(l, "exec-context-pam-name="))) {
938,147✔
3076
                        r = free_and_strdup(&c->pam_name, val);
453✔
3077
                        if (r < 0)
453✔
3078
                                return r;
3079
                } else if ((val = startswith(l, "exec-context-read-write-paths="))) {
937,694✔
3080
                        r = deserialize_strv(val, &c->read_write_paths);
812✔
3081
                        if (r < 0)
812✔
3082
                                return r;
3083
                } else if ((val = startswith(l, "exec-context-read-only-paths="))) {
936,882✔
3084
                        r = deserialize_strv(val, &c->read_only_paths);
2✔
3085
                        if (r < 0)
2✔
3086
                                return r;
3087
                } else if ((val = startswith(l, "exec-context-inaccessible-paths="))) {
936,880✔
3088
                        r = deserialize_strv(val, &c->inaccessible_paths);
5✔
3089
                        if (r < 0)
5✔
3090
                                return r;
3091
                } else if ((val = startswith(l, "exec-context-exec-paths="))) {
936,875✔
3092
                        r = deserialize_strv(val, &c->exec_paths);
1✔
3093
                        if (r < 0)
1✔
3094
                                return r;
3095
                } else if ((val = startswith(l, "exec-context-no-exec-paths="))) {
936,874✔
3096
                        r = deserialize_strv(val, &c->no_exec_paths);
1✔
3097
                        if (r < 0)
1✔
3098
                                return r;
3099
                } else if ((val = startswith(l, "exec-context-exec-search-path="))) {
936,873✔
3100
                        r = deserialize_strv(val, &c->exec_search_path);
×
3101
                        if (r < 0)
×
3102
                                return r;
3103
                } else if ((val = startswith(l, "exec-context-mount-propagation-flag="))) {
936,873✔
3104
                        r = safe_atolu(val, &c->mount_propagation_flag);
11,737✔
3105
                        if (r < 0)
11,737✔
3106
                                return r;
3107
                } else if ((val = startswith(l, "exec-context-bind-read-only-path="))) {
925,136✔
3108
                        _cleanup_free_ char *source = NULL, *destination = NULL;
7✔
3109
                        bool rbind = true, ignore_enoent = false;
7✔
3110
                        char *s = NULL, *d = NULL;
7✔
3111

3112
                        r = extract_first_word(&val,
7✔
3113
                                               &source,
3114
                                               ":" WHITESPACE,
3115
                                               EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3116
                        if (r < 0)
7✔
3117
                                return r;
3118
                        if (r == 0)
7✔
3119
                                return -EINVAL;
3120

3121
                        s = source;
7✔
3122
                        if (s[0] == '-') {
7✔
3123
                                ignore_enoent = true;
1✔
3124
                                s++;
1✔
3125
                        }
3126

3127
                        if (val && val[-1] == ':') {
7✔
3128
                                r = extract_first_word(&val,
7✔
3129
                                                       &destination,
3130
                                                       ":" WHITESPACE,
3131
                                                       EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3132
                                if (r < 0)
7✔
3133
                                        return r;
3134
                                if (r == 0)
7✔
3135
                                        continue;
×
3136

3137
                                d = destination;
7✔
3138

3139
                                if (val && val[-1] == ':') {
7✔
3140
                                        _cleanup_free_ char *options = NULL;
7✔
3141

3142
                                        r = extract_first_word(&val, &options, NULL, EXTRACT_UNQUOTE);
7✔
3143
                                        if (r < 0)
7✔
3144
                                                return -r;
×
3145

3146
                                        if (isempty(options) || streq(options, "rbind"))
15✔
3147
                                                rbind = true;
3148
                                        else if (streq(options, "norbind"))
1✔
3149
                                                rbind = false;
3150
                                        else
3151
                                                continue;
×
3152
                                }
3153
                        } else
3154
                                d = s;
3155

3156
                        r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts,
14✔
3157
                                        &(BindMount) {
7✔
3158
                                                .source = s,
3159
                                                .destination = d,
3160
                                                .read_only = true,
3161
                                                .recursive = rbind,
3162
                                                .ignore_enoent = ignore_enoent,
3163
                                        });
3164
                        if (r < 0)
7✔
3165
                                return log_oom_debug();
×
3166
                } else if ((val = startswith(l, "exec-context-bind-path="))) {
925,129✔
3167
                        _cleanup_free_ char *source = NULL, *destination = NULL;
20✔
3168
                        bool rbind = true, ignore_enoent = false;
20✔
3169
                        char *s = NULL, *d = NULL;
20✔
3170

3171
                        r = extract_first_word(&val,
20✔
3172
                                               &source,
3173
                                               ":" WHITESPACE,
3174
                                               EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3175
                        if (r < 0)
20✔
3176
                                return r;
3177
                        if (r == 0)
20✔
3178
                                return -EINVAL;
3179

3180
                        s = source;
20✔
3181
                        if (s[0] == '-') {
20✔
3182
                                ignore_enoent = true;
1✔
3183
                                s++;
1✔
3184
                        }
3185

3186
                        if (val && val[-1] == ':') {
20✔
3187
                                r = extract_first_word(&val,
20✔
3188
                                                       &destination,
3189
                                                       ":" WHITESPACE,
3190
                                                       EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3191
                                if (r < 0)
20✔
3192
                                        return r;
3193
                                if (r == 0)
20✔
3194
                                        continue;
×
3195

3196
                                d = destination;
20✔
3197

3198
                                if (val && val[-1] == ':') {
20✔
3199
                                        _cleanup_free_ char *options = NULL;
20✔
3200

3201
                                        r = extract_first_word(&val, &options, NULL, EXTRACT_UNQUOTE);
20✔
3202
                                        if (r < 0)
20✔
3203
                                                return -r;
×
3204

3205
                                        if (isempty(options) || streq(options, "rbind"))
43✔
3206
                                                rbind = true;
3207
                                        else if (streq(options, "norbind"))
3✔
3208
                                                rbind = false;
3209
                                        else
3210
                                                continue;
×
3211
                                }
3212
                        } else
3213
                                d = s;
3214

3215
                        r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts,
40✔
3216
                                        &(BindMount) {
20✔
3217
                                                .source = s,
3218
                                                .destination = d,
3219
                                                .read_only = false,
3220
                                                .recursive = rbind,
3221
                                                .ignore_enoent = ignore_enoent,
3222
                                        });
3223
                        if (r < 0)
20✔
3224
                                return log_oom_debug();
×
3225
                } else if ((val = startswith(l, "exec-context-temporary-filesystems="))) {
925,109✔
3226
                        _cleanup_free_ char *path = NULL, *options = NULL;
61✔
3227

3228
                        r = extract_many_words(&val, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &path, &options);
61✔
3229
                        if (r < 0)
61✔
3230
                                return r;
3231
                        if (r < 1)
61✔
3232
                                continue;
×
3233

3234
                        r = temporary_filesystem_add(&c->temporary_filesystems, &c->n_temporary_filesystems, path, options);
61✔
3235
                        if (r < 0)
61✔
3236
                                return log_oom_debug();
×
3237
                } else if ((val = startswith(l, "exec-context-utmp-id="))) {
925,048✔
3238
                        r = free_and_strdup(&c->utmp_id, val);
154✔
3239
                        if (r < 0)
154✔
3240
                                return r;
3241
                } else if ((val = startswith(l, "exec-context-utmp-mode="))) {
924,894✔
3242
                        c->utmp_mode = exec_utmp_mode_from_string(val);
11,737✔
3243
                        if (c->utmp_mode < 0)
11,737✔
3244
                                return c->utmp_mode;
3245
                } else if ((val = startswith(l, "exec-context-no-new-privileges="))) {
913,157✔
3246
                        r = parse_boolean(val);
2,198✔
3247
                        if (r < 0)
2,198✔
3248
                                return r;
3249
                        c->no_new_privileges = r;
2,198✔
3250
                } else if ((val = startswith(l, "exec-context-selinux-context="))) {
910,959✔
3251
                        if (val[0] == '-') {
×
3252
                                c->selinux_context_ignore = true;
×
3253
                                val++;
×
3254
                        } else
3255
                                c->selinux_context_ignore = false;
×
3256

3257
                        r = free_and_strdup(&c->selinux_context, val);
×
3258
                        if (r < 0)
×
3259
                                return r;
3260
                } else if ((val = startswith(l, "exec-context-apparmor-profile="))) {
910,959✔
3261
                        if (val[0] == '-') {
×
3262
                                c->apparmor_profile_ignore = true;
×
3263
                                val++;
×
3264
                        } else
3265
                                c->apparmor_profile_ignore = false;
×
3266

3267
                        r = free_and_strdup(&c->apparmor_profile, val);
×
3268
                        if (r < 0)
×
3269
                                return r;
3270
                } else if ((val = startswith(l, "exec-context-smack-process-label="))) {
910,959✔
3271
                        if (val[0] == '-') {
×
3272
                                c->smack_process_label_ignore = true;
×
3273
                                val++;
×
3274
                        } else
3275
                                c->smack_process_label_ignore = false;
×
3276

3277
                        r = free_and_strdup(&c->smack_process_label, val);
×
3278
                        if (r < 0)
×
3279
                                return r;
3280
                } else if ((val = startswith(l, "exec-context-personality="))) {
910,959✔
3281
                        c->personality = personality_from_string(val);
×
3282
                        if (c->personality == PERSONALITY_INVALID)
×
3283
                                return -EINVAL;
3284
                } else if ((val = startswith(l, "exec-context-lock-personality="))) {
910,959✔
3285
                        r = parse_boolean(val);
2,256✔
3286
                        if (r < 0)
2,256✔
3287
                                return r;
3288
                        c->lock_personality = r;
2,256✔
3289
#if HAVE_SECCOMP
3290
                } else if ((val = startswith(l, "exec-context-syscall-filter="))) {
908,703✔
3291
                        _cleanup_free_ char *s_id = NULL, *s_errno_num = NULL;
871,263✔
3292
                        int id, errno_num;
871,263✔
3293

3294
                        r = extract_many_words(&val, NULL, 0, &s_id, &s_errno_num);
871,263✔
3295
                        if (r < 0)
871,263✔
3296
                                return r;
3297
                        if (r != 2)
871,263✔
3298
                                continue;
×
3299

3300
                        r = safe_atoi(s_id, &id);
871,263✔
3301
                        if (r < 0)
871,263✔
3302
                                return r;
3303

3304
                        r = safe_atoi(s_errno_num, &errno_num);
871,263✔
3305
                        if (r < 0)
871,263✔
3306
                                return r;
3307

3308
                        r = hashmap_ensure_put(&c->syscall_filter, NULL, INT_TO_PTR(id + 1), INT_TO_PTR(errno_num));
871,263✔
3309
                        if (r < 0)
871,263✔
3310
                                return r;
3311
                } else if ((val = startswith(l, "exec-context-syscall-archs="))) {
37,440✔
3312
                        unsigned id;
2,256✔
3313

3314
                        r = safe_atou(val, &id);
2,256✔
3315
                        if (r < 0)
2,256✔
3316
                                return r;
×
3317

3318
                        r = set_ensure_put(&c->syscall_archs, NULL, UINT_TO_PTR(id + 1));
2,256✔
3319
                        if (r < 0)
2,256✔
3320
                                return r;
3321
                } else if ((val = startswith(l, "exec-context-syscall-errno="))) {
35,184✔
3322
                        r = safe_atoi(val, &c->syscall_errno);
11,737✔
3323
                        if (r < 0)
11,737✔
3324
                                return r;
3325
                } else if ((val = startswith(l, "exec-context-syscall-allow-list="))) {
23,447✔
3326
                        r = parse_boolean(val);
2,238✔
3327
                        if (r < 0)
2,238✔
3328
                                return r;
3329
                        c->syscall_allow_list = r;
2,238✔
3330
                } else if ((val = startswith(l, "exec-context-syscall-log="))) {
21,209✔
3331
                        _cleanup_free_ char *s_id = NULL, *s_errno_num = NULL;
×
3332
                        int id, errno_num;
×
3333

3334
                        r = extract_many_words(&val, " ", 0, &s_id, &s_errno_num);
×
3335
                        if (r < 0)
×
3336
                                return r;
3337
                        if (r != 2)
×
3338
                                continue;
×
3339

3340
                        r = safe_atoi(s_id, &id);
×
3341
                        if (r < 0)
×
3342
                                return r;
3343

3344
                        r = safe_atoi(s_errno_num, &errno_num);
×
3345
                        if (r < 0)
×
3346
                                return r;
3347

3348
                        r = hashmap_ensure_put(&c->syscall_log, NULL, INT_TO_PTR(id + 1), INT_TO_PTR(errno_num));
×
3349
                        if (r < 0)
×
3350
                                return r;
3351
                } else if ((val = startswith(l, "exec-context-syscall-log-allow-list="))) {
21,209✔
3352
                        r = parse_boolean(val);
×
3353
                        if (r < 0)
×
3354
                                return r;
3355
                        c->syscall_log_allow_list = r;
×
3356
#endif
3357
                } else if ((val = startswith(l, "exec-context-restrict-namespaces="))) {
21,209✔
3358
                        r = safe_atolu(val, &c->restrict_namespaces);
1,998✔
3359
                        if (r < 0)
1,998✔
3360
                                return r;
3361
                } else if ((val = startswith(l, "exec-context-delegate-namespaces="))) {
19,211✔
3362
                        r = safe_atolu(val, &c->delegate_namespaces);
12✔
3363
                        if (r < 0)
12✔
3364
                                return r;
3365
                } else if ((val = startswith(l, "exec-context-restrict-filesystems="))) {
19,199✔
3366
                        r = set_put_strdup(&c->restrict_filesystems, val);
×
3367
                        if (r < 0)
×
3368
                                return r;
3369
                } else if ((val = startswith(l, "exec-context-restrict-filesystems-allow-list="))) {
19,199✔
3370
                        r = parse_boolean(val);
×
3371
                        if (r < 0)
×
3372
                                return r;
3373
                        c->restrict_filesystems_allow_list = r;
×
3374
                } else if ((val = startswith(l, "exec-context-address-families="))) {
19,199✔
3375
                        int af;
9,408✔
3376

3377
                        r = safe_atoi(val, &af);
9,408✔
3378
                        if (r < 0)
9,408✔
3379
                                return r;
×
3380

3381
                        r = set_ensure_put(&c->address_families, NULL, INT_TO_PTR(af));
9,408✔
3382
                        if (r < 0)
9,408✔
3383
                                return r;
3384
                } else if ((val = startswith(l, "exec-context-address-families-allow-list="))) {
9,791✔
3385
                        r = parse_boolean(val);
2,253✔
3386
                        if (r < 0)
2,253✔
3387
                                return r;
3388
                        c->address_families_allow_list = r;
2,253✔
3389
                } else if ((val = startswith(l, "exec-context-network-namespace-path="))) {
7,538✔
3390
                        r = free_and_strdup(&c->network_namespace_path, val);
×
3391
                        if (r < 0)
×
3392
                                return r;
3393
                } else if ((val = startswith(l, "exec-context-ipc-namespace-path="))) {
7,538✔
3394
                        r = free_and_strdup(&c->ipc_namespace_path, val);
×
3395
                        if (r < 0)
×
3396
                                return r;
3397
                } else if ((val = startswith(l, "exec-context-mount-image="))) {
7,538✔
3398
                        _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
×
3399
                        _cleanup_free_ char *source = NULL, *destination = NULL;
56✔
3400
                        bool permissive = false;
56✔
3401
                        char *s;
56✔
3402

3403
                        r = extract_many_words(&val,
56✔
3404
                                               NULL,
3405
                                               EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS,
3406
                                               &source,
3407
                                               &destination);
3408
                        if (r < 0)
56✔
3409
                                return r;
3410
                        if (r == 0)
56✔
3411
                                return -EINVAL;
3412

3413
                        s = source;
56✔
3414
                        if (s[0] == '-') {
56✔
3415
                                permissive = true;
×
3416
                                s++;
×
3417
                        }
3418

3419
                        if (isempty(destination))
56✔
3420
                                continue;
×
3421

3422
                        for (;;) {
61✔
3423
                                _cleanup_free_ char *tuple = NULL, *partition = NULL, *opts = NULL;
5✔
3424
                                PartitionDesignator partition_designator;
61✔
3425
                                MountOptions *o = NULL;
61✔
3426
                                const char *p;
61✔
3427

3428
                                r = extract_first_word(&val, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
61✔
3429
                                if (r < 0)
61✔
3430
                                        return r;
3431
                                if (r == 0)
61✔
3432
                                        break;
3433

3434
                                p = tuple;
5✔
3435
                                r = extract_many_words(&p,
5✔
3436
                                                       ":",
3437
                                                       EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS,
3438
                                                       &partition,
3439
                                                       &opts);
3440
                                if (r < 0)
5✔
3441
                                        return r;
3442
                                if (r == 0)
5✔
3443
                                        continue;
×
3444
                                if (r == 1) {
5✔
3445
                                        o = new(MountOptions, 1);
×
3446
                                        if (!o)
×
3447
                                                return log_oom_debug();
×
3448
                                        *o = (MountOptions) {
×
3449
                                                .partition_designator = PARTITION_ROOT,
3450
                                                .options = TAKE_PTR(partition),
×
3451
                                        };
3452
                                        LIST_APPEND(mount_options, options, o);
×
3453

3454
                                        continue;
×
3455
                                }
3456

3457
                                partition_designator = partition_designator_from_string(partition);
5✔
3458
                                if (partition_designator < 0)
5✔
3459
                                        continue;
×
3460

3461
                                o = new(MountOptions, 1);
5✔
3462
                                if (!o)
5✔
3463
                                        return log_oom_debug();
×
3464
                                *o = (MountOptions) {
5✔
3465
                                        .partition_designator = partition_designator,
3466
                                        .options = TAKE_PTR(opts),
5✔
3467
                                };
3468
                                LIST_APPEND(mount_options, options, o);
5✔
3469
                        }
3470

3471
                        r = mount_image_add(&c->mount_images, &c->n_mount_images,
112✔
3472
                                        &(MountImage) {
56✔
3473
                                                .source = s,
3474
                                                .destination = destination,
3475
                                                .mount_options = options,
3476
                                                .ignore_enoent = permissive,
3477
                                                .type = MOUNT_IMAGE_DISCRETE,
3478
                                        });
3479
                        if (r < 0)
56✔
3480
                                return log_oom_debug();
×
3481
                } else if ((val = startswith(l, "exec-context-extension-image="))) {
7,482✔
3482
                        _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
×
3483
                        _cleanup_free_ char *source = NULL;
9✔
3484
                        bool permissive = false;
9✔
3485
                        char *s;
9✔
3486

3487
                        r = extract_first_word(&val,
9✔
3488
                                               &source,
3489
                                               NULL,
3490
                                               EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS);
3491
                        if (r < 0)
9✔
3492
                                return r;
3493
                        if (r == 0)
9✔
3494
                                return -EINVAL;
3495

3496
                        s = source;
9✔
3497
                        if (s[0] == '-') {
9✔
3498
                                permissive = true;
3✔
3499
                                s++;
3✔
3500
                        }
3501

3502
                        for (;;) {
9✔
3503
                                _cleanup_free_ char *tuple = NULL, *partition = NULL, *opts = NULL;
×
3504
                                PartitionDesignator partition_designator;
9✔
3505
                                MountOptions *o = NULL;
9✔
3506
                                const char *p;
9✔
3507

3508
                                r = extract_first_word(&val, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
9✔
3509
                                if (r < 0)
9✔
3510
                                        return r;
3511
                                if (r == 0)
9✔
3512
                                        break;
3513

3514
                                p = tuple;
×
3515
                                r = extract_many_words(&p,
×
3516
                                                       ":",
3517
                                                       EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS,
3518
                                                       &partition,
3519
                                                       &opts);
3520
                                if (r < 0)
×
3521
                                        return r;
3522
                                if (r == 0)
×
3523
                                        continue;
×
3524
                                if (r == 1) {
×
3525
                                        o = new(MountOptions, 1);
×
3526
                                        if (!o)
×
3527
                                                return log_oom_debug();
×
3528
                                        *o = (MountOptions) {
×
3529
                                                .partition_designator = PARTITION_ROOT,
3530
                                                .options = TAKE_PTR(partition),
×
3531
                                        };
3532
                                        LIST_APPEND(mount_options, options, o);
×
3533

3534
                                        continue;
×
3535
                                }
3536

3537
                                partition_designator = partition_designator_from_string(partition);
×
3538
                                if (partition_designator < 0)
×
3539
                                        continue;
×
3540

3541
                                o = new(MountOptions, 1);
×
3542
                                if (!o)
×
3543
                                        return log_oom_debug();
×
3544
                                *o = (MountOptions) {
×
3545
                                        .partition_designator = partition_designator,
3546
                                        .options = TAKE_PTR(opts),
×
3547
                                };
3548
                                LIST_APPEND(mount_options, options, o);
×
3549
                        }
3550

3551
                        r = mount_image_add(&c->extension_images, &c->n_extension_images,
18✔
3552
                                        &(MountImage) {
9✔
3553
                                                .source = s,
3554
                                                .mount_options = options,
3555
                                                .ignore_enoent = permissive,
3556
                                                .type = MOUNT_IMAGE_EXTENSION,
3557
                                        });
3558
                        if (r < 0)
9✔
3559
                                return log_oom_debug();
×
3560
                } else if ((val = startswith(l, "exec-context-extension-directories="))) {
7,473✔
3561
                        r = deserialize_strv(val, &c->extension_directories);
8✔
3562
                        if (r < 0)
8✔
3563
                                return r;
3564
                } else if ((val = startswith(l, "exec-context-set-credentials="))) {
7,465✔
3565
                        _cleanup_free_ char *id = NULL, *data = NULL, *encrypted = NULL;
×
3566

3567
                        r = extract_many_words(&val, " ", EXTRACT_DONT_COALESCE_SEPARATORS, &id, &data, &encrypted);
182✔
3568
                        if (r < 0)
182✔
3569
                                return r;
3570
                        if (r != 3)
182✔
3571
                                return -EINVAL;
3572

3573
                        r = parse_boolean(encrypted);
182✔
3574
                        if (r < 0)
182✔
3575
                                return r;
3576
                        bool e = r;
182✔
3577

3578
                        _cleanup_free_ void *d = NULL;
182✔
3579
                        size_t size;
182✔
3580

3581
                        r = unbase64mem_full(data, SIZE_MAX, /* secure = */ true, &d, &size);
182✔
3582
                        if (r < 0)
182✔
3583
                                return r;
3584

3585
                        r = exec_context_put_set_credential(c, id, TAKE_PTR(d), size, e);
182✔
3586
                        if (r < 0)
182✔
3587
                                return r;
3588
                } else if ((val = startswith(l, "exec-context-load-credentials="))) {
7,283✔
3589
                        _cleanup_free_ char *id = NULL, *path = NULL, *encrypted = NULL;
61✔
3590

3591
                        r = extract_many_words(&val, " ", EXTRACT_DONT_COALESCE_SEPARATORS, &id, &path, &encrypted);
61✔
3592
                        if (r < 0)
61✔
3593
                                return r;
3594
                        if (r != 3)
61✔
3595
                                return -EINVAL;
3596

3597
                        r = parse_boolean(encrypted);
61✔
3598
                        if (r < 0)
61✔
3599
                                return r;
3600

3601
                        r = exec_context_put_load_credential(c, id, path, r > 0);
61✔
3602
                        if (r < 0)
61✔
3603
                                return r;
3604
                } else if ((val = startswith(l, "exec-context-import-credentials="))) {
7,222✔
3605
                        _cleanup_free_ char *glob = NULL, *rename = NULL;
7,218✔
3606

3607
                        r = extract_many_words(&val, " ", EXTRACT_DONT_COALESCE_SEPARATORS, &glob, &rename);
7,218✔
3608
                        if (r < 0)
7,218✔
3609
                                return r;
3610
                        if (r == 0)
7,218✔
3611
                                return -EINVAL;
3612

3613
                        r = exec_context_put_import_credential(c, glob, rename);
7,218✔
3614
                        if (r < 0)
7,218✔
3615
                                return r;
3616
                } else if ((val = startswith(l, "exec-context-root-image-policy="))) {
4✔
3617
                        if (c->root_image_policy)
4✔
3618
                                return -EINVAL; /* duplicated */
3619

3620
                        r = image_policy_from_string(val, &c->root_image_policy);
4✔
3621
                        if (r < 0)
4✔
3622
                                return r;
3623
                } else if ((val = startswith(l, "exec-context-mount-image-policy="))) {
×
3624
                        if (c->mount_image_policy)
×
3625
                                return -EINVAL; /* duplicated */
3626

3627
                        r = image_policy_from_string(val, &c->mount_image_policy);
×
3628
                        if (r < 0)
×
3629
                                return r;
3630
                } else if ((val = startswith(l, "exec-context-extension-image-policy="))) {
×
3631
                        if (c->extension_image_policy)
×
3632
                                return -EINVAL; /* duplicated */
3633

3634
                        r = image_policy_from_string(val, &c->extension_image_policy);
×
3635
                        if (r < 0)
×
3636
                                return r;
3637
                } else
3638
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
3639
        }
3640

3641
        return 0;
11,737✔
3642
}
3643

3644
static int exec_command_serialize(const ExecCommand *c, FILE *f) {
2,234✔
3645
        int r;
2,234✔
3646

3647
        assert(c);
2,234✔
3648
        assert(f);
2,234✔
3649

3650
        r = serialize_item(f, "exec-command-path", c->path);
2,234✔
3651
        if (r < 0)
2,234✔
3652
                return r;
3653

3654
        r = serialize_strv(f, "exec-command-argv", c->argv);
2,234✔
3655
        if (r < 0)
2,234✔
3656
                return r;
3657

3658
        r = serialize_item_format(f, "exec-command-flags", "%d", (int) c->flags);
2,234✔
3659
        if (r < 0)
2,234✔
3660
                return r;
3661

3662
        fputc('\n', f); /* End marker */
2,234✔
3663

3664
        return 0;
2,234✔
3665
}
3666

3667
static int exec_command_deserialize(ExecCommand *c, FILE *f) {
11,737✔
3668
        int r;
11,737✔
3669

3670
        assert(c);
11,737✔
3671
        assert(f);
11,737✔
3672

3673
        for (;;) {
125,381✔
3674
                _cleanup_free_ char *l = NULL;
56,822✔
3675
                const char *val;
68,559✔
3676

3677
                r = deserialize_read_line(f, &l);
68,559✔
3678
                if (r < 0)
68,559✔
3679
                        return r;
3680
                if (r == 0) /* eof or end marker */
68,559✔
3681
                        break;
3682

3683
                if ((val = startswith(l, "exec-command-path="))) {
56,822✔
3684
                        r = free_and_strdup(&c->path, val);
11,737✔
3685
                        if (r < 0)
11,737✔
3686
                                return r;
3687
                } else if ((val = startswith(l, "exec-command-argv="))) {
45,085✔
3688
                        r = deserialize_strv(val, &c->argv);
33,348✔
3689
                        if (r < 0)
33,348✔
3690
                                return r;
3691
                } else if ((val = startswith(l, "exec-command-flags="))) {
11,737✔
3692
                        r = safe_atoi(val, &c->flags);
11,737✔
3693
                        if (r < 0)
11,737✔
3694
                                return r;
3695
                } else
3696
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
3697

3698
        }
3699

3700
        return 0;
11,737✔
3701
}
3702

3703
int exec_serialize_invocation(
2,234✔
3704
                FILE *f,
3705
                FDSet *fds,
3706
                const ExecContext *ctx,
3707
                const ExecCommand *cmd,
3708
                const ExecParameters *p,
3709
                const ExecRuntime *rt,
3710
                const CGroupContext *cg) {
3711

3712
        int r;
2,234✔
3713

3714
        assert(f);
2,234✔
3715
        assert(fds);
2,234✔
3716

3717
        r = exec_context_serialize(ctx, f);
2,234✔
3718
        if (r < 0)
2,234✔
3719
                return log_debug_errno(r, "Failed to serialize context: %m");
×
3720

3721
        r = exec_command_serialize(cmd, f);
2,234✔
3722
        if (r < 0)
2,234✔
3723
                return log_debug_errno(r, "Failed to serialize command: %m");
×
3724

3725
        r = exec_parameters_serialize(p, ctx, f, fds);
2,234✔
3726
        if (r < 0)
2,234✔
3727
                return log_debug_errno(r, "Failed to serialize parameters: %m");
×
3728

3729
        r = exec_runtime_serialize(rt, f, fds);
2,234✔
3730
        if (r < 0)
2,234✔
3731
                return log_debug_errno(r, "Failed to serialize runtime: %m");
×
3732

3733
        r = exec_cgroup_context_serialize(cg, f);
2,234✔
3734
        if (r < 0)
2,234✔
3735
                return log_debug_errno(r, "Failed to serialize cgroup context: %m");
×
3736

3737
        return 0;
3738
}
3739

3740
int exec_deserialize_invocation(
11,737✔
3741
                FILE *f,
3742
                FDSet *fds,
3743
                ExecContext *ctx,
3744
                ExecCommand *cmd,
3745
                ExecParameters *p,
3746
                ExecRuntime *rt,
3747
                CGroupContext *cg) {
3748

3749
        int r;
11,737✔
3750

3751
        assert(f);
11,737✔
3752
        assert(fds);
11,737✔
3753

3754
        r = exec_context_deserialize(ctx, f);
11,737✔
3755
        if (r < 0)
11,737✔
3756
                return log_debug_errno(r, "Failed to deserialize context: %m");
×
3757

3758
        r = exec_command_deserialize(cmd, f);
11,737✔
3759
        if (r < 0)
11,737✔
3760
                return log_debug_errno(r, "Failed to deserialize command: %m");
×
3761

3762
        r = exec_parameters_deserialize(p, f, fds);
11,737✔
3763
        if (r < 0)
11,737✔
3764
                return log_debug_errno(r, "Failed to deserialize parameters: %m");
×
3765

3766
        r = exec_runtime_deserialize(rt, f, fds);
11,737✔
3767
        if (r < 0)
11,737✔
3768
                return log_debug_errno(r, "Failed to deserialize runtime: %m");
×
3769

3770
        r = exec_cgroup_context_deserialize(cg, f);
11,737✔
3771
        if (r < 0)
11,737✔
3772
                return log_debug_errno(r, "Failed to deserialize cgroup context: %m");
×
3773

3774
        return 0;
3775
}
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