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

systemd / systemd / 15668827893

16 Jun 2025 12:08AM UTC coverage: 72.048% (-0.08%) from 72.126%
15668827893

push

github

web-flow
socket-activate: add a --now option to instantly start service (#37620)

18 of 29 new or added lines in 1 file covered. (62.07%)

406 existing lines in 44 files now uncovered.

300222 of 416697 relevant lines covered (72.05%)

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

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

40
        assert(f);
2,230✔
41

42
        if (!c)
2,230✔
43
                return 0;
44

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

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

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

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

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

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

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

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

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

89
        cpuset_cpus = cpu_set_to_range_string(&c->cpuset_cpus);
2,230✔
90
        if (!cpuset_cpus)
2,230✔
91
                return log_oom_debug();
×
92

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

97
        startup_cpuset_cpus = cpu_set_to_range_string(&c->startup_cpuset_cpus);
2,230✔
98
        if (!startup_cpuset_cpus)
2,230✔
99
                return log_oom_debug();
×
100

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

105
        cpuset_mems = cpu_set_to_range_string(&c->cpuset_mems);
2,230✔
106
        if (!cpuset_mems)
2,230✔
107
                return log_oom_debug();
×
108

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

113
        startup_cpuset_mems = cpu_set_to_range_string(&c->startup_cpuset_mems);
2,230✔
114
        if (!startup_cpuset_mems)
2,230✔
115
                return log_oom_debug();
×
116

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

271
        r = cg_mask_to_string(c->disable_controllers, &disable_controllers_str);
2,230✔
272
        if (r < 0)
2,230✔
273
                return r;
274

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

279
        r = cg_mask_to_string(c->delegate_controllers, &delegate_controllers_str);
2,230✔
280
        if (r < 0)
2,230✔
281
                return r;
282

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

429
        fputc('\n', f); /* End marker */
2,230✔
430

431
        return 0;
432
}
433

434
static int exec_cgroup_context_deserialize(CGroupContext *c, FILE *f) {
11,626✔
435
        int r;
11,626✔
436

437
        assert(f);
11,626✔
438

439
        if (!c)
11,626✔
440
                return 0;
441

442
        for (;;) {
419,960✔
443
                _cleanup_free_ char *l = NULL;
204,167✔
444
                const char *val;
215,793✔
445

446
                r = deserialize_read_line(f, &l);
215,793✔
447
                if (r < 0)
215,793✔
448
                        return r;
449
                if (r == 0) /* eof or end marker */
215,793✔
450
                        break;
451

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

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

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

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

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

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

731
                        p = isempty(rwm) ? 0 : cgroup_device_permissions_from_string(rwm);
9,018✔
732
                        if (p < 0)
4,509✔
733
                                return p;
734

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

940
        return 0;
11,626✔
941
}
942

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

946
        assert(f);
2,230✔
947
        assert(fds);
2,230✔
948

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

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

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

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

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

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

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

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

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

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

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

1008
        return 0;
70✔
1009
}
1010

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

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

1020
        for (;;) {
12,817✔
1021
                _cleanup_free_ char *l = NULL;
1,191✔
1022
                const char *val;
12,817✔
1023

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

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

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

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

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

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

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

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

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

1082
        return 0;
11,626✔
1083
}
1084

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

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

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

1098
        assert(f);
2,230✔
1099
        assert(fds);
2,230✔
1100

1101
        if (!p)
2,230✔
1102
                return 0;
1103

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

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

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

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

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

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

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

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

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

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

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

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

1164
        for (ExecDirectoryType dt = 0; dt < _EXEC_DIRECTORY_TYPE_MAX; dt++) {
13,380✔
1165
                _cleanup_free_ char *key = NULL;
11,150✔
1166

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1278
        return 0;
2,230✔
1279
}
1280

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

1284
        assert(p);
11,626✔
1285
        assert(f);
11,626✔
1286
        assert(fds);
11,626✔
1287

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

1293
        for (;;) {
260,407✔
1294
                _cleanup_free_ char *l = NULL;
248,781✔
1295
                const char *val;
260,407✔
1296

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

1303
                if ((val = startswith(l, "exec-parameters-runtime-scope="))) {
248,781✔
1304
                        p->runtime_scope = runtime_scope_from_string(val);
11,626✔
1305
                        if (p->runtime_scope < 0)
11,626✔
1306
                                return p->runtime_scope;
1307
                } else if ((val = startswith(l, "exec-parameters-environment="))) {
237,155✔
1308
                        r = deserialize_strv(val, &p->environment);
48,912✔
1309
                        if (r < 0)
48,912✔
1310
                                return r;
1311
                } else if ((val = startswith(l, "exec-parameters-n-socket-fds="))) {
188,243✔
1312
                        if (p->fds)
2,264✔
1313
                                return -EINVAL; /* Already received */
1314

1315
                        r = safe_atozu(val, &p->n_socket_fds);
2,264✔
1316
                        if (r < 0)
2,264✔
1317
                                return r;
1318

1319
                        if (p->n_socket_fds > (size_t) nr_open)
2,264✔
1320
                                return -EINVAL; /* too many, someone is playing games with us */
1321
                } else if ((val = startswith(l, "exec-parameters-n-storage-fds="))) {
185,979✔
1322
                        if (p->fds)
141✔
1323
                                return -EINVAL; /* Already received */
1324

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

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

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

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

1350
                        if (p->fds)
2,275✔
1351
                                return -EINVAL; /* duplicated */
1352

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

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

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

1365
                } else if ((val = startswith(l, "exec-parameters-fd-names="))) {
183,561✔
1366
                        r = deserialize_strv(val, &p->fd_names);
3,971✔
1367
                        if (r < 0)
3,971✔
1368
                                return r;
1369
                } else if ((val = startswith(l, "exec-parameters-flags="))) {
179,590✔
1370
                        unsigned flags;
11,626✔
1371

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

1381
                        p->selinux_context_net = r;
×
1382
                } else if ((val = startswith(l, "exec-parameters-cgroup-supported="))) {
167,964✔
1383
                        unsigned cgroup_supported;
11,615✔
1384

1385
                        r = safe_atou(val, &cgroup_supported);
11,615✔
1386
                        if (r < 0)
11,615✔
1387
                                return r;
×
1388
                        p->cgroup_supported = cgroup_supported;
11,615✔
1389
                } else if ((val = startswith(l, "exec-parameters-cgroup-path="))) {
156,349✔
1390
                        r = free_and_strdup(&p->cgroup_path, val);
11,626✔
1391
                        if (r < 0)
11,626✔
1392
                                return r;
1393
                } else if ((val = startswith(l, "exec-parameters-cgroup-id="))) {
144,723✔
1394
                        r = safe_atou64(val, &p->cgroup_id);
11,626✔
1395
                        if (r < 0)
11,626✔
1396
                                return r;
1397
                } else if ((val = startswith(l, "exec-parameters-prefix-directories-"))) {
133,097✔
1398
                        _cleanup_free_ char *type = NULL, *prefix = NULL;
58,130✔
1399
                        ExecDirectoryType dt;
58,130✔
1400

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

1407
                        dt = exec_directory_type_from_string(type);
58,130✔
1408
                        if (dt < 0)
58,130✔
1409
                                return -EINVAL;
1410

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

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

1438
                        p->shall_confirm_spawn = r;
×
1439
                } else if ((val = startswith(l, "exec-parameters-watchdog-usec="))) {
64,136✔
1440
                        r = deserialize_usec(val, &p->watchdog_usec);
2,227✔
1441
                        if (r < 0)
2,227✔
1442
                                return r;
1443
                } else if ((val = startswith(l, "exec-parameters-idle-pipe="))) {
61,909✔
1444
                        if (p->idle_pipe)
152✔
1445
                                return -EINVAL; /* duplicated */
1446

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

1451
                        p->idle_pipe[0] = p->idle_pipe[1] = p->idle_pipe[2] = p->idle_pipe[3] = -EBADF;
152✔
1452

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

1457
                } else if ((val = startswith(l, "exec-parameters-stdin-fd="))) {
61,757✔
1458
                        int fd;
550✔
1459

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

1464
                        close_and_replace(p->stdin_fd, fd);
550✔
1465

1466
                } else if ((val = startswith(l, "exec-parameters-stdout-fd="))) {
61,207✔
1467
                        int fd;
550✔
1468

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

1473
                        close_and_replace(p->stdout_fd, fd);
550✔
1474

1475
                } else if ((val = startswith(l, "exec-parameters-stderr-fd="))) {
60,657✔
1476
                        int fd;
550✔
1477

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

1482
                        close_and_replace(p->stderr_fd, fd);
550✔
1483
                } else if ((val = startswith(l, "exec-parameters-exec-fd="))) {
60,107✔
1484
                        int fd;
396✔
1485

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

1490
                        close_and_replace(p->exec_fd, fd);
396✔
1491
                } else if ((val = startswith(l, "exec-parameters-handoff-timestamp-fd="))) {
59,711✔
1492
                        int fd;
11,626✔
1493

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

1498
                        close_and_replace(p->handoff_timestamp_fd, fd);
11,626✔
1499
                } else if ((val = startswith(l, "exec-parameters-pidref-transport-fd="))) {
48,085✔
1500
                        int fd;
10,580✔
1501

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

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

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

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

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

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

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

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

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

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

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

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

1571
        return 0;
1572
}
1573

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

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

1582
        type = fileno == STDOUT_FILENO ? "output" : "error";
4,460✔
1583

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

1589
                break;
×
1590

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

1595
                break;
2✔
1596

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

1601
                break;
×
1602

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

1607
                break;
×
1608

1609
        default:
1610
                return 0;
1611
        }
1612

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

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

1619
        assert(f);
2,230✔
1620

1621
        if (!c)
2,230✔
1622
                return 0;
2,230✔
1623

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1737
        /* This must be set in unit_patch_contexts() before executing a command. */
1738
        assert(c->private_var_tmp >= 0 && c->private_var_tmp < _PRIVATE_TMP_MAX);
2,230✔
1739
        r = serialize_item(f, "exec-context-private-var-tmp", private_tmp_to_string(c->private_var_tmp));
2,230✔
1740
        if (r < 0)
2,230✔
1741
                return r;
1742

1743
        r = serialize_bool_elide(f, "exec-context-private-devices", c->private_devices);
2,230✔
1744
        if (r < 0)
2,230✔
1745
                return r;
1746

1747
        r = serialize_bool_elide(f, "exec-context-protect-kernel-tunables", c->protect_kernel_tunables);
2,230✔
1748
        if (r < 0)
2,230✔
1749
                return r;
1750

1751
        r = serialize_bool_elide(f, "exec-context-protect-kernel-modules", c->protect_kernel_modules);
2,230✔
1752
        if (r < 0)
2,230✔
1753
                return r;
1754

1755
        r = serialize_bool_elide(f, "exec-context-protect-kernel-logs", c->protect_kernel_logs);
2,230✔
1756
        if (r < 0)
2,230✔
1757
                return r;
1758

1759
        r = serialize_bool_elide(f, "exec-context-protect-clock", c->protect_clock);
2,230✔
1760
        if (r < 0)
2,230✔
1761
                return r;
1762

1763
        r = serialize_item(f, "exec-context-protect-control-groups", protect_control_groups_to_string(c->protect_control_groups));
2,230✔
1764
        if (r < 0)
2,230✔
1765
                return r;
1766

1767
        r = serialize_bool_elide(f, "exec-context-private-network", c->private_network);
2,230✔
1768
        if (r < 0)
2,230✔
1769
                return r;
1770

1771
        r = serialize_item(f, "exec-context-private-users", private_users_to_string(c->private_users));
2,230✔
1772
        if (r < 0)
2,230✔
1773
                return r;
1774

1775
        r = serialize_bool_elide(f, "exec-context-private-ipc", c->private_ipc);
2,230✔
1776
        if (r < 0)
2,230✔
1777
                return r;
1778

1779
        r = serialize_item(f, "exec-context-private-pids", private_pids_to_string(c->private_pids));
2,230✔
1780
        if (r < 0)
2,230✔
1781
                return r;
1782

1783
        r = serialize_bool_elide(f, "exec-context-remove-ipc", c->remove_ipc);
2,230✔
1784
        if (r < 0)
2,230✔
1785
                return r;
1786

1787
        r = serialize_item(f, "exec-context-protect-home", protect_home_to_string(c->protect_home));
2,230✔
1788
        if (r < 0)
2,230✔
1789
                return r;
1790

1791
        r = serialize_item(f, "exec-context-protect-system", protect_system_to_string(c->protect_system));
2,230✔
1792
        if (r < 0)
2,230✔
1793
                return r;
1794

1795
        r = serialize_bool_elide(f, "exec-context-same-pgrp", c->same_pgrp);
2,230✔
1796
        if (r < 0)
2,230✔
1797
                return r;
1798

1799
        r = serialize_bool(f, "exec-context-ignore-sigpipe", c->ignore_sigpipe);
2,230✔
1800
        if (r < 0)
2,230✔
1801
                return r;
1802

1803
        r = serialize_bool_elide(f, "exec-context-memory-deny-write-execute", c->memory_deny_write_execute);
2,230✔
1804
        if (r < 0)
2,230✔
1805
                return r;
1806

1807
        r = serialize_bool_elide(f, "exec-context-restrict-realtime", c->restrict_realtime);
2,230✔
1808
        if (r < 0)
2,230✔
1809
                return r;
1810

1811
        r = serialize_bool_elide(f, "exec-context-restrict-suid-sgid", c->restrict_suid_sgid);
2,230✔
1812
        if (r < 0)
2,230✔
1813
                return r;
1814

1815
        r = serialize_item(f, "exec-context-keyring-mode", exec_keyring_mode_to_string(c->keyring_mode));
2,230✔
1816
        if (r < 0)
2,230✔
1817
                return r;
1818

1819
        r = serialize_item(f, "exec-context-protect-hostname", protect_hostname_to_string(c->protect_hostname));
2,230✔
1820
        if (r < 0)
2,230✔
1821
                return r;
1822

1823
        r = serialize_item(f, "exec-context-private-hostname", c->private_hostname);
2,230✔
1824
        if (r < 0)
2,230✔
1825
                return r;
1826

1827
        r = serialize_item(f, "exec-context-protect-proc", protect_proc_to_string(c->protect_proc));
2,230✔
1828
        if (r < 0)
2,230✔
1829
                return r;
1830

1831
        r = serialize_item(f, "exec-context-proc-subset", proc_subset_to_string(c->proc_subset));
2,230✔
1832
        if (r < 0)
2,230✔
1833
                return r;
1834

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

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

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

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

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

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

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

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

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

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

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

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

1877
                r = serialize_item(f, key, value);
11,150✔
1878
                if (r < 0)
11,150✔
1879
                        return r;
1880
        }
1881

1882
        r = serialize_usec(f, "exec-context-timeout-clean-usec", c->timeout_clean_usec);
2,230✔
1883
        if (r < 0)
2,230✔
1884
                return r;
1885

1886
        if (c->nice_set) {
2,230✔
1887
                r = serialize_item_format(f, "exec-context-nice", "%i", c->nice);
2✔
1888
                if (r < 0)
2✔
1889
                        return r;
1890
        }
1891

1892
        if (c->oom_score_adjust_set) {
2,230✔
1893
                r = serialize_item_format(f, "exec-context-oom-score-adjust", "%i", c->oom_score_adjust);
654✔
1894
                if (r < 0)
654✔
1895
                        return r;
1896
        }
1897

1898
        if (c->coredump_filter_set) {
2,230✔
1899
                r = serialize_item_format(f, "exec-context-coredump-filter", "%"PRIx64, c->coredump_filter);
×
1900
                if (r < 0)
×
1901
                        return r;
1902
        }
1903

1904
        for (unsigned i = 0; i < RLIM_NLIMITS; i++) {
37,910✔
1905
                _cleanup_free_ char *key = NULL, *limit = NULL;
4,453✔
1906

1907
                if (!c->rlimit[i])
35,680✔
1908
                        continue;
31,227✔
1909

1910
                key = strjoin("exec-context-limit-", rlimit_to_string(i));
4,453✔
1911
                if (!key)
4,453✔
1912
                        return log_oom_debug();
×
1913

1914
                r = rlimit_format(c->rlimit[i], &limit);
4,453✔
1915
                if (r < 0)
4,453✔
1916
                        return r;
1917

1918
                r = serialize_item(f, key, limit);
4,453✔
1919
                if (r < 0)
4,453✔
1920
                        return r;
1921
        }
1922

1923
        if (c->ioprio_set) {
2,230✔
1924
                r = serialize_item_format(f, "exec-context-ioprio", "%d", c->ioprio);
5✔
1925
                if (r < 0)
5✔
1926
                        return r;
1927
        }
1928

1929
        if (c->cpu_sched_set) {
2,230✔
1930
                _cleanup_free_ char *policy_str = NULL;
×
1931

1932
                r = sched_policy_to_string_alloc(c->cpu_sched_policy, &policy_str);
×
1933
                if (r < 0)
×
1934
                        return r;
1935

1936
                r = serialize_item(f, "exec-context-cpu-scheduling-policy", policy_str);
×
1937
                if (r < 0)
×
1938
                        return r;
1939

1940
                r = serialize_item_format(f, "exec-context-cpu-scheduling-priority", "%i", c->cpu_sched_priority);
×
1941
                if (r < 0)
×
1942
                        return r;
1943

1944
                r = serialize_bool_elide(f, "exec-context-cpu-scheduling-reset-on-fork", c->cpu_sched_reset_on_fork);
×
1945
                if (r < 0)
×
1946
                        return r;
1947
        }
1948

1949
        if (c->cpu_set.set) {
2,230✔
1950
                _cleanup_free_ char *affinity = NULL;
×
1951

1952
                affinity = cpu_set_to_range_string(&c->cpu_set);
×
1953
                if (!affinity)
×
1954
                        return log_oom_debug();
×
1955

1956
                r = serialize_item(f, "exec-context-cpu-affinity", affinity);
×
1957
                if (r < 0)
×
1958
                        return r;
1959
        }
1960

1961
        if (mpol_is_valid(numa_policy_get_type(&c->numa_policy))) {
2,230✔
1962
                _cleanup_free_ char *nodes = NULL;
×
1963

1964
                nodes = cpu_set_to_range_string(&c->numa_policy.nodes);
×
1965
                if (!nodes)
×
1966
                        return log_oom_debug();
×
1967

1968
                if (nodes) {
×
1969
                        r = serialize_item(f, "exec-context-numa-mask", nodes);
×
1970
                        if (r < 0)
×
1971
                                return r;
1972
                }
1973

1974
                r = serialize_item_format(f, "exec-context-numa-policy", "%d", c->numa_policy.type);
×
1975
                if (r < 0)
×
1976
                        return r;
1977
        }
1978

1979
        r = serialize_bool_elide(f, "exec-context-cpu-affinity-from-numa", c->cpu_affinity_from_numa);
2,230✔
1980
        if (r < 0)
2,230✔
1981
                return r;
1982

1983
        if (c->timer_slack_nsec != NSEC_INFINITY) {
2,230✔
1984
                r = serialize_item_format(f, "exec-context-timer-slack-nsec", NSEC_FMT, c->timer_slack_nsec);
×
1985
                if (r < 0)
×
1986
                        return r;
1987
        }
1988

1989
        r = serialize_item(f, "exec-context-std-input", exec_input_to_string(c->std_input));
2,230✔
1990
        if (r < 0)
2,230✔
1991
                return r;
1992

1993
        r = serialize_item(f, "exec-context-std-output", exec_output_to_string(c->std_output));
2,230✔
1994
        if (r < 0)
2,230✔
1995
                return r;
1996

1997
        r = serialize_item(f, "exec-context-std-error", exec_output_to_string(c->std_error));
2,230✔
1998
        if (r < 0)
2,230✔
1999
                return r;
2000

2001
        r = serialize_bool_elide(f, "exec-context-stdio-as-fds", c->stdio_as_fds);
2,230✔
2002
        if (r < 0)
2,230✔
2003
                return r;
2004

2005
        switch (c->std_input) {
2,230✔
2006
        case EXEC_INPUT_NAMED_FD:
×
2007
                r = serialize_item(f, "exec-context-std-input-fd-name", c->stdio_fdname[STDIN_FILENO]);
×
2008
                if (r < 0)
×
2009
                        return r;
2010
                break;
2011

2012
        case EXEC_INPUT_FILE:
×
2013
                r = serialize_item(f, "exec-context-std-input-file", c->stdio_file[STDIN_FILENO]);
×
2014
                if (r < 0)
×
2015
                        return r;
2016
                break;
2017

2018
        default:
2,230✔
2019
                ;
2,230✔
2020
        }
2021

2022
        r = serialize_std_out_err(c, f, STDOUT_FILENO);
2,230✔
2023
        if (r < 0)
2,230✔
2024
                return r;
2025

2026
        r = serialize_std_out_err(c, f, STDERR_FILENO);
2,230✔
2027
        if (r < 0)
2,230✔
2028
                return r;
2029

2030
        r = serialize_item_base64mem(f, "exec-context-stdin-data", c->stdin_data, c->stdin_data_size);
2,230✔
2031
        if (r < 0)
2,230✔
2032
                return r;
2033

2034
        r = serialize_item(f, "exec-context-tty-path", c->tty_path);
2,230✔
2035
        if (r < 0)
2,230✔
2036
                return r;
2037

2038
        r = serialize_bool_elide(f, "exec-context-tty-reset", c->tty_reset);
2,230✔
2039
        if (r < 0)
2,230✔
2040
                return r;
2041

2042
        r = serialize_bool_elide(f, "exec-context-tty-vhangup", c->tty_vhangup);
2,230✔
2043
        if (r < 0)
2,230✔
2044
                return r;
2045

2046
        r = serialize_bool_elide(f, "exec-context-tty-vt-disallocate", c->tty_vt_disallocate);
2,230✔
2047
        if (r < 0)
2,230✔
2048
                return r;
2049

2050
        r = serialize_item_format(f, "exec-context-tty-rows", "%u", c->tty_rows);
2,230✔
2051
        if (r < 0)
2,230✔
2052
                return r;
2053

2054
        r = serialize_item_format(f, "exec-context-tty-columns", "%u", c->tty_cols);
2,230✔
2055
        if (r < 0)
2,230✔
2056
                return r;
2057

2058
        r = serialize_item_format(f, "exec-context-syslog-priority", "%i", c->syslog_priority);
2,230✔
2059
        if (r < 0)
2,230✔
2060
                return r;
2061

2062
        r = serialize_bool(f, "exec-context-syslog-level-prefix", c->syslog_level_prefix);
2,230✔
2063
        if (r < 0)
2,230✔
2064
                return r;
2065

2066
        r = serialize_item(f, "exec-context-syslog-identifier", c->syslog_identifier);
2,230✔
2067
        if (r < 0)
2,230✔
2068
                return r;
2069

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

2076
        if (c->log_ratelimit.interval > 0) {
2,230✔
2077
                r = serialize_usec(f, "exec-context-log-ratelimit-interval-usec", c->log_ratelimit.interval);
×
2078
                if (r < 0)
×
2079
                        return r;
2080
        }
2081

2082
        if (c->log_ratelimit.burst > 0) {
2,230✔
2083
                r = serialize_item_format(f, "exec-context-log-ratelimit-burst", "%u", c->log_ratelimit.burst);
×
2084
                if (r < 0)
×
2085
                        return r;
2086
        }
2087

2088
        r = serialize_string_set(f, "exec-context-log-filter-allowed-patterns", c->log_filter_allowed_patterns);
2,230✔
2089
        if (r < 0)
2,230✔
2090
                return r;
2091

2092
        r = serialize_string_set(f, "exec-context-log-filter-denied-patterns", c->log_filter_denied_patterns);
2,230✔
2093
        if (r < 0)
2,230✔
2094
                return r;
2095

2096
        FOREACH_ARRAY(field, c->log_extra_fields, c->n_log_extra_fields) {
2,230✔
2097
                r = serialize_item(f, "exec-context-log-extra-fields", field->iov_base);
×
2098
                if (r < 0)
×
2099
                        return r;
2100
        }
2101

2102
        r = serialize_item(f, "exec-context-log-namespace", c->log_namespace);
2,230✔
2103
        if (r < 0)
2,230✔
2104
                return r;
2105

2106
        if (c->secure_bits != 0) {
2,230✔
2107
                r = serialize_item_format(f, "exec-context-secure-bits", "%d", c->secure_bits);
×
2108
                if (r < 0)
×
2109
                        return r;
2110
        }
2111

2112
        if (c->capability_bounding_set != CAP_MASK_UNSET) {
2,230✔
2113
                r = serialize_item_format(f, "exec-context-capability-bounding-set", "%" PRIu64, c->capability_bounding_set);
276✔
2114
                if (r < 0)
276✔
2115
                        return r;
2116
        }
2117

2118
        if (c->capability_ambient_set != 0) {
2,230✔
2119
                r = serialize_item_format(f, "exec-context-capability-ambient-set", "%" PRIu64, c->capability_ambient_set);
76✔
2120
                if (r < 0)
76✔
2121
                        return r;
2122
        }
2123

2124
        if (c->user) {
2,230✔
2125
                r = serialize_item(f, "exec-context-user", c->user);
157✔
2126
                if (r < 0)
157✔
2127
                        return r;
2128
        }
2129

2130
        r = serialize_item(f, "exec-context-group", c->group);
2,230✔
2131
        if (r < 0)
2,230✔
2132
                return r;
2133

2134
        r = serialize_bool_elide(f, "exec-context-dynamic-user", c->dynamic_user);
2,230✔
2135
        if (r < 0)
2,230✔
2136
                return r;
2137

2138
        r = serialize_strv(f, "exec-context-supplementary-groups", c->supplementary_groups);
2,230✔
2139
        if (r < 0)
2,230✔
2140
                return r;
2141

2142
        r = serialize_item_tristate(f, "exec-context-set-login-environment", c->set_login_environment);
2,230✔
2143
        if (r < 0)
×
2144
                return r;
2145

2146
        r = serialize_item(f, "exec-context-pam-name", c->pam_name);
2,230✔
2147
        if (r < 0)
2,230✔
2148
                return r;
2149

2150
        r = serialize_strv(f, "exec-context-read-write-paths", c->read_write_paths);
2,230✔
2151
        if (r < 0)
2,230✔
2152
                return r;
2153

2154
        r = serialize_strv(f, "exec-context-read-only-paths", c->read_only_paths);
2,230✔
2155
        if (r < 0)
2,230✔
2156
                return r;
2157

2158
        r = serialize_strv(f, "exec-context-inaccessible-paths", c->inaccessible_paths);
2,230✔
2159
        if (r < 0)
2,230✔
2160
                return r;
2161

2162
        r = serialize_strv(f, "exec-context-exec-paths", c->exec_paths);
2,230✔
2163
        if (r < 0)
2,230✔
2164
                return r;
2165

2166
        r = serialize_strv(f, "exec-context-no-exec-paths", c->no_exec_paths);
2,230✔
2167
        if (r < 0)
2,230✔
2168
                return r;
2169

2170
        r = serialize_strv(f, "exec-context-exec-search-path", c->exec_search_path);
2,230✔
2171
        if (r < 0)
2,230✔
2172
                return r;
2173

2174
        r = serialize_item_format(f, "exec-context-mount-propagation-flag", "%lu", c->mount_propagation_flag);
2,230✔
2175
        if (r < 0)
2,230✔
2176
                return r;
2177

2178
        FOREACH_ARRAY(mount, c->bind_mounts, c->n_bind_mounts) {
2,245✔
2179
                _cleanup_free_ char *src_escaped = NULL, *dst_escaped = NULL;
15✔
2180

2181
                src_escaped = shell_escape(mount->source, ":" WHITESPACE);
15✔
2182
                if (!src_escaped)
15✔
2183
                        return log_oom_debug();
×
2184

2185
                dst_escaped = shell_escape(mount->destination, ":" WHITESPACE);
15✔
2186
                if (!dst_escaped)
15✔
2187
                        return log_oom_debug();
×
2188

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

2200
        FOREACH_ARRAY(tmpfs, c->temporary_filesystems, c->n_temporary_filesystems) {
2,234✔
2201
                _cleanup_free_ char *escaped = NULL;
4✔
2202

2203
                if (!isempty(tmpfs->options)) {
4✔
2204
                        escaped = shell_escape(tmpfs->options, ":");
×
2205
                        if (!escaped)
×
2206
                                return log_oom_debug();
×
2207
                }
2208

2209
                r = serialize_item_format(f, "exec-context-temporary-filesystems", "%s%s%s",
×
2210
                                          tmpfs->path,
2211
                                          isempty(escaped) ? "" : ":",
4✔
2212
                                          strempty(escaped));
2213
                if (r < 0)
4✔
2214
                        return r;
2215
        }
2216

2217
        r = serialize_item(f, "exec-context-utmp-id", c->utmp_id);
2,230✔
2218
        if (r < 0)
2,230✔
2219
                return r;
2220

2221
        r = serialize_item(f, "exec-context-utmp-mode", exec_utmp_mode_to_string(c->utmp_mode));
2,230✔
2222
        if (r < 0)
2,230✔
2223
                return r;
2224

2225
        r = serialize_bool_elide(f, "exec-context-no-new-privileges", c->no_new_privileges);
2,230✔
2226
        if (r < 0)
2,230✔
2227
                return r;
2228

2229
        if (c->selinux_context) {
2,230✔
2230
                r = serialize_item_format(f, "exec-context-selinux-context",
×
2231
                                          "%s%s",
2232
                                          c->selinux_context_ignore ? "-" : "",
×
2233
                                          c->selinux_context);
2234
                if (r < 0)
×
2235
                        return r;
2236
        }
2237

2238
        if (c->apparmor_profile) {
2,230✔
2239
                r = serialize_item_format(f, "exec-context-apparmor-profile",
×
2240
                                          "%s%s",
2241
                                          c->apparmor_profile_ignore ? "-" : "",
×
2242
                                          c->apparmor_profile);
2243
                if (r < 0)
×
2244
                        return r;
2245
        }
2246

2247
        if (c->smack_process_label) {
2,230✔
2248
                r = serialize_item_format(f, "exec-context-smack-process-label",
×
2249
                                          "%s%s",
2250
                                          c->smack_process_label_ignore ? "-" : "",
×
2251
                                          c->smack_process_label);
2252
                if (r < 0)
×
2253
                        return r;
2254
        }
2255

2256
        if (c->personality != PERSONALITY_INVALID) {
2,230✔
2257
                r = serialize_item(f, "exec-context-personality", personality_to_string(c->personality));
×
2258
                if (r < 0)
×
2259
                        return r;
2260
        }
2261

2262
        r = serialize_bool_elide(f, "exec-context-lock-personality", c->lock_personality);
2,230✔
2263
        if (r < 0)
2,230✔
2264
                return r;
2265

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

2276
        if (!set_isempty(c->syscall_archs)) {
2,230✔
2277
                void *id;
238✔
2278
                SET_FOREACH(id, c->syscall_archs) {
476✔
2279
                        r = serialize_item_format(f, "exec-context-syscall-archs", "%u", PTR_TO_UINT(id) - 1);
238✔
2280
                        if (r < 0)
238✔
2281
                                return r;
×
2282
                }
2283
        }
2284

2285
        if (c->syscall_errno > 0) {
2,230✔
2286
                r = serialize_item_format(f, "exec-context-syscall-errno", "%d", c->syscall_errno);
2,230✔
2287
                if (r < 0)
2,230✔
2288
                        return r;
2289
        }
2290

2291
        r = serialize_bool_elide(f, "exec-context-syscall-allow-list", c->syscall_allow_list);
2,230✔
2292
        if (r < 0)
2,230✔
2293
                return r;
2294

2295
        if (!hashmap_isempty(c->syscall_log)) {
2,230✔
2296
                void *errno_num, *id;
×
2297
                HASHMAP_FOREACH_KEY(errno_num, id, c->syscall_log) {
×
2298
                        r = serialize_item_format(f, "exec-context-syscall-log", "%d %d", PTR_TO_INT(id) - 1, PTR_TO_INT(errno_num));
×
2299
                        if (r < 0)
×
2300
                                return r;
×
2301
                }
2302
        }
2303

2304
        r = serialize_bool_elide(f, "exec-context-syscall-log-allow-list", c->syscall_log_allow_list);
2,230✔
2305
        if (r < 0)
2,230✔
2306
                return r;
2307
#endif
2308

2309
        if (c->restrict_namespaces != NAMESPACE_FLAGS_INITIAL) {
2,230✔
2310
                r = serialize_item_format(f, "exec-context-restrict-namespaces", "%lu", c->restrict_namespaces);
188✔
2311
                if (r < 0)
188✔
2312
                        return r;
2313
        }
2314

2315
        if (c->delegate_namespaces != NAMESPACE_FLAGS_INITIAL) {
2,230✔
2316
                r = serialize_item_format(f, "exec-context-delegate-namespaces", "%lu", c->delegate_namespaces);
9✔
2317
                if (r < 0)
9✔
2318
                        return r;
2319
        }
2320

2321
#if HAVE_LIBBPF
2322
        if (exec_context_restrict_filesystems_set(c)) {
2,230✔
2323
                char *fs;
×
2324
                SET_FOREACH(fs, c->restrict_filesystems) {
×
2325
                        r = serialize_item(f, "exec-context-restrict-filesystems", fs);
×
2326
                        if (r < 0)
×
2327
                                return r;
×
2328
                }
2329
        }
2330

2331
        r = serialize_bool_elide(f, "exec-context-restrict-filesystems-allow-list", c->restrict_filesystems_allow_list);
2,230✔
2332
        if (r < 0)
2,230✔
2333
                return r;
2334
#endif
2335

2336
        if (!set_isempty(c->address_families)) {
2,230✔
2337
                void *afp;
238✔
2338

2339
                SET_FOREACH(afp, c->address_families) {
1,134✔
2340
                        int af = PTR_TO_INT(afp);
896✔
2341

2342
                        if (af <= 0 || af >= af_max())
896✔
2343
                                continue;
×
2344

2345
                        r = serialize_item_format(f, "exec-context-address-families", "%d", af);
896✔
2346
                        if (r < 0)
896✔
2347
                                return r;
×
2348
                }
2349
        }
2350

2351
        r = serialize_bool_elide(f, "exec-context-address-families-allow-list", c->address_families_allow_list);
2,230✔
2352
        if (r < 0)
2,230✔
2353
                return r;
2354

2355
        r = serialize_item(f, "exec-context-network-namespace-path", c->network_namespace_path);
2,230✔
2356
        if (r < 0)
2,230✔
2357
                return r;
2358

2359
        r = serialize_item(f, "exec-context-ipc-namespace-path", c->ipc_namespace_path);
2,230✔
2360
        if (r < 0)
2,230✔
2361
                return r;
2362

2363
        FOREACH_ARRAY(mount, c->mount_images, c->n_mount_images) {
2,230✔
2364
                _cleanup_free_ char *s = NULL, *source_escaped = NULL, *dest_escaped = NULL;
×
2365

2366
                source_escaped = shell_escape(mount->source, WHITESPACE);
×
2367
                if (!source_escaped)
×
2368
                        return log_oom_debug();
×
2369

2370
                dest_escaped = shell_escape(mount->destination, WHITESPACE);
×
2371
                if (!dest_escaped)
×
2372
                        return log_oom_debug();
×
2373

2374
                s = strjoin(mount->ignore_enoent ? "-" : "",
×
2375
                            source_escaped,
2376
                            " ",
2377
                            dest_escaped);
2378
                if (!s)
×
2379
                        return log_oom_debug();
×
2380

2381
                LIST_FOREACH(mount_options, o, mount->mount_options) {
×
2382
                        _cleanup_free_ char *escaped = NULL;
×
2383

2384
                        if (isempty(o->options))
×
2385
                                continue;
×
2386

2387
                        escaped = shell_escape(o->options, ":");
×
2388
                        if (!escaped)
×
2389
                                return log_oom_debug();
×
2390

2391
                        if (!strextend(&s,
×
2392
                                       " ",
2393
                                       partition_designator_to_string(o->partition_designator),
2394
                                       ":",
2395
                                       escaped))
2396
                                return log_oom_debug();
×
2397
                }
2398

2399
                r = serialize_item(f, "exec-context-mount-image", s);
×
2400
                if (r < 0)
×
2401
                        return r;
2402
        }
2403

2404
        FOREACH_ARRAY(mount, c->extension_images, c->n_extension_images) {
2,230✔
2405
                _cleanup_free_ char *s = NULL, *source_escaped = NULL;
×
2406

2407
                source_escaped = shell_escape(mount->source, ":" WHITESPACE);
×
2408
                if (!source_escaped)
×
2409
                        return log_oom_debug();
×
2410

2411
                s = strjoin(mount->ignore_enoent ? "-" : "",
×
2412
                            source_escaped);
2413
                if (!s)
×
2414
                        return log_oom_debug();
×
2415

2416
                LIST_FOREACH(mount_options, o, mount->mount_options) {
×
2417
                        _cleanup_free_ char *escaped = NULL;
×
2418

2419
                        if (isempty(o->options))
×
2420
                                continue;
×
2421

2422
                        escaped = shell_escape(o->options, ":");
×
2423
                        if (!escaped)
×
2424
                                return log_oom_debug();
×
2425

2426
                        if (!strextend(&s,
×
2427
                                       " ",
2428
                                       partition_designator_to_string(o->partition_designator),
2429
                                       ":",
2430
                                       escaped))
2431
                                return log_oom_debug();
×
2432
                }
2433

2434
                r = serialize_item(f, "exec-context-extension-image", s);
×
2435
                if (r < 0)
×
2436
                        return r;
2437
        }
2438

2439
        r = serialize_strv(f, "exec-context-extension-directories", c->extension_directories);
2,230✔
2440
        if (r < 0)
2,230✔
2441
                return r;
2442

2443
        ExecSetCredential *sc;
2,230✔
2444
        HASHMAP_FOREACH(sc, c->set_credentials) {
2,230✔
2445
                _cleanup_free_ char *data = NULL;
×
2446

2447
                if (base64mem(sc->data, sc->size, &data) < 0)
×
2448
                        return log_oom_debug();
×
2449

2450
                r = serialize_item_format(f, "exec-context-set-credentials", "%s %s %s", sc->id, data, yes_no(sc->encrypted));
×
2451
                if (r < 0)
×
2452
                        return r;
2453
        }
2454

2455
        ExecLoadCredential *lc;
2,230✔
2456
        HASHMAP_FOREACH(lc, c->load_credentials) {
2,238✔
2457
                r = serialize_item_format(f, "exec-context-load-credentials", "%s %s %s", lc->id, lc->path, yes_no(lc->encrypted));
15✔
2458
                if (r < 0)
8✔
2459
                        return r;
×
2460
        }
2461

2462
        ExecImportCredential *ic;
2,230✔
2463
        ORDERED_SET_FOREACH(ic, c->import_credentials) {
3,039✔
2464
                r = serialize_item_format(f, "exec-context-import-credentials", "%s%s%s",
1,570✔
2465
                                          ic->glob,
2466
                                          ic->rename ? " " : "",
2467
                                          strempty(ic->rename));
809✔
2468
                if (r < 0)
809✔
2469
                        return r;
×
2470
        }
2471

2472
        r = serialize_image_policy(f, "exec-context-root-image-policy", c->root_image_policy);
2,230✔
2473
        if (r < 0)
2,230✔
2474
                return r;
2475

2476
        r = serialize_image_policy(f, "exec-context-mount-image-policy", c->mount_image_policy);
2,230✔
2477
        if (r < 0)
2,230✔
2478
                return r;
2479

2480
        r = serialize_image_policy(f, "exec-context-extension-image-policy", c->extension_image_policy);
2,230✔
2481
        if (r < 0)
2,230✔
2482
                return r;
2483

2484
        fputc('\n', f); /* End marker */
2,230✔
2485

2486
        return 0;
2487
}
2488

2489
static int exec_context_deserialize(ExecContext *c, FILE *f) {
11,626✔
2490
        int r;
11,626✔
2491

2492
        assert(f);
11,626✔
2493

2494
        if (!c)
11,626✔
2495
                return 0;
2496

2497
        for (;;) {
1,303,179✔
2498
                _cleanup_free_ char *l = NULL;
1,291,553✔
2499
                const char *val;
1,303,179✔
2500

2501
                r = deserialize_read_line(f, &l);
1,303,179✔
2502
                if (r < 0)
1,303,179✔
2503
                        return r;
2504
                if (r == 0) /* eof or end marker */
1,303,179✔
2505
                        break;
2506

2507
                if ((val = startswith(l, "exec-context-environment="))) {
1,291,553✔
2508
                        r = deserialize_strv(val, &c->environment);
3,835✔
2509
                        if (r < 0)
3,835✔
2510
                                return r;
2511
                } else if ((val = startswith(l, "exec-context-environment-files="))) {
1,287,718✔
2512
                        r = deserialize_strv(val, &c->environment_files);
338✔
2513
                        if (r < 0)
338✔
2514
                                return r;
2515
                } else if ((val = startswith(l, "exec-context-pass-environment="))) {
1,287,380✔
2516
                        r = deserialize_strv(val, &c->pass_environment);
432✔
2517
                        if (r < 0)
432✔
2518
                                return r;
2519
                } else if ((val = startswith(l, "exec-context-unset-environment="))) {
1,286,948✔
2520
                        r = deserialize_strv(val, &c->unset_environment);
1,404✔
2521
                        if (r < 0)
1,404✔
2522
                                return r;
2523
                } else if ((val = startswith(l, "exec-context-working-directory="))) {
1,285,544✔
2524
                        ssize_t k;
860✔
2525
                        char *p;
860✔
2526

2527
                        k = cunescape(val, 0, &p);
860✔
2528
                        if (k < 0)
860✔
2529
                                return k;
×
2530
                        free_and_replace(c->working_directory, p);
860✔
2531
                } else if ((val = startswith(l, "exec-context-root-directory="))) {
1,284,684✔
2532
                        ssize_t k;
7✔
2533
                        char *p;
7✔
2534

2535
                        k = cunescape(val, 0, &p);
7✔
2536
                        if (k < 0)
7✔
2537
                                return k;
×
2538
                        free_and_replace(c->root_directory, p);
7✔
2539
                } else if ((val = startswith(l, "exec-context-root-image="))) {
1,284,677✔
2540
                        ssize_t k;
8✔
2541
                        char *p;
8✔
2542

2543
                        k = cunescape(val, 0, &p);
8✔
2544
                        if (k < 0)
8✔
2545
                                return k;
×
2546
                        free_and_replace(c->root_image, p);
8✔
2547
                } else if ((val = startswith(l, "exec-context-root-image-options="))) {
1,284,669✔
2548
                        for (;;) {
×
2549
                                _cleanup_free_ char *word = NULL, *mount_options = NULL, *partition = NULL;
×
2550
                                PartitionDesignator partition_designator;
×
2551
                                MountOptions *o = NULL;
×
2552
                                const char *p;
×
2553

2554
                                r = extract_first_word(&val, &word, NULL, 0);
×
2555
                                if (r < 0)
×
2556
                                        return r;
2557
                                if (r == 0)
×
2558
                                        break;
2559

2560
                                p = word;
×
2561
                                r = extract_many_words(&p, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &partition, &mount_options);
×
2562
                                if (r < 0)
×
2563
                                        return r;
2564
                                if (r == 0)
×
2565
                                        continue;
×
2566

2567
                                partition_designator = partition_designator_from_string(partition);
×
2568
                                if (partition_designator < 0)
×
2569
                                        return -EINVAL;
2570

2571
                                o = new(MountOptions, 1);
×
2572
                                if (!o)
×
2573
                                        return log_oom_debug();
×
2574
                                *o = (MountOptions) {
×
2575
                                        .partition_designator = partition_designator,
2576
                                        .options = TAKE_PTR(mount_options),
×
2577
                                };
2578
                                LIST_APPEND(mount_options, c->root_image_options, o);
×
2579
                        }
2580
                } else if ((val = startswith(l, "exec-context-root-verity="))) {
1,284,669✔
2581
                        r = free_and_strdup(&c->root_verity, val);
×
2582
                        if (r < 0)
×
2583
                                return r;
2584
                } else if ((val = startswith(l, "exec-context-root-hash-path="))) {
1,284,669✔
2585
                        r = free_and_strdup(&c->root_hash_path, val);
×
2586
                        if (r < 0)
×
2587
                                return r;
2588
                } else if ((val = startswith(l, "exec-context-root-hash-sig-path="))) {
1,284,669✔
2589
                        r = free_and_strdup(&c->root_hash_sig_path, val);
×
2590
                        if (r < 0)
×
2591
                                return r;
2592
                } else if ((val = startswith(l, "exec-context-root-hash="))) {
1,284,669✔
2593
                        c->root_hash = mfree(c->root_hash);
4✔
2594
                        r = unhexmem(val, &c->root_hash, &c->root_hash_size);
4✔
2595
                        if (r < 0)
4✔
2596
                                return r;
2597
                } else if ((val = startswith(l, "exec-context-root-hash-sig="))) {
1,284,665✔
2598
                        c->root_hash_sig = mfree(c->root_hash_sig);
×
2599
                        r= unbase64mem(val, &c->root_hash_sig, &c->root_hash_sig_size);
×
2600
                        if (r < 0)
×
2601
                                return r;
2602
                } else if ((val = startswith(l, "exec-context-root-ephemeral="))) {
1,284,665✔
2603
                        r = parse_boolean(val);
×
2604
                        if (r < 0)
×
2605
                                return r;
2606
                        c->root_ephemeral = r;
×
2607
                } else if ((val = startswith(l, "exec-context-umask="))) {
1,284,665✔
2608
                        r = parse_mode(val, &c->umask);
11,626✔
2609
                        if (r < 0)
11,626✔
2610
                                return r;
2611
                } else if ((val = startswith(l, "exec-context-private-non-blocking="))) {
1,273,039✔
2612
                        r = parse_boolean(val);
×
2613
                        if (r < 0)
×
2614
                                return r;
2615
                        c->non_blocking = r;
×
2616
                } else if ((val = startswith(l, "exec-context-private-mounts="))) {
1,273,039✔
2617
                        r = safe_atoi(val, &c->private_mounts);
131✔
2618
                        if (r < 0)
131✔
2619
                                return r;
2620
                } else if ((val = startswith(l, "exec-context-mount-api-vfs="))) {
1,272,908✔
2621
                        r = safe_atoi(val, &c->mount_apivfs);
30✔
2622
                        if (r < 0)
30✔
2623
                                return r;
2624
                } else if ((val = startswith(l, "exec-context-bind-log-sockets="))) {
1,272,878✔
2625
                        r = safe_atoi(val, &c->bind_log_sockets);
2✔
2626
                        if (r < 0)
2✔
2627
                                return r;
2628
                } else if ((val = startswith(l, "exec-context-memory-ksm="))) {
1,272,876✔
2629
                        r = safe_atoi(val, &c->memory_ksm);
×
2630
                        if (r < 0)
×
2631
                                return r;
2632
                } else if ((val = startswith(l, "exec-context-private-tmp="))) {
1,272,876✔
2633
                        c->private_tmp = private_tmp_from_string(val);
11,626✔
2634
                        if (c->private_tmp < 0)
11,626✔
2635
                                return c->private_tmp;
2636
                } else if ((val = startswith(l, "exec-context-private-var-tmp="))) {
1,261,250✔
2637
                        c->private_var_tmp = private_tmp_from_string(val);
11,626✔
2638
                        if (c->private_var_tmp < 0)
11,626✔
2639
                                return c->private_var_tmp;
2640
                } else if ((val = startswith(l, "exec-context-private-devices="))) {
1,249,624✔
2641
                        r = parse_boolean(val);
730✔
2642
                        if (r < 0)
730✔
2643
                                return r;
2644
                        c->private_devices = r;
730✔
2645
                } else if ((val = startswith(l, "exec-context-protect-kernel-tunables="))) {
1,248,894✔
2646
                        r = parse_boolean(val);
533✔
2647
                        if (r < 0)
533✔
2648
                                return r;
2649
                        c->protect_kernel_tunables = r;
533✔
2650
                } else if ((val = startswith(l, "exec-context-protect-kernel-modules="))) {
1,248,361✔
2651
                        r = parse_boolean(val);
1,727✔
2652
                        if (r < 0)
1,727✔
2653
                                return r;
2654
                        c->protect_kernel_modules = r;
1,727✔
2655
                } else if ((val = startswith(l, "exec-context-protect-kernel-logs="))) {
1,246,634✔
2656
                        r = parse_boolean(val);
1,727✔
2657
                        if (r < 0)
1,727✔
2658
                                return r;
2659
                        c->protect_kernel_logs = r;
1,727✔
2660
                } else if ((val = startswith(l, "exec-context-protect-clock="))) {
1,244,907✔
2661
                        r = parse_boolean(val);
1,568✔
2662
                        if (r < 0)
1,568✔
2663
                                return r;
2664
                        c->protect_clock = r;
1,568✔
2665
                } else if ((val = startswith(l, "exec-context-protect-control-groups="))) {
1,243,339✔
2666
                        r = protect_control_groups_from_string(val);
11,626✔
2667
                        if (r < 0)
11,626✔
2668
                                return r;
2669
                        c->protect_control_groups = r;
11,626✔
2670
                } else if ((val = startswith(l, "exec-context-private-network="))) {
1,231,713✔
2671
                        r = parse_boolean(val);
60✔
2672
                        if (r < 0)
60✔
2673
                                return r;
2674
                        c->private_network = r;
60✔
2675
                } else if ((val = startswith(l, "exec-context-private-users="))) {
1,231,653✔
2676
                        c->private_users = private_users_from_string(val);
11,626✔
2677
                        if (c->private_users < 0)
11,626✔
2678
                                return -EINVAL;
2679
                } else if ((val = startswith(l, "exec-context-private-ipc="))) {
1,220,027✔
2680
                        r = parse_boolean(val);
6✔
2681
                        if (r < 0)
6✔
2682
                                return r;
2683
                        c->private_ipc = r;
6✔
2684
                } else if ((val = startswith(l, "exec-context-private-pids="))) {
1,220,021✔
2685
                        c->private_pids = private_pids_from_string(val);
11,626✔
2686
                        if (c->private_pids < 0)
11,626✔
2687
                                return -EINVAL;
2688
                } else if ((val = startswith(l, "exec-context-remove-ipc="))) {
1,208,395✔
2689
                        r = parse_boolean(val);
70✔
2690
                        if (r < 0)
70✔
2691
                                return r;
2692
                        c->remove_ipc = r;
70✔
2693
                } else if ((val = startswith(l, "exec-context-protect-home="))) {
1,208,325✔
2694
                        c->protect_home = protect_home_from_string(val);
11,626✔
2695
                        if (c->protect_home < 0)
11,626✔
2696
                                return -EINVAL;
2697
                } else if ((val = startswith(l, "exec-context-protect-system="))) {
1,196,699✔
2698
                        c->protect_system = protect_system_from_string(val);
11,626✔
2699
                        if (c->protect_system < 0)
11,626✔
2700
                                return -EINVAL;
2701
                } else if ((val = startswith(l, "exec-context-same-pgrp="))) {
1,185,073✔
2702
                        r = parse_boolean(val);
863✔
2703
                        if (r < 0)
863✔
2704
                                return r;
2705
                        c->same_pgrp = r;
863✔
2706
                } else if ((val = startswith(l, "exec-context-non-blocking="))) {
1,184,210✔
2707
                        r = parse_boolean(val);
×
2708
                        if (r < 0)
×
2709
                                return r;
2710
                        c->non_blocking = r;
×
2711
                } else if ((val = startswith(l, "exec-context-ignore-sigpipe="))) {
1,184,210✔
2712
                        r = parse_boolean(val);
11,626✔
2713
                        if (r < 0)
11,626✔
2714
                                return r;
2715
                        c->ignore_sigpipe = r;
11,626✔
2716
                } else if ((val = startswith(l, "exec-context-memory-deny-write-execute="))) {
1,172,584✔
2717
                        r = parse_boolean(val);
2,216✔
2718
                        if (r < 0)
2,216✔
2719
                                return r;
2720
                        c->memory_deny_write_execute = r;
2,216✔
2721
                } else if ((val = startswith(l, "exec-context-restrict-realtime="))) {
1,170,368✔
2722
                        r = parse_boolean(val);
2,216✔
2723
                        if (r < 0)
2,216✔
2724
                                return r;
2725
                        c->restrict_realtime = r;
2,216✔
2726
                } else if ((val = startswith(l, "exec-context-restrict-suid-sgid="))) {
1,168,152✔
2727
                        r = parse_boolean(val);
2,155✔
2728
                        if (r < 0)
2,155✔
2729
                                return r;
2730
                        c->restrict_suid_sgid = r;
2,155✔
2731
                } else if ((val = startswith(l, "exec-context-keyring-mode="))) {
1,165,997✔
2732
                        c->keyring_mode = exec_keyring_mode_from_string(val);
11,626✔
2733
                        if (c->keyring_mode < 0)
11,626✔
2734
                                return -EINVAL;
2735
                } else if ((val = startswith(l, "exec-context-protect-hostname="))) {
1,154,371✔
2736
                        c->protect_hostname = protect_hostname_from_string(val);
11,626✔
2737
                        if (c->protect_hostname < 0)
11,626✔
2738
                                return -EINVAL;
2739
                } else if ((val = startswith(l, "exec-context-private-hostname="))) {
1,142,745✔
2740
                        r = free_and_strdup(&c->private_hostname, val);
4✔
2741
                        if (r < 0)
4✔
2742
                                return r;
2743
                } else if ((val = startswith(l, "exec-context-protect-proc="))) {
1,142,741✔
2744
                        c->protect_proc = protect_proc_from_string(val);
11,626✔
2745
                        if (c->protect_proc < 0)
11,626✔
2746
                                return -EINVAL;
2747
                } else if ((val = startswith(l, "exec-context-proc-subset="))) {
1,131,115✔
2748
                        c->proc_subset = proc_subset_from_string(val);
11,626✔
2749
                        if (c->proc_subset < 0)
11,626✔
2750
                                return -EINVAL;
2751
                } else if ((val = startswith(l, "exec-context-runtime-directory-preserve-mode="))) {
1,119,489✔
2752
                        c->runtime_directory_preserve_mode = exec_preserve_mode_from_string(val);
11,626✔
2753
                        if (c->runtime_directory_preserve_mode < 0)
11,626✔
2754
                                return -EINVAL;
2755
                } else if ((val = startswith(l, "exec-context-directories-"))) {
1,107,863✔
2756
                        _cleanup_free_ char *type = NULL, *mode = NULL;
×
2757
                        ExecDirectoryType dt;
58,130✔
2758

2759
                        r = extract_many_words(&val, "= ", 0, &type, &mode);
58,130✔
2760
                        if (r < 0)
58,130✔
2761
                                return r;
2762
                        if (r == 0 || !mode)
58,130✔
2763
                                return -EINVAL;
2764

2765
                        dt = exec_directory_type_from_string(type);
58,130✔
2766
                        if (dt < 0)
58,130✔
2767
                                return -EINVAL;
2768

2769
                        r = parse_mode(mode, &c->directories[dt].mode);
58,130✔
2770
                        if (r < 0)
58,130✔
2771
                                return r;
2772

2773
                        for (;;) {
61,856✔
2774
                                _cleanup_free_ char *tuple = NULL, *path = NULL, *only_create = NULL, *read_only = NULL;
61,749✔
2775
                                ExecDirectoryFlags exec_directory_flags = 0;
61,856✔
2776
                                const char *p;
61,856✔
2777

2778
                                /* Use EXTRACT_UNESCAPE_RELAX here, as we unescape the colons in subsequent calls */
2779
                                r = extract_first_word(&val, &tuple, WHITESPACE, EXTRACT_UNESCAPE_SEPARATORS|EXTRACT_UNESCAPE_RELAX);
61,856✔
2780
                                if (r < 0)
61,856✔
2781
                                        return r;
2782
                                if (r == 0)
61,856✔
2783
                                        break;
2784

2785
                                p = tuple;
3,726✔
2786
                                r = extract_many_words(&p, ":", EXTRACT_UNESCAPE_SEPARATORS, &path, &only_create, &read_only);
3,726✔
2787
                                if (r < 0)
3,726✔
2788
                                        return r;
2789
                                if (r < 2)
3,726✔
2790
                                        continue;
×
2791

2792
                                r = parse_boolean(only_create);
3,726✔
2793
                                if (r < 0)
3,726✔
2794
                                        return r;
2795
                                if (r > 0)
3,726✔
2796
                                        exec_directory_flags |= EXEC_DIRECTORY_ONLY_CREATE;
5✔
2797

2798
                                r = parse_boolean(read_only);
3,726✔
2799
                                if (r < 0)
3,726✔
2800
                                        return r;
2801
                                if (r > 0)
3,726✔
2802
                                        exec_directory_flags |= EXEC_DIRECTORY_READ_ONLY;
50✔
2803

2804
                                r = exec_directory_add(&c->directories[dt], path, /* symlink= */ NULL, exec_directory_flags);
3,726✔
2805
                                if (r < 0)
3,726✔
2806
                                        return r;
2807

2808
                                if (isempty(p))
3,726✔
2809
                                        continue;
3,619✔
2810

2811
                                for (;;) {
385✔
2812
                                        _cleanup_free_ char *link = NULL;
246✔
2813

2814
                                        r = extract_first_word(&p, &link, ":", EXTRACT_UNESCAPE_SEPARATORS);
246✔
2815
                                        if (r < 0)
246✔
2816
                                                return r;
2817
                                        if (r == 0)
246✔
2818
                                                break;
2819

2820
                                        r = strv_consume(&c->directories[dt].items[c->directories[dt].n_items - 1].symlinks, TAKE_PTR(link));
139✔
2821
                                        if (r < 0)
139✔
2822
                                                return r;
2823
                                }
2824
                        }
2825
                } else if ((val = startswith(l, "exec-context-timeout-clean-usec="))) {
1,049,733✔
2826
                        r = deserialize_usec(val, &c->timeout_clean_usec);
×
2827
                        if (r < 0)
×
2828
                                return r;
2829
                } else if ((val = startswith(l, "exec-context-nice="))) {
1,049,733✔
2830
                        r = safe_atoi(val, &c->nice);
15✔
2831
                        if (r < 0)
15✔
2832
                                return r;
2833
                        c->nice_set = true;
15✔
2834
                } else if ((val = startswith(l, "exec-context-working-directory-missing-ok="))) {
1,049,718✔
2835
                        r = parse_boolean(val);
800✔
2836
                        if (r < 0)
800✔
2837
                                return r;
2838
                        c->working_directory_missing_ok = r;
800✔
2839
                } else if ((val = startswith(l, "exec-context-working-directory-home="))) {
1,048,918✔
2840
                        r = parse_boolean(val);
151✔
2841
                        if (r < 0)
151✔
2842
                                return r;
2843
                        c->working_directory_home = r;
151✔
2844
                } else if ((val = startswith(l, "exec-context-oom-score-adjust="))) {
1,048,767✔
2845
                        r = safe_atoi(val, &c->oom_score_adjust);
1,306✔
2846
                        if (r < 0)
1,306✔
2847
                                return r;
2848
                        c->oom_score_adjust_set = true;
1,306✔
2849
                } else if ((val = startswith(l, "exec-context-coredump-filter="))) {
1,047,461✔
2850
                        r = safe_atoux64(val, &c->coredump_filter);
2✔
2851
                        if (r < 0)
2✔
2852
                                return r;
2853
                        c->coredump_filter_set = true;
2✔
2854
                } else if ((val = startswith(l, "exec-context-limit-"))) {
1,047,459✔
2855
                        _cleanup_free_ struct rlimit *rlimit = NULL;
×
2856
                        _cleanup_free_ char *limit = NULL;
23,247✔
2857
                        int type;
23,247✔
2858

2859
                        r = extract_first_word(&val, &limit, "=", 0);
23,247✔
2860
                        if (r < 0)
23,247✔
2861
                                return r;
2862
                        if (r == 0 || !val)
23,247✔
2863
                                return -EINVAL;
2864

2865
                        type = rlimit_from_string(limit);
23,247✔
2866
                        if (type < 0)
23,247✔
2867
                                return -EINVAL;
2868

2869
                        if (!c->rlimit[type]) {
23,247✔
2870
                                rlimit = new0(struct rlimit, 1);
23,247✔
2871
                                if (!rlimit)
23,247✔
2872
                                        return log_oom_debug();
×
2873

2874
                                r = rlimit_parse(type, val, rlimit);
23,247✔
2875
                                if (r < 0)
23,247✔
2876
                                        return r;
2877

2878
                                c->rlimit[type] = TAKE_PTR(rlimit);
23,247✔
2879
                        } else {
2880
                                r = rlimit_parse(type, val, c->rlimit[type]);
×
2881
                                if (r < 0)
×
2882
                                        return r;
2883
                        }
2884
                } else if ((val = startswith(l, "exec-context-ioprio="))) {
1,024,212✔
2885
                        r = safe_atoi(val, &c->ioprio);
7✔
2886
                        if (r < 0)
7✔
2887
                                return r;
2888
                        c->ioprio_set = true;
7✔
2889
                } else if ((val = startswith(l, "exec-context-cpu-scheduling-policy="))) {
1,024,205✔
2890
                        c->cpu_sched_policy = sched_policy_from_string(val);
×
2891
                        if (c->cpu_sched_policy < 0)
×
2892
                                return -EINVAL;
2893
                        c->cpu_sched_set = true;
×
2894
                } else if ((val = startswith(l, "exec-context-cpu-scheduling-priority="))) {
1,024,205✔
2895
                        r = safe_atoi(val, &c->cpu_sched_priority);
×
2896
                        if (r < 0)
×
2897
                                return r;
2898
                        c->cpu_sched_set = true;
×
2899
                } else if ((val = startswith(l, "exec-context-cpu-scheduling-reset-on-fork="))) {
1,024,205✔
2900
                        r = parse_boolean(val);
×
2901
                        if (r < 0)
×
2902
                                return r;
2903
                        c->cpu_sched_reset_on_fork = r;
×
2904
                        c->cpu_sched_set = true;
×
2905
                } else if ((val = startswith(l, "exec-context-cpu-affinity="))) {
1,024,205✔
2906
                        if (c->cpu_set.set)
×
2907
                                return -EINVAL; /* duplicated */
2908

2909
                        r = parse_cpu_set(val, &c->cpu_set);
×
2910
                        if (r < 0)
×
2911
                                return r;
2912
                } else if ((val = startswith(l, "exec-context-numa-mask="))) {
1,024,205✔
2913
                        if (c->numa_policy.nodes.set)
19✔
2914
                                return -EINVAL; /* duplicated */
2915

2916
                        r = parse_cpu_set(val, &c->numa_policy.nodes);
19✔
2917
                        if (r < 0)
19✔
2918
                                return r;
2919
                } else if ((val = startswith(l, "exec-context-numa-policy="))) {
1,024,186✔
2920
                        r = safe_atoi(val, &c->numa_policy.type);
19✔
2921
                        if (r < 0)
19✔
2922
                                return r;
2923
                } else if ((val = startswith(l, "exec-context-cpu-affinity-from-numa="))) {
1,024,167✔
2924
                        r = parse_boolean(val);
2✔
2925
                        if (r < 0)
2✔
2926
                                return r;
2927
                        c->cpu_affinity_from_numa = r;
2✔
2928
                } else if ((val = startswith(l, "exec-context-timer-slack-nsec="))) {
1,024,165✔
2929
                        r = deserialize_usec(val, (usec_t *)&c->timer_slack_nsec);
×
2930
                        if (r < 0)
×
2931
                                return r;
2932
                } else if ((val = startswith(l, "exec-context-std-input="))) {
1,024,165✔
2933
                        c->std_input = exec_input_from_string(val);
11,626✔
2934
                        if (c->std_input < 0)
11,626✔
2935
                                return c->std_input;
2936
                } else if ((val = startswith(l, "exec-context-std-output="))) {
1,012,539✔
2937
                        c->std_output = exec_output_from_string(val);
11,626✔
2938
                        if (c->std_output < 0)
11,626✔
2939
                                return c->std_output;
2940
                } else if ((val = startswith(l, "exec-context-std-error="))) {
1,000,913✔
2941
                        c->std_error = exec_output_from_string(val);
11,626✔
2942
                        if (c->std_error < 0)
11,626✔
2943
                                return c->std_error;
2944
                } else if ((val = startswith(l, "exec-context-stdio-as-fds="))) {
989,287✔
2945
                        r = parse_boolean(val);
550✔
2946
                        if (r < 0)
550✔
2947
                                return r;
2948
                        c->stdio_as_fds = r;
550✔
2949
                } else if ((val = startswith(l, "exec-context-std-input-fd-name="))) {
988,737✔
2950
                        r = free_and_strdup(&c->stdio_fdname[STDIN_FILENO], val);
×
2951
                        if (r < 0)
×
2952
                                return r;
2953
                } else if ((val = startswith(l, "exec-context-std-output-fd-name="))) {
988,737✔
2954
                        r = free_and_strdup(&c->stdio_fdname[STDOUT_FILENO], val);
×
2955
                        if (r < 0)
×
2956
                                return r;
2957
                } else if ((val = startswith(l, "exec-context-std-error-fd-name="))) {
988,737✔
2958
                        r = free_and_strdup(&c->stdio_fdname[STDERR_FILENO], val);
×
2959
                        if (r < 0)
×
2960
                                return r;
2961
                } else if ((val = startswith(l, "exec-context-std-input-file="))) {
988,737✔
2962
                        r = free_and_strdup(&c->stdio_file[STDIN_FILENO], val);
×
2963
                        if (r < 0)
×
2964
                                return r;
2965
                } else if ((val = startswith(l, "exec-context-std-output-file="))) {
988,737✔
2966
                        r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], val);
4✔
2967
                        if (r < 0)
4✔
2968
                                return r;
2969
                } else if ((val = startswith(l, "exec-context-std-output-file-append="))) {
988,733✔
2970
                        r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], val);
1✔
2971
                        if (r < 0)
1✔
2972
                                return r;
2973
                } else if ((val = startswith(l, "exec-context-std-output-file-truncate="))) {
988,732✔
2974
                        r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], val);
2✔
2975
                        if (r < 0)
2✔
2976
                                return r;
2977
                } else if ((val = startswith(l, "exec-context-std-error-file="))) {
988,730✔
2978
                        r = free_and_strdup(&c->stdio_file[STDERR_FILENO], val);
2✔
2979
                        if (r < 0)
2✔
2980
                                return r;
2981
                } else if ((val = startswith(l, "exec-context-std-error-file-append="))) {
988,728✔
2982
                        r = free_and_strdup(&c->stdio_file[STDERR_FILENO], val);
1✔
2983
                        if (r < 0)
1✔
2984
                                return r;
2985
                } else if ((val = startswith(l, "exec-context-std-error-file-truncate="))) {
988,727✔
2986
                        r = free_and_strdup(&c->stdio_file[STDERR_FILENO], val);
1✔
2987
                        if (r < 0)
1✔
2988
                                return r;
2989
                } else if ((val = startswith(l, "exec-context-stdin-data="))) {
988,726✔
2990
                        if (c->stdin_data)
1✔
2991
                                return -EINVAL; /* duplicated */
2992

2993
                        r = unbase64mem(val, &c->stdin_data, &c->stdin_data_size);
1✔
2994
                        if (r < 0)
1✔
2995
                                return r;
2996
                } else if ((val = startswith(l, "exec-context-tty-path="))) {
988,725✔
2997
                        r = free_and_strdup(&c->tty_path, val);
166✔
2998
                        if (r < 0)
166✔
2999
                                return r;
3000
                } else if ((val = startswith(l, "exec-context-tty-reset="))) {
988,559✔
3001
                        r = parse_boolean(val);
155✔
3002
                        if (r < 0)
155✔
3003
                                return r;
3004
                        c->tty_reset = r;
155✔
3005
                } else if ((val = startswith(l, "exec-context-tty-vhangup="))) {
988,404✔
3006
                        r = parse_boolean(val);
150✔
3007
                        if (r < 0)
150✔
3008
                                return r;
3009
                        c->tty_vhangup = r;
150✔
3010
                } else if ((val = startswith(l, "exec-context-tty-vt-disallocate="))) {
988,254✔
3011
                        r = parse_boolean(val);
84✔
3012
                        if (r < 0)
84✔
3013
                                return r;
3014
                        c->tty_vt_disallocate = r;
84✔
3015
                } else if ((val = startswith(l, "exec-context-tty-rows="))) {
988,170✔
3016
                        r = safe_atou(val, &c->tty_rows);
11,626✔
3017
                        if (r < 0)
11,626✔
3018
                                return r;
3019
                } else if ((val = startswith(l, "exec-context-tty-columns="))) {
976,544✔
3020
                        r = safe_atou(val, &c->tty_cols);
11,626✔
3021
                        if (r < 0)
11,626✔
3022
                                return r;
3023
                } else if ((val = startswith(l, "exec-context-syslog-priority="))) {
964,918✔
3024
                        r = safe_atoi(val, &c->syslog_priority);
11,626✔
3025
                        if (r < 0)
11,626✔
3026
                                return r;
3027
                } else if ((val = startswith(l, "exec-context-syslog-level-prefix="))) {
953,292✔
3028
                        r = parse_boolean(val);
11,626✔
3029
                        if (r < 0)
11,626✔
3030
                                return r;
3031
                        c->syslog_level_prefix = r;
11,626✔
3032
                } else if ((val = startswith(l, "exec-context-syslog-identifier="))) {
941,666✔
3033
                        r = free_and_strdup(&c->syslog_identifier, val);
×
3034
                        if (r < 0)
×
3035
                                return r;
3036
                } else if ((val = startswith(l, "exec-context-log-level-max="))) {
941,666✔
3037
                        /* See comment in serialization. */
3038
                        r = safe_atoi(val, &c->log_level_max);
11,626✔
3039
                        if (r < 0)
11,626✔
3040
                                return r;
3041
                } else if ((val = startswith(l, "exec-context-log-ratelimit-interval-usec="))) {
930,040✔
3042
                        r = deserialize_usec(val, &c->log_ratelimit.interval);
×
3043
                        if (r < 0)
×
3044
                                return r;
3045
                } else if ((val = startswith(l, "exec-context-log-ratelimit-burst="))) {
930,040✔
3046
                        r = safe_atou(val, &c->log_ratelimit.burst);
×
3047
                        if (r < 0)
×
3048
                                return r;
3049
                } else if ((val = startswith(l, "exec-context-log-filter-allowed-patterns="))) {
930,040✔
3050
                        r = set_put_strdup(&c->log_filter_allowed_patterns, val);
9✔
3051
                        if (r < 0)
9✔
3052
                                return r;
3053
                } else if ((val = startswith(l, "exec-context-log-filter-denied-patterns="))) {
930,031✔
3054
                        r = set_put_strdup(&c->log_filter_denied_patterns, val);
5✔
3055
                        if (r < 0)
5✔
3056
                                return r;
3057
                } else if ((val = startswith(l, "exec-context-log-extra-fields="))) {
930,026✔
3058
                        if (!GREEDY_REALLOC(c->log_extra_fields, c->n_log_extra_fields + 1))
619✔
3059
                                return log_oom_debug();
×
3060

3061
                        c->log_extra_fields[c->n_log_extra_fields++].iov_base = strdup(val);
619✔
3062
                        if (!c->log_extra_fields[c->n_log_extra_fields-1].iov_base)
619✔
3063
                                return log_oom_debug();
×
3064
                } else if ((val = startswith(l, "exec-context-log-namespace="))) {
929,407✔
3065
                        r = free_and_strdup(&c->log_namespace, val);
2✔
3066
                        if (r < 0)
2✔
3067
                                return r;
3068
                } else if ((val = startswith(l, "exec-context-secure-bits="))) {
929,405✔
3069
                        r = safe_atoi(val, &c->secure_bits);
×
3070
                        if (r < 0)
×
3071
                                return r;
3072
                } else if ((val = startswith(l, "exec-context-capability-bounding-set="))) {
929,405✔
3073
                        r = safe_atou64(val, &c->capability_bounding_set);
2,349✔
3074
                        if (r < 0)
2,349✔
3075
                                return r;
3076
                } else if ((val = startswith(l, "exec-context-capability-ambient-set="))) {
927,056✔
3077
                        r = safe_atou64(val, &c->capability_ambient_set);
1,289✔
3078
                        if (r < 0)
1,289✔
3079
                                return r;
3080
                } else if ((val = startswith(l, "exec-context-user="))) {
925,767✔
3081
                        r = free_and_strdup(&c->user, val);
2,627✔
3082
                        if (r < 0)
2,627✔
3083
                                return r;
3084
                } else if ((val = startswith(l, "exec-context-group="))) {
923,140✔
3085
                        r = free_and_strdup(&c->group, val);
73✔
3086
                        if (r < 0)
73✔
3087
                                return r;
3088
                } else if ((val = startswith(l, "exec-context-dynamic-user="))) {
923,067✔
3089
                        r = parse_boolean(val);
62✔
3090
                        if (r < 0)
62✔
3091
                                return r;
3092
                        c->dynamic_user = r;
62✔
3093
                } else if ((val = startswith(l, "exec-context-supplementary-groups="))) {
923,005✔
3094
                        r = deserialize_strv(val, &c->supplementary_groups);
9✔
3095
                        if (r < 0)
9✔
3096
                                return r;
3097
                } else if ((val = startswith(l, "exec-context-set-login-environment="))) {
922,996✔
3098
                        r = safe_atoi(val, &c->set_login_environment);
×
3099
                        if (r < 0)
×
3100
                                return r;
3101
                } else if ((val = startswith(l, "exec-context-pam-name="))) {
922,996✔
3102
                        r = free_and_strdup(&c->pam_name, val);
452✔
3103
                        if (r < 0)
452✔
3104
                                return r;
3105
                } else if ((val = startswith(l, "exec-context-read-write-paths="))) {
922,544✔
3106
                        r = deserialize_strv(val, &c->read_write_paths);
790✔
3107
                        if (r < 0)
790✔
3108
                                return r;
3109
                } else if ((val = startswith(l, "exec-context-read-only-paths="))) {
921,754✔
3110
                        r = deserialize_strv(val, &c->read_only_paths);
2✔
3111
                        if (r < 0)
2✔
3112
                                return r;
3113
                } else if ((val = startswith(l, "exec-context-inaccessible-paths="))) {
921,752✔
3114
                        r = deserialize_strv(val, &c->inaccessible_paths);
5✔
3115
                        if (r < 0)
5✔
3116
                                return r;
3117
                } else if ((val = startswith(l, "exec-context-exec-paths="))) {
921,747✔
3118
                        r = deserialize_strv(val, &c->exec_paths);
1✔
3119
                        if (r < 0)
1✔
3120
                                return r;
3121
                } else if ((val = startswith(l, "exec-context-no-exec-paths="))) {
921,746✔
3122
                        r = deserialize_strv(val, &c->no_exec_paths);
1✔
3123
                        if (r < 0)
1✔
3124
                                return r;
3125
                } else if ((val = startswith(l, "exec-context-exec-search-path="))) {
921,745✔
3126
                        r = deserialize_strv(val, &c->exec_search_path);
×
3127
                        if (r < 0)
×
3128
                                return r;
3129
                } else if ((val = startswith(l, "exec-context-mount-propagation-flag="))) {
921,745✔
3130
                        r = safe_atolu(val, &c->mount_propagation_flag);
11,626✔
3131
                        if (r < 0)
11,626✔
3132
                                return r;
3133
                } else if ((val = startswith(l, "exec-context-bind-read-only-path="))) {
910,119✔
3134
                        _cleanup_free_ char *source = NULL, *destination = NULL;
7✔
3135
                        bool rbind = true, ignore_enoent = false;
7✔
3136
                        char *s = NULL, *d = NULL;
7✔
3137

3138
                        r = extract_first_word(&val,
7✔
3139
                                               &source,
3140
                                               ":" WHITESPACE,
3141
                                               EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3142
                        if (r < 0)
7✔
3143
                                return r;
3144
                        if (r == 0)
7✔
3145
                                return -EINVAL;
3146

3147
                        s = source;
7✔
3148
                        if (s[0] == '-') {
7✔
3149
                                ignore_enoent = true;
1✔
3150
                                s++;
1✔
3151
                        }
3152

3153
                        if (val && val[-1] == ':') {
7✔
3154
                                r = extract_first_word(&val,
7✔
3155
                                                       &destination,
3156
                                                       ":" WHITESPACE,
3157
                                                       EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3158
                                if (r < 0)
7✔
3159
                                        return r;
3160
                                if (r == 0)
7✔
3161
                                        continue;
×
3162

3163
                                d = destination;
7✔
3164

3165
                                if (val && val[-1] == ':') {
7✔
3166
                                        _cleanup_free_ char *options = NULL;
7✔
3167

3168
                                        r = extract_first_word(&val, &options, NULL, EXTRACT_UNQUOTE);
7✔
3169
                                        if (r < 0)
7✔
3170
                                                return -r;
×
3171

3172
                                        if (isempty(options) || streq(options, "rbind"))
15✔
3173
                                                rbind = true;
3174
                                        else if (streq(options, "norbind"))
1✔
3175
                                                rbind = false;
3176
                                        else
3177
                                                continue;
×
3178
                                }
3179
                        } else
3180
                                d = s;
3181

3182
                        r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts,
14✔
3183
                                        &(BindMount) {
7✔
3184
                                                .source = s,
3185
                                                .destination = d,
3186
                                                .read_only = true,
3187
                                                .recursive = rbind,
3188
                                                .ignore_enoent = ignore_enoent,
3189
                                        });
3190
                        if (r < 0)
7✔
3191
                                return log_oom_debug();
×
3192
                } else if ((val = startswith(l, "exec-context-bind-path="))) {
910,112✔
3193
                        _cleanup_free_ char *source = NULL, *destination = NULL;
20✔
3194
                        bool rbind = true, ignore_enoent = false;
20✔
3195
                        char *s = NULL, *d = NULL;
20✔
3196

3197
                        r = extract_first_word(&val,
20✔
3198
                                               &source,
3199
                                               ":" WHITESPACE,
3200
                                               EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3201
                        if (r < 0)
20✔
3202
                                return r;
3203
                        if (r == 0)
20✔
3204
                                return -EINVAL;
3205

3206
                        s = source;
20✔
3207
                        if (s[0] == '-') {
20✔
3208
                                ignore_enoent = true;
1✔
3209
                                s++;
1✔
3210
                        }
3211

3212
                        if (val && val[-1] == ':') {
20✔
3213
                                r = extract_first_word(&val,
20✔
3214
                                                       &destination,
3215
                                                       ":" WHITESPACE,
3216
                                                       EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3217
                                if (r < 0)
20✔
3218
                                        return r;
3219
                                if (r == 0)
20✔
3220
                                        continue;
×
3221

3222
                                d = destination;
20✔
3223

3224
                                if (val && val[-1] == ':') {
20✔
3225
                                        _cleanup_free_ char *options = NULL;
20✔
3226

3227
                                        r = extract_first_word(&val, &options, NULL, EXTRACT_UNQUOTE);
20✔
3228
                                        if (r < 0)
20✔
3229
                                                return -r;
×
3230

3231
                                        if (isempty(options) || streq(options, "rbind"))
43✔
3232
                                                rbind = true;
3233
                                        else if (streq(options, "norbind"))
3✔
3234
                                                rbind = false;
3235
                                        else
3236
                                                continue;
×
3237
                                }
3238
                        } else
3239
                                d = s;
3240

3241
                        r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts,
40✔
3242
                                        &(BindMount) {
20✔
3243
                                                .source = s,
3244
                                                .destination = d,
3245
                                                .read_only = false,
3246
                                                .recursive = rbind,
3247
                                                .ignore_enoent = ignore_enoent,
3248
                                        });
3249
                        if (r < 0)
20✔
3250
                                return log_oom_debug();
×
3251
                } else if ((val = startswith(l, "exec-context-temporary-filesystems="))) {
910,092✔
3252
                        _cleanup_free_ char *path = NULL, *options = NULL;
61✔
3253

3254
                        r = extract_many_words(&val, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &path, &options);
61✔
3255
                        if (r < 0)
61✔
3256
                                return r;
3257
                        if (r < 1)
61✔
3258
                                continue;
×
3259

3260
                        r = temporary_filesystem_add(&c->temporary_filesystems, &c->n_temporary_filesystems, path, options);
61✔
3261
                        if (r < 0)
61✔
3262
                                return log_oom_debug();
×
3263
                } else if ((val = startswith(l, "exec-context-utmp-id="))) {
910,031✔
3264
                        r = free_and_strdup(&c->utmp_id, val);
157✔
3265
                        if (r < 0)
157✔
3266
                                return r;
3267
                } else if ((val = startswith(l, "exec-context-utmp-mode="))) {
909,874✔
3268
                        c->utmp_mode = exec_utmp_mode_from_string(val);
11,626✔
3269
                        if (c->utmp_mode < 0)
11,626✔
3270
                                return c->utmp_mode;
3271
                } else if ((val = startswith(l, "exec-context-no-new-privileges="))) {
898,248✔
3272
                        r = parse_boolean(val);
2,161✔
3273
                        if (r < 0)
2,161✔
3274
                                return r;
3275
                        c->no_new_privileges = r;
2,161✔
3276
                } else if ((val = startswith(l, "exec-context-selinux-context="))) {
896,087✔
3277
                        if (val[0] == '-') {
×
3278
                                c->selinux_context_ignore = true;
×
3279
                                val++;
×
3280
                        } else
3281
                                c->selinux_context_ignore = false;
×
3282

3283
                        r = free_and_strdup(&c->selinux_context, val);
×
3284
                        if (r < 0)
×
3285
                                return r;
3286
                } else if ((val = startswith(l, "exec-context-apparmor-profile="))) {
896,087✔
3287
                        if (val[0] == '-') {
×
3288
                                c->apparmor_profile_ignore = true;
×
3289
                                val++;
×
3290
                        } else
3291
                                c->apparmor_profile_ignore = false;
×
3292

3293
                        r = free_and_strdup(&c->apparmor_profile, val);
×
3294
                        if (r < 0)
×
3295
                                return r;
3296
                } else if ((val = startswith(l, "exec-context-smack-process-label="))) {
896,087✔
3297
                        if (val[0] == '-') {
×
3298
                                c->smack_process_label_ignore = true;
×
3299
                                val++;
×
3300
                        } else
3301
                                c->smack_process_label_ignore = false;
×
3302

3303
                        r = free_and_strdup(&c->smack_process_label, val);
×
3304
                        if (r < 0)
×
3305
                                return r;
3306
                } else if ((val = startswith(l, "exec-context-personality="))) {
896,087✔
3307
                        c->personality = personality_from_string(val);
×
3308
                        if (c->personality == PERSONALITY_INVALID)
×
3309
                                return -EINVAL;
3310
                } else if ((val = startswith(l, "exec-context-lock-personality="))) {
896,087✔
3311
                        r = parse_boolean(val);
2,219✔
3312
                        if (r < 0)
2,219✔
3313
                                return r;
3314
                        c->lock_personality = r;
2,219✔
3315
#if HAVE_SECCOMP
3316
                } else if ((val = startswith(l, "exec-context-syscall-filter="))) {
893,868✔
3317
                        _cleanup_free_ char *s_id = NULL, *s_errno_num = NULL;
856,885✔
3318
                        int id, errno_num;
856,885✔
3319

3320
                        r = extract_many_words(&val, NULL, 0, &s_id, &s_errno_num);
856,885✔
3321
                        if (r < 0)
856,885✔
3322
                                return r;
3323
                        if (r != 2)
856,885✔
3324
                                continue;
×
3325

3326
                        r = safe_atoi(s_id, &id);
856,885✔
3327
                        if (r < 0)
856,885✔
3328
                                return r;
3329

3330
                        r = safe_atoi(s_errno_num, &errno_num);
856,885✔
3331
                        if (r < 0)
856,885✔
3332
                                return r;
3333

3334
                        r = hashmap_ensure_put(&c->syscall_filter, NULL, INT_TO_PTR(id + 1), INT_TO_PTR(errno_num));
856,885✔
3335
                        if (r < 0)
856,885✔
3336
                                return r;
3337
                } else if ((val = startswith(l, "exec-context-syscall-archs="))) {
36,983✔
3338
                        unsigned id;
2,219✔
3339

3340
                        r = safe_atou(val, &id);
2,219✔
3341
                        if (r < 0)
2,219✔
3342
                                return r;
×
3343

3344
                        r = set_ensure_put(&c->syscall_archs, NULL, UINT_TO_PTR(id + 1));
2,219✔
3345
                        if (r < 0)
2,219✔
3346
                                return r;
3347
                } else if ((val = startswith(l, "exec-context-syscall-errno="))) {
34,764✔
3348
                        r = safe_atoi(val, &c->syscall_errno);
11,626✔
3349
                        if (r < 0)
11,626✔
3350
                                return r;
3351
                } else if ((val = startswith(l, "exec-context-syscall-allow-list="))) {
23,138✔
3352
                        r = parse_boolean(val);
2,201✔
3353
                        if (r < 0)
2,201✔
3354
                                return r;
3355
                        c->syscall_allow_list = r;
2,201✔
3356
                } else if ((val = startswith(l, "exec-context-syscall-log="))) {
20,937✔
3357
                        _cleanup_free_ char *s_id = NULL, *s_errno_num = NULL;
×
3358
                        int id, errno_num;
×
3359

3360
                        r = extract_many_words(&val, " ", 0, &s_id, &s_errno_num);
×
3361
                        if (r < 0)
×
3362
                                return r;
3363
                        if (r != 2)
×
3364
                                continue;
×
3365

3366
                        r = safe_atoi(s_id, &id);
×
3367
                        if (r < 0)
×
3368
                                return r;
3369

3370
                        r = safe_atoi(s_errno_num, &errno_num);
×
3371
                        if (r < 0)
×
3372
                                return r;
3373

3374
                        r = hashmap_ensure_put(&c->syscall_log, NULL, INT_TO_PTR(id + 1), INT_TO_PTR(errno_num));
×
3375
                        if (r < 0)
×
3376
                                return r;
3377
                } else if ((val = startswith(l, "exec-context-syscall-log-allow-list="))) {
20,937✔
3378
                        r = parse_boolean(val);
×
3379
                        if (r < 0)
×
3380
                                return r;
3381
                        c->syscall_log_allow_list = r;
×
3382
#endif
3383
                } else if ((val = startswith(l, "exec-context-restrict-namespaces="))) {
20,937✔
3384
                        r = safe_atolu(val, &c->restrict_namespaces);
1,962✔
3385
                        if (r < 0)
1,962✔
3386
                                return r;
3387
                } else if ((val = startswith(l, "exec-context-delegate-namespaces="))) {
18,975✔
3388
                        r = safe_atolu(val, &c->delegate_namespaces);
12✔
3389
                        if (r < 0)
12✔
3390
                                return r;
3391
                } else if ((val = startswith(l, "exec-context-restrict-filesystems="))) {
18,963✔
3392
                        r = set_put_strdup(&c->restrict_filesystems, val);
×
3393
                        if (r < 0)
×
3394
                                return r;
3395
                } else if ((val = startswith(l, "exec-context-restrict-filesystems-allow-list="))) {
18,963✔
3396
                        r = parse_boolean(val);
×
3397
                        if (r < 0)
×
3398
                                return r;
3399
                        c->restrict_filesystems_allow_list = r;
×
3400
                } else if ((val = startswith(l, "exec-context-address-families="))) {
18,963✔
3401
                        int af;
9,260✔
3402

3403
                        r = safe_atoi(val, &af);
9,260✔
3404
                        if (r < 0)
9,260✔
3405
                                return r;
×
3406

3407
                        r = set_ensure_put(&c->address_families, NULL, INT_TO_PTR(af));
9,260✔
3408
                        if (r < 0)
9,260✔
3409
                                return r;
3410
                } else if ((val = startswith(l, "exec-context-address-families-allow-list="))) {
9,703✔
3411
                        r = parse_boolean(val);
2,216✔
3412
                        if (r < 0)
2,216✔
3413
                                return r;
3414
                        c->address_families_allow_list = r;
2,216✔
3415
                } else if ((val = startswith(l, "exec-context-network-namespace-path="))) {
7,487✔
3416
                        r = free_and_strdup(&c->network_namespace_path, val);
×
3417
                        if (r < 0)
×
3418
                                return r;
3419
                } else if ((val = startswith(l, "exec-context-ipc-namespace-path="))) {
7,487✔
3420
                        r = free_and_strdup(&c->ipc_namespace_path, val);
×
3421
                        if (r < 0)
×
3422
                                return r;
3423
                } else if ((val = startswith(l, "exec-context-mount-image="))) {
7,487✔
3424
                        _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
×
3425
                        _cleanup_free_ char *source = NULL, *destination = NULL;
46✔
3426
                        bool permissive = false;
46✔
3427
                        char *s;
46✔
3428

3429
                        r = extract_many_words(&val,
46✔
3430
                                               NULL,
3431
                                               EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS,
3432
                                               &source,
3433
                                               &destination);
3434
                        if (r < 0)
46✔
3435
                                return r;
3436
                        if (r == 0)
46✔
3437
                                return -EINVAL;
3438

3439
                        s = source;
46✔
3440
                        if (s[0] == '-') {
46✔
3441
                                permissive = true;
×
3442
                                s++;
×
3443
                        }
3444

3445
                        if (isempty(destination))
46✔
3446
                                continue;
×
3447

3448
                        for (;;) {
51✔
3449
                                _cleanup_free_ char *tuple = NULL, *partition = NULL, *opts = NULL;
5✔
3450
                                PartitionDesignator partition_designator;
51✔
3451
                                MountOptions *o = NULL;
51✔
3452
                                const char *p;
51✔
3453

3454
                                r = extract_first_word(&val, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
51✔
3455
                                if (r < 0)
51✔
3456
                                        return r;
3457
                                if (r == 0)
51✔
3458
                                        break;
3459

3460
                                p = tuple;
5✔
3461
                                r = extract_many_words(&p,
5✔
3462
                                                       ":",
3463
                                                       EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS,
3464
                                                       &partition,
3465
                                                       &opts);
3466
                                if (r < 0)
5✔
3467
                                        return r;
3468
                                if (r == 0)
5✔
3469
                                        continue;
×
3470
                                if (r == 1) {
5✔
3471
                                        o = new(MountOptions, 1);
×
3472
                                        if (!o)
×
3473
                                                return log_oom_debug();
×
3474
                                        *o = (MountOptions) {
×
3475
                                                .partition_designator = PARTITION_ROOT,
3476
                                                .options = TAKE_PTR(partition),
×
3477
                                        };
3478
                                        LIST_APPEND(mount_options, options, o);
×
3479

3480
                                        continue;
×
3481
                                }
3482

3483
                                partition_designator = partition_designator_from_string(partition);
5✔
3484
                                if (partition_designator < 0)
5✔
3485
                                        continue;
×
3486

3487
                                o = new(MountOptions, 1);
5✔
3488
                                if (!o)
5✔
3489
                                        return log_oom_debug();
×
3490
                                *o = (MountOptions) {
5✔
3491
                                        .partition_designator = partition_designator,
3492
                                        .options = TAKE_PTR(opts),
5✔
3493
                                };
3494
                                LIST_APPEND(mount_options, options, o);
5✔
3495
                        }
3496

3497
                        r = mount_image_add(&c->mount_images, &c->n_mount_images,
92✔
3498
                                        &(MountImage) {
46✔
3499
                                                .source = s,
3500
                                                .destination = destination,
3501
                                                .mount_options = options,
3502
                                                .ignore_enoent = permissive,
3503
                                                .type = MOUNT_IMAGE_DISCRETE,
3504
                                        });
3505
                        if (r < 0)
46✔
3506
                                return log_oom_debug();
×
3507
                } else if ((val = startswith(l, "exec-context-extension-image="))) {
7,441✔
3508
                        _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
×
3509
                        _cleanup_free_ char *source = NULL;
9✔
3510
                        bool permissive = false;
9✔
3511
                        char *s;
9✔
3512

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

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

3528
                        for (;;) {
9✔
3529
                                _cleanup_free_ char *tuple = NULL, *partition = NULL, *opts = NULL;
×
3530
                                PartitionDesignator partition_designator;
9✔
3531
                                MountOptions *o = NULL;
9✔
3532
                                const char *p;
9✔
3533

3534
                                r = extract_first_word(&val, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
9✔
3535
                                if (r < 0)
9✔
3536
                                        return r;
3537
                                if (r == 0)
9✔
3538
                                        break;
3539

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

3560
                                        continue;
×
3561
                                }
3562

3563
                                partition_designator = partition_designator_from_string(partition);
×
3564
                                if (partition_designator < 0)
×
3565
                                        continue;
×
3566

3567
                                o = new(MountOptions, 1);
×
3568
                                if (!o)
×
3569
                                        return log_oom_debug();
×
3570
                                *o = (MountOptions) {
×
3571
                                        .partition_designator = partition_designator,
3572
                                        .options = TAKE_PTR(opts),
×
3573
                                };
3574
                                LIST_APPEND(mount_options, options, o);
×
3575
                        }
3576

3577
                        r = mount_image_add(&c->extension_images, &c->n_extension_images,
18✔
3578
                                        &(MountImage) {
9✔
3579
                                                .source = s,
3580
                                                .mount_options = options,
3581
                                                .ignore_enoent = permissive,
3582
                                                .type = MOUNT_IMAGE_EXTENSION,
3583
                                        });
3584
                        if (r < 0)
9✔
3585
                                return log_oom_debug();
×
3586
                } else if ((val = startswith(l, "exec-context-extension-directories="))) {
7,432✔
3587
                        r = deserialize_strv(val, &c->extension_directories);
8✔
3588
                        if (r < 0)
8✔
3589
                                return r;
3590
                } else if ((val = startswith(l, "exec-context-set-credentials="))) {
7,424✔
3591
                        _cleanup_free_ char *id = NULL, *data = NULL, *encrypted = NULL;
×
3592

3593
                        r = extract_many_words(&val, " ", EXTRACT_DONT_COALESCE_SEPARATORS, &id, &data, &encrypted);
182✔
3594
                        if (r < 0)
182✔
3595
                                return r;
3596
                        if (r != 3)
182✔
3597
                                return -EINVAL;
3598

3599
                        r = parse_boolean(encrypted);
182✔
3600
                        if (r < 0)
182✔
3601
                                return r;
3602
                        bool e = r;
182✔
3603

3604
                        _cleanup_free_ void *d = NULL;
182✔
3605
                        size_t size;
182✔
3606

3607
                        r = unbase64mem_full(data, SIZE_MAX, /* secure = */ true, &d, &size);
182✔
3608
                        if (r < 0)
182✔
3609
                                return r;
3610

3611
                        r = exec_context_put_set_credential(c, id, TAKE_PTR(d), size, e);
182✔
3612
                        if (r < 0)
182✔
3613
                                return r;
3614
                } else if ((val = startswith(l, "exec-context-load-credentials="))) {
7,242✔
3615
                        _cleanup_free_ char *id = NULL, *path = NULL, *encrypted = NULL;
71✔
3616

3617
                        r = extract_many_words(&val, " ", EXTRACT_DONT_COALESCE_SEPARATORS, &id, &path, &encrypted);
71✔
3618
                        if (r < 0)
71✔
3619
                                return r;
3620
                        if (r != 3)
71✔
3621
                                return -EINVAL;
3622

3623
                        r = parse_boolean(encrypted);
71✔
3624
                        if (r < 0)
71✔
3625
                                return r;
3626

3627
                        r = exec_context_put_load_credential(c, id, path, r > 0);
71✔
3628
                        if (r < 0)
71✔
3629
                                return r;
3630
                } else if ((val = startswith(l, "exec-context-import-credentials="))) {
7,171✔
3631
                        _cleanup_free_ char *glob = NULL, *rename = NULL;
7,167✔
3632

3633
                        r = extract_many_words(&val, " ", EXTRACT_DONT_COALESCE_SEPARATORS, &glob, &rename);
7,167✔
3634
                        if (r < 0)
7,167✔
3635
                                return r;
3636
                        if (r == 0)
7,167✔
3637
                                return -EINVAL;
3638

3639
                        r = exec_context_put_import_credential(c, glob, rename);
7,167✔
3640
                        if (r < 0)
7,167✔
3641
                                return r;
3642
                } else if ((val = startswith(l, "exec-context-root-image-policy="))) {
4✔
3643
                        if (c->root_image_policy)
4✔
3644
                                return -EINVAL; /* duplicated */
3645

3646
                        r = image_policy_from_string(val, &c->root_image_policy);
4✔
3647
                        if (r < 0)
4✔
3648
                                return r;
3649
                } else if ((val = startswith(l, "exec-context-mount-image-policy="))) {
×
3650
                        if (c->mount_image_policy)
×
3651
                                return -EINVAL; /* duplicated */
3652

3653
                        r = image_policy_from_string(val, &c->mount_image_policy);
×
3654
                        if (r < 0)
×
3655
                                return r;
3656
                } else if ((val = startswith(l, "exec-context-extension-image-policy="))) {
×
3657
                        if (c->extension_image_policy)
×
3658
                                return -EINVAL; /* duplicated */
3659

3660
                        r = image_policy_from_string(val, &c->extension_image_policy);
×
3661
                        if (r < 0)
×
3662
                                return r;
3663
                } else
3664
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
3665
        }
3666

3667
        return 0;
11,626✔
3668
}
3669

3670
static int exec_command_serialize(const ExecCommand *c, FILE *f) {
2,230✔
3671
        int r;
2,230✔
3672

3673
        assert(c);
2,230✔
3674
        assert(f);
2,230✔
3675

3676
        r = serialize_item(f, "exec-command-path", c->path);
2,230✔
3677
        if (r < 0)
2,230✔
3678
                return r;
3679

3680
        r = serialize_strv(f, "exec-command-argv", c->argv);
2,230✔
3681
        if (r < 0)
2,230✔
3682
                return r;
3683

3684
        r = serialize_item_format(f, "exec-command-flags", "%d", (int) c->flags);
2,230✔
3685
        if (r < 0)
2,230✔
3686
                return r;
3687

3688
        fputc('\n', f); /* End marker */
2,230✔
3689

3690
        return 0;
2,230✔
3691
}
3692

3693
static int exec_command_deserialize(ExecCommand *c, FILE *f) {
11,626✔
3694
        int r;
11,626✔
3695

3696
        assert(c);
11,626✔
3697
        assert(f);
11,626✔
3698

3699
        for (;;) {
124,380✔
3700
                _cleanup_free_ char *l = NULL;
56,377✔
3701
                const char *val;
68,003✔
3702

3703
                r = deserialize_read_line(f, &l);
68,003✔
3704
                if (r < 0)
68,003✔
3705
                        return r;
3706
                if (r == 0) /* eof or end marker */
68,003✔
3707
                        break;
3708

3709
                if ((val = startswith(l, "exec-command-path="))) {
56,377✔
3710
                        r = free_and_strdup(&c->path, val);
11,626✔
3711
                        if (r < 0)
11,626✔
3712
                                return r;
3713
                } else if ((val = startswith(l, "exec-command-argv="))) {
44,751✔
3714
                        r = deserialize_strv(val, &c->argv);
33,125✔
3715
                        if (r < 0)
33,125✔
3716
                                return r;
3717
                } else if ((val = startswith(l, "exec-command-flags="))) {
11,626✔
3718
                        r = safe_atoi(val, &c->flags);
11,626✔
3719
                        if (r < 0)
11,626✔
3720
                                return r;
3721
                } else
3722
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
3723

3724
        }
3725

3726
        return 0;
11,626✔
3727
}
3728

3729
int exec_serialize_invocation(
2,230✔
3730
                FILE *f,
3731
                FDSet *fds,
3732
                const ExecContext *ctx,
3733
                const ExecCommand *cmd,
3734
                const ExecParameters *p,
3735
                const ExecRuntime *rt,
3736
                const CGroupContext *cg) {
3737

3738
        int r;
2,230✔
3739

3740
        assert(f);
2,230✔
3741
        assert(fds);
2,230✔
3742

3743
        r = exec_context_serialize(ctx, f);
2,230✔
3744
        if (r < 0)
2,230✔
3745
                return log_debug_errno(r, "Failed to serialize context: %m");
×
3746

3747
        r = exec_command_serialize(cmd, f);
2,230✔
3748
        if (r < 0)
2,230✔
3749
                return log_debug_errno(r, "Failed to serialize command: %m");
×
3750

3751
        r = exec_parameters_serialize(p, ctx, f, fds);
2,230✔
3752
        if (r < 0)
2,230✔
3753
                return log_debug_errno(r, "Failed to serialize parameters: %m");
×
3754

3755
        r = exec_runtime_serialize(rt, f, fds);
2,230✔
3756
        if (r < 0)
2,230✔
3757
                return log_debug_errno(r, "Failed to serialize runtime: %m");
×
3758

3759
        r = exec_cgroup_context_serialize(cg, f);
2,230✔
3760
        if (r < 0)
2,230✔
3761
                return log_debug_errno(r, "Failed to serialize cgroup context: %m");
×
3762

3763
        return 0;
3764
}
3765

3766
int exec_deserialize_invocation(
11,626✔
3767
                FILE *f,
3768
                FDSet *fds,
3769
                ExecContext *ctx,
3770
                ExecCommand *cmd,
3771
                ExecParameters *p,
3772
                ExecRuntime *rt,
3773
                CGroupContext *cg) {
3774

3775
        int r;
11,626✔
3776

3777
        assert(f);
11,626✔
3778
        assert(fds);
11,626✔
3779

3780
        r = exec_context_deserialize(ctx, f);
11,626✔
3781
        if (r < 0)
11,626✔
3782
                return log_debug_errno(r, "Failed to deserialize context: %m");
×
3783

3784
        r = exec_command_deserialize(cmd, f);
11,626✔
3785
        if (r < 0)
11,626✔
3786
                return log_debug_errno(r, "Failed to deserialize command: %m");
×
3787

3788
        r = exec_parameters_deserialize(p, f, fds);
11,626✔
3789
        if (r < 0)
11,626✔
3790
                return log_debug_errno(r, "Failed to deserialize parameters: %m");
×
3791

3792
        r = exec_runtime_deserialize(rt, f, fds);
11,626✔
3793
        if (r < 0)
11,626✔
3794
                return log_debug_errno(r, "Failed to deserialize runtime: %m");
×
3795

3796
        r = exec_cgroup_context_deserialize(cg, f);
11,626✔
3797
        if (r < 0)
11,626✔
3798
                return log_debug_errno(r, "Failed to deserialize cgroup context: %m");
×
3799

3800
        return 0;
3801
}
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