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

systemd / systemd / 21572936961

01 Feb 2026 08:26PM UTC coverage: 72.759% (-0.05%) from 72.813%
21572936961

push

github

yuwata
po: Translated using Weblate (Greek)

Currently translated at 35.9% (95 of 264 strings)

Co-authored-by: Jim Spentzos <jimspentzos2000@gmail.com>
Translate-URL: https://translate.fedoraproject.org/projects/systemd/main/el/
Translation: systemd/main

311274 of 427817 relevant lines covered (72.76%)

1131788.47 hits per line

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

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

3
#include <unistd.h>
4

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

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

42
        assert(f);
2,461✔
43

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

153
        if (c->memory_high != CGROUP_LIMIT_MAX) {
2,461✔
154
                r = serialize_item_format(f, "exec-cgroup-context-memory-high", "%" PRIu64, c->memory_high);
2✔
155
                if (r < 0)
2✔
156
                        return r;
157
        }
158

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

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

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

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

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

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

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

201
        r = serialize_bool(f, "exec-cgroup-context-memory-zswap-writeback", c->memory_zswap_writeback);
2,461✔
202
        if (r < 0)
2,461✔
203
                return r;
204

205
        if (c->tasks_max.value != UINT64_MAX) {
2,461✔
206
                r = serialize_item_format(f, "exec-cgroup-context-tasks-max-value", "%" PRIu64, c->tasks_max.value);
2,409✔
207
                if (r < 0)
2,409✔
208
                        return r;
209
        }
210

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

217
        r = serialize_bool_elide(f, "exec-cgroup-context-startup-memory-low-set", c->startup_memory_low_set);
2,461✔
218
        if (r < 0)
2,461✔
219
                return r;
220

221
        r = serialize_bool_elide(f, "exec-cgroup-context-startup-memory-high-set", c->startup_memory_high_set);
2,461✔
222
        if (r < 0)
2,461✔
223
                return r;
224

225
        r = serialize_bool_elide(f, "exec-cgroup-context-startup-memory-max-set", c->startup_memory_max_set);
2,461✔
226
        if (r < 0)
2,461✔
227
                return r;
228

229
        r = serialize_bool_elide(f, "exec-cgroup-context-startup-memory-swap-max-set", c->startup_memory_swap_max_set);
2,461✔
230
        if (r < 0)
2,461✔
231
                return r;
232

233
        r = serialize_bool_elide(f, "exec-cgroup-context-startup-memory-zswap-max-set", c->startup_memory_zswap_max_set);
2,461✔
234
        if (r < 0)
2,461✔
235
                return r;
236

237
        r = serialize_item(f, "exec-cgroup-context-device-policy", cgroup_device_policy_to_string(c->device_policy));
2,461✔
238
        if (r < 0)
2,461✔
239
                return r;
240

241
        r = cg_mask_to_string(c->disable_controllers, &disable_controllers_str);
2,461✔
242
        if (r < 0)
2,461✔
243
                return r;
244

245
        r = serialize_item(f, "exec-cgroup-context-disable-controllers", disable_controllers_str);
2,461✔
246
        if (r < 0)
2,461✔
247
                return r;
248

249
        r = cg_mask_to_string(c->delegate_controllers, &delegate_controllers_str);
2,461✔
250
        if (r < 0)
2,461✔
251
                return r;
252

253
        r = serialize_item(f, "exec-cgroup-context-delegate-controllers", delegate_controllers_str);
2,461✔
254
        if (r < 0)
2,461✔
255
                return r;
256

257
        r = serialize_bool_elide(f, "exec-cgroup-context-delegate", c->delegate);
2,461✔
258
        if (r < 0)
2,461✔
259
                return r;
260

261
        r = serialize_item(f, "exec-cgroup-context-managed-oom-swap", managed_oom_mode_to_string(c->moom_swap));
2,461✔
262
        if (r < 0)
2,461✔
263
                return r;
264

265
        r = serialize_item(f, "exec-cgroup-context-managed-oom-memory-pressure", managed_oom_mode_to_string(c->moom_mem_pressure));
2,461✔
266
        if (r < 0)
2,461✔
267
                return r;
268

269
        r = serialize_item_format(f, "exec-cgroup-context-managed-oom-memory-pressure-limit", "%" PRIu32, c->moom_mem_pressure_limit);
2,461✔
270
        if (r < 0)
2,461✔
271
                return r;
272

273
        r = serialize_usec(f, "exec-cgroup-context-managed-oom-memory-pressure-duration-usec", c->moom_mem_pressure_duration_usec);
2,461✔
274
        if (r < 0)
2,461✔
275
                return r;
276

277
        r = serialize_item(f, "exec-cgroup-context-managed-oom-preference", managed_oom_preference_to_string(c->moom_preference));
2,461✔
278
        if (r < 0)
2,461✔
279
                return r;
280

281
        r = serialize_item(f, "exec-cgroup-context-memory-pressure-watch", cgroup_pressure_watch_to_string(c->memory_pressure_watch));
2,461✔
282
        if (r < 0)
2,461✔
283
                return r;
284

285
        r = serialize_item(f, "exec-cgroup-context-delegate-subgroup", c->delegate_subgroup);
2,461✔
286
        if (r < 0)
2,461✔
287
                return r;
288

289
        if (c->memory_pressure_threshold_usec != USEC_INFINITY) {
2,461✔
290
                r = serialize_usec(f, "exec-cgroup-context-memory-pressure-threshold-usec", c->memory_pressure_threshold_usec);
2,461✔
291
                if (r < 0)
2,461✔
292
                        return r;
293
        }
294

295
        LIST_FOREACH(device_allow, a, c->device_allow) {
3,144✔
296
                r = serialize_item_format(f, "exec-cgroup-context-device-allow", "%s %s",
683✔
297
                                          a->path,
298
                                          cgroup_device_permissions_to_string(a->permissions));
299
                if (r < 0)
683✔
300
                        return r;
301
        }
302

303
        LIST_FOREACH(device_weights, iw, c->io_device_weights) {
2,461✔
304
                r = serialize_item_format(f, "exec-cgroup-context-io-device-weight", "%s %" PRIu64,
×
305
                                          iw->path,
306
                                          iw->weight);
307
                if (r < 0)
×
308
                        return r;
309
        }
310

311
        LIST_FOREACH(device_latencies, l, c->io_device_latencies) {
2,461✔
312
                r = serialize_item_format(f, "exec-cgroup-context-io-device-latency-target-usec", "%s " USEC_FMT,
×
313
                                          l->path,
314
                                          l->target_usec);
315
                if (r < 0)
×
316
                        return r;
317
        }
318

319
        LIST_FOREACH(device_limits, il, c->io_device_limits)
2,461✔
320
                for (CGroupIOLimitType type = 0; type < _CGROUP_IO_LIMIT_TYPE_MAX; type++) {
×
321
                        _cleanup_free_ char *key = NULL;
×
322

323
                        if (il->limits[type] == cgroup_io_limit_defaults[type])
×
324
                                continue;
×
325

326
                        key = strjoin("exec-cgroup-context-io-device-limit-", cgroup_io_limit_type_to_string(type));
×
327
                        if (!key)
×
328
                                return -ENOMEM;
329

330
                        r = serialize_item_format(f, key, "%s %" PRIu64, il->path, il->limits[type]);
×
331
                        if (r < 0)
×
332
                                return r;
333
                }
334

335
        SET_FOREACH(iaai, c->ip_address_allow) {
2,461✔
336
                r = serialize_item(f,
×
337
                                   "exec-cgroup-context-ip-address-allow",
338
                                   IN_ADDR_PREFIX_TO_STRING(iaai->family, &iaai->address, iaai->prefixlen));
×
339
                if (r < 0)
×
340
                        return r;
×
341
        }
342
        SET_FOREACH(iaai, c->ip_address_deny) {
2,733✔
343
                r = serialize_item(f,
272✔
344
                                   "exec-cgroup-context-ip-address-deny",
345
                                   IN_ADDR_PREFIX_TO_STRING(iaai->family, &iaai->address, iaai->prefixlen));
272✔
346
                if (r < 0)
272✔
347
                        return r;
×
348
        }
349

350
        r = serialize_bool_elide(f, "exec-cgroup-context-ip-address-allow-reduced", c->ip_address_allow_reduced);
2,461✔
351
        if (r < 0)
2,461✔
352
                return r;
353

354
        r = serialize_bool_elide(f, "exec-cgroup-context-ip-address-deny-reduced", c->ip_address_deny_reduced);
2,461✔
355
        if (r < 0)
2,461✔
356
                return r;
357

358
        r = serialize_strv(f, "exec-cgroup-context-ip-ingress-filter-path", c->ip_filters_ingress);
2,461✔
359
        if (r < 0)
2,461✔
360
                return r;
361

362
        r = serialize_strv(f, "exec-cgroup-context-ip-egress-filter-path", c->ip_filters_egress);
2,461✔
363
        if (r < 0)
2,461✔
364
                return r;
365

366
        LIST_FOREACH(programs, p, c->bpf_foreign_programs) {
2,461✔
367
                r = serialize_item_format(f, "exec-cgroup-context-bpf-program", "%" PRIu32 " %s",
×
368
                                          p->attach_type,
369
                                          p->bpffs_path);
370
                if (r < 0)
×
371
                        return r;
372
        }
373

374
        LIST_FOREACH(socket_bind_items, bi, c->socket_bind_allow) {
2,461✔
375
                fprintf(f, "exec-cgroup-context-socket-bind-allow=");
×
376
                cgroup_context_dump_socket_bind_item(bi, f);
×
377
                fputc('\n', f);
×
378
        }
379

380
        LIST_FOREACH(socket_bind_items, bi, c->socket_bind_deny) {
2,461✔
381
                fprintf(f, "exec-cgroup-context-socket-bind-deny=");
×
382
                cgroup_context_dump_socket_bind_item(bi, f);
×
383
                fputc('\n', f);
×
384
        }
385

386
        SET_FOREACH(iface, c->restrict_network_interfaces) {
2,461✔
387
                r = serialize_item(f, "exec-cgroup-context-restrict-network-interfaces", iface);
×
388
                if (r < 0)
×
389
                        return r;
×
390
        }
391

392
        r = serialize_bool_elide(
4,922✔
393
                        f,
394
                        "exec-cgroup-context-restrict-network-interfaces-is-allow-list",
395
                        c->restrict_network_interfaces_is_allow_list);
2,461✔
396
        if (r < 0)
2,461✔
397
                return r;
398

399
        r = serialize_item(f, "exec-cgroup-context-bind-iface", c->bind_network_interface);
2,461✔
400
        if (r < 0)
2,461✔
401
                return r;
402

403
        fputc('\n', f); /* End marker */
2,461✔
404

405
        return 0;
406
}
407

408
static int exec_cgroup_context_deserialize(CGroupContext *c, FILE *f) {
10,009✔
409
        int r;
10,009✔
410

411
        assert(f);
10,009✔
412

413
        if (!c)
10,009✔
414
                return 0;
415

416
        for (;;) {
373,403✔
417
                _cleanup_free_ char *l = NULL;
181,697✔
418
                const char *val;
191,706✔
419

420
                r = deserialize_read_line(f, &l);
191,706✔
421
                if (r < 0)
191,706✔
422
                        return r;
423
                if (r == 0) /* eof or end marker */
191,706✔
424
                        break;
425

426
                if ((val = startswith(l, "exec-cgroup-context-io-accounting="))) {
181,697✔
427
                        r = parse_boolean(val);
2✔
428
                        if (r < 0)
2✔
429
                                return r;
430
                        c->io_accounting = r;
2✔
431
                } else if ((val = startswith(l, "exec-cgroup-context-memory-accounting="))) {
181,695✔
432
                        r = parse_boolean(val);
9,689✔
433
                        if (r < 0)
9,689✔
434
                                return r;
435
                        c->memory_accounting = r;
9,689✔
436
                } else if ((val = startswith(l, "exec-cgroup-context-tasks-accounting="))) {
172,006✔
437
                        r = parse_boolean(val);
10,009✔
438
                        if (r < 0)
10,009✔
439
                                return r;
440
                        c->tasks_accounting = r;
10,009✔
441
                } else if ((val = startswith(l, "exec-cgroup-context-ip-accounting="))) {
161,997✔
442
                        r = parse_boolean(val);
×
443
                        if (r < 0)
×
444
                                return r;
445
                        c->ip_accounting = r;
×
446
                } else if ((val = startswith(l, "exec-cgroup-context-memory-oom-group="))) {
161,997✔
447
                        r = parse_boolean(val);
2✔
448
                        if (r < 0)
2✔
449
                                return r;
450
                        c->memory_oom_group = r;
2✔
451
                } else if ((val = startswith(l, "exec-cgroup-context-cpu-weight="))) {
161,995✔
452
                        r = safe_atou64(val, &c->cpu_weight);
1✔
453
                        if (r < 0)
1✔
454
                                return r;
455
                } else if ((val = startswith(l, "exec-cgroup-context-startup-cpu-weight="))) {
161,994✔
456
                        r = safe_atou64(val, &c->startup_cpu_weight);
×
457
                        if (r < 0)
×
458
                                return r;
459
                } else if ((val = startswith(l, "exec-cgroup-context-cpu-quota-per-sec-usec="))) {
161,994✔
460
                        r = deserialize_usec(val, &c->cpu_quota_per_sec_usec);
×
461
                        if (r < 0)
×
462
                                return r;
463
                } else if ((val = startswith(l, "exec-cgroup-context-cpu-quota-period-usec="))) {
161,994✔
464
                        r = deserialize_usec(val, &c->cpu_quota_period_usec);
×
465
                        if (r < 0)
×
466
                                return r;
467
                } else if ((val = startswith(l, "exec-cgroup-context-allowed-cpus="))) {
161,994✔
468
                        if (c->cpuset_cpus.set)
10,009✔
469
                                return -EINVAL; /* duplicated */
470

471
                        r = parse_cpu_set(val, &c->cpuset_cpus);
10,009✔
472
                        if (r < 0)
10,009✔
473
                                return r;
474
                } else if ((val = startswith(l, "exec-cgroup-context-startup-allowed-cpus="))) {
151,985✔
475
                        if (c->startup_cpuset_cpus.set)
10,009✔
476
                                return -EINVAL; /* duplicated */
477

478
                        r = parse_cpu_set(val, &c->startup_cpuset_cpus);
10,009✔
479
                        if (r < 0)
10,009✔
480
                                return r;
481
                } else if ((val = startswith(l, "exec-cgroup-context-allowed-memory-nodes="))) {
141,976✔
482
                        if (c->cpuset_mems.set)
10,009✔
483
                                return -EINVAL; /* duplicated */
484

485
                        r = parse_cpu_set(val, &c->cpuset_mems);
10,009✔
486
                        if (r < 0)
10,009✔
487
                                return r;
488
                } else if ((val = startswith(l, "exec-cgroup-context-startup-allowed-memory-nodes="))) {
131,967✔
489
                        if (c->startup_cpuset_mems.set)
10,009✔
490
                                return -EINVAL; /* duplicated */
491

492
                        r = parse_cpu_set(val, &c->startup_cpuset_mems);
10,009✔
493
                        if (r < 0)
10,009✔
494
                                return r;
495
                } else if ((val = startswith(l, "exec-cgroup-context-io-weight="))) {
121,958✔
496
                        r = safe_atou64(val, &c->io_weight);
×
497
                        if (r < 0)
×
498
                                return r;
499
                } else if ((val = startswith(l, "exec-cgroup-context-startup-io-weight="))) {
121,958✔
500
                        r = safe_atou64(val, &c->startup_io_weight);
×
501
                        if (r < 0)
×
502
                                return r;
503
                } else if ((val = startswith(l, "exec-cgroup-context-memory-min="))) {
121,958✔
504
                        r = safe_atou64(val, &c->memory_min);
1✔
505
                        if (r < 0)
1✔
506
                                return r;
507
                } else if ((val = startswith(l, "exec-cgroup-context-memory-low="))) {
121,957✔
508
                        r = safe_atou64(val, &c->memory_low);
1✔
509
                        if (r < 0)
1✔
510
                                return r;
511
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-low="))) {
121,956✔
512
                        r = safe_atou64(val, &c->startup_memory_low);
×
513
                        if (r < 0)
×
514
                                return r;
515
                } else if ((val = startswith(l, "exec-cgroup-context-memory-high="))) {
121,956✔
516
                        r = safe_atou64(val, &c->memory_high);
10✔
517
                        if (r < 0)
10✔
518
                                return r;
519
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-high="))) {
121,946✔
520
                        r = safe_atou64(val, &c->startup_memory_high);
×
521
                        if (r < 0)
×
522
                                return r;
523
                } else if ((val = startswith(l, "exec-cgroup-context-memory-max="))) {
121,946✔
524
                        r = safe_atou64(val, &c->memory_max);
11✔
525
                        if (r < 0)
11✔
526
                                return r;
527
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-max="))) {
121,935✔
528
                        r = safe_atou64(val, &c->startup_memory_max);
×
529
                        if (r < 0)
×
530
                                return r;
531
                } else if ((val = startswith(l, "exec-cgroup-context-memory-swap-max="))) {
121,935✔
532
                        r = safe_atou64(val, &c->memory_swap_max);
10✔
533
                        if (r < 0)
10✔
534
                                return r;
535
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-swap-max="))) {
121,925✔
536
                        r = safe_atou64(val, &c->startup_memory_swap_max);
×
537
                        if (r < 0)
×
538
                                return r;
539
                } else if ((val = startswith(l, "exec-cgroup-context-memory-zswap-max="))) {
121,925✔
540
                        r = safe_atou64(val, &c->memory_zswap_max);
1✔
541
                        if (r < 0)
1✔
542
                                return r;
543
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-zswap-max="))) {
121,924✔
544
                        r = safe_atou64(val, &c->startup_memory_zswap_max);
×
545
                        if (r < 0)
×
546
                                return r;
547
                } else if ((val = startswith(l, "exec-cgroup-context-memory-zswap-writeback="))) {
121,924✔
548
                        r = parse_boolean(val);
10,009✔
549
                        if (r < 0)
10,009✔
550
                                return r;
551
                        c->memory_zswap_writeback = r;
10,009✔
552
                } else if ((val = startswith(l, "exec-cgroup-context-tasks-max-value="))) {
111,915✔
553
                        r = safe_atou64(val, &c->tasks_max.value);
9,709✔
554
                        if (r < 0)
9,709✔
555
                                return r;
556
                } else if ((val = startswith(l, "exec-cgroup-context-tasks-max-scale="))) {
102,206✔
557
                        r = safe_atou64(val, &c->tasks_max.scale);
9,668✔
558
                        if (r < 0)
9,668✔
559
                                return r;
560
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-low-set="))) {
92,538✔
561
                        r = parse_boolean(val);
×
562
                        if (r < 0)
×
563
                                return r;
564
                        c->startup_memory_low_set = r;
×
565
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-high-set="))) {
92,538✔
566
                        r = parse_boolean(val);
×
567
                        if (r < 0)
×
568
                                return r;
569
                        c->startup_memory_high_set = r;
×
570
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-max-set="))) {
92,538✔
571
                        r = parse_boolean(val);
×
572
                        if (r < 0)
×
573
                                return r;
574
                        c->startup_memory_max_set = r;
×
575
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-swap-max-set="))) {
92,538✔
576
                        r = parse_boolean(val);
×
577
                        if (r < 0)
×
578
                                return r;
579
                        c->startup_memory_swap_max_set = r;
×
580
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-zswap-max-set="))) {
92,538✔
581
                        r = parse_boolean(val);
×
582
                        if (r < 0)
×
583
                                return r;
584
                        c->startup_memory_zswap_max_set = r;
×
585
                } else if ((val = startswith(l, "exec-cgroup-context-device-policy="))) {
92,538✔
586
                        c->device_policy = cgroup_device_policy_from_string(val);
10,009✔
587
                        if (c->device_policy < 0)
10,009✔
588
                                return -EINVAL;
589
                } else if ((val = startswith(l, "exec-cgroup-context-disable-controllers="))) {
82,529✔
590
                        r = cg_mask_from_string(val, &c->disable_controllers);
×
591
                        if (r < 0)
×
592
                                return r;
593
                } else if ((val = startswith(l, "exec-cgroup-context-delegate-controllers="))) {
82,529✔
594
                        r = cg_mask_from_string(val, &c->delegate_controllers);
580✔
595
                        if (r < 0)
580✔
596
                                return r;
597
                } else if ((val = startswith(l, "exec-cgroup-context-delegate="))) {
81,949✔
598
                        r = parse_boolean(val);
696✔
599
                        if (r < 0)
696✔
600
                                return r;
601
                        c->delegate = r;
696✔
602
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-swap="))) {
81,253✔
603
                        c->moom_swap = managed_oom_mode_from_string(val);
10,009✔
604
                        if (c->moom_swap < 0)
10,009✔
605
                                return -EINVAL;
606
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-memory-pressure="))) {
71,244✔
607
                        c->moom_mem_pressure = managed_oom_mode_from_string(val);
10,009✔
608
                        if (c->moom_mem_pressure < 0)
10,009✔
609
                                return -EINVAL;
610
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-memory-pressure-limit="))) {
61,235✔
611
                        r = safe_atou32(val, &c->moom_mem_pressure_limit);
10,009✔
612
                        if (r < 0)
10,009✔
613
                                return r;
614
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-preference="))) {
51,226✔
615
                        c->moom_preference = managed_oom_preference_from_string(val);
10,009✔
616
                        if (c->moom_preference < 0)
10,009✔
617
                                return -EINVAL;
618
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-memory-pressure-duration-usec="))) {
41,217✔
619
                        r = deserialize_usec(val, &c->moom_mem_pressure_duration_usec);
1✔
620
                        if (r < 0)
1✔
621
                                return r;
622
                } else if ((val = startswith(l, "exec-cgroup-context-memory-pressure-watch="))) {
41,216✔
623
                        c->memory_pressure_watch = cgroup_pressure_watch_from_string(val);
10,009✔
624
                        if (c->memory_pressure_watch < 0)
10,009✔
625
                                return -EINVAL;
626
                } else if ((val = startswith(l, "exec-cgroup-context-delegate-subgroup="))) {
31,207✔
627
                        r = free_and_strdup(&c->delegate_subgroup, val);
350✔
628
                        if (r < 0)
350✔
629
                                return r;
630
                } else if ((val = startswith(l, "exec-cgroup-context-memory-pressure-threshold-usec="))) {
30,857✔
631
                        r = deserialize_usec(val, &c->memory_pressure_threshold_usec);
10,009✔
632
                        if (r < 0)
10,009✔
633
                                return r;
634
                } else if ((val = startswith(l, "exec-cgroup-context-device-allow="))) {
20,848✔
635
                        _cleanup_free_ char *path = NULL, *rwm = NULL;
3,340✔
636
                        CGroupDevicePermissions p;
3,340✔
637

638
                        r = extract_many_words(&val, " ", 0, &path, &rwm);
3,340✔
639
                        if (r < 0)
3,340✔
640
                                return r;
641
                        if (r == 0)
3,340✔
642
                                return -EINVAL;
643

644
                        p = isempty(rwm) ? 0 : cgroup_device_permissions_from_string(rwm);
6,680✔
645
                        if (p < 0)
3,340✔
646
                                return p;
647

648
                        r = cgroup_context_add_or_update_device_allow(c, path, p);
3,340✔
649
                        if (r < 0)
3,340✔
650
                                return r;
651
                } else if ((val = startswith(l, "exec-cgroup-context-io-device-weight="))) {
17,508✔
652
                        _cleanup_free_ char *path = NULL, *weight = NULL;
×
653
                        CGroupIODeviceWeight *a = NULL;
×
654

655
                        r = extract_many_words(&val, " ", 0, &path, &weight);
×
656
                        if (r < 0)
×
657
                                return r;
658
                        if (r != 2)
×
659
                                return -EINVAL;
660

661
                        LIST_FOREACH(device_weights, b, c->io_device_weights)
×
662
                                if (path_equal(b->path, path)) {
×
663
                                        a = b;
664
                                        break;
665
                                }
666

667
                        if (!a) {
×
668
                                a = new0(CGroupIODeviceWeight, 1);
×
669
                                if (!a)
×
670
                                        return log_oom_debug();
×
671

672
                                a->path = TAKE_PTR(path);
×
673

674
                                LIST_PREPEND(device_weights, c->io_device_weights, a);
×
675
                        }
676

677
                        r = safe_atou64(weight, &a->weight);
×
678
                        if (r < 0)
×
679
                                return r;
680
                } else if ((val = startswith(l, "exec-cgroup-context-io-device-latency-target-usec="))) {
17,508✔
681
                        _cleanup_free_ char *path = NULL, *target = NULL;
×
682
                        CGroupIODeviceLatency *a = NULL;
×
683

684
                        r = extract_many_words(&val, " ", 0, &path, &target);
×
685
                        if (r < 0)
×
686
                                return r;
687
                        if (r != 2)
×
688
                                return -EINVAL;
689

690
                        LIST_FOREACH(device_latencies, b, c->io_device_latencies)
×
691
                                if (path_equal(b->path, path)) {
×
692
                                        a = b;
693
                                        break;
694
                                }
695

696
                        if (!a) {
×
697
                                a = new0(CGroupIODeviceLatency, 1);
×
698
                                if (!a)
×
699
                                        return log_oom_debug();
×
700

701
                                a->path = TAKE_PTR(path);
×
702

703
                                LIST_PREPEND(device_latencies, c->io_device_latencies, a);
×
704
                        }
705

706
                        r = deserialize_usec(target, &a->target_usec);
×
707
                        if (r < 0)
×
708
                                return r;
709
                } else if ((val = startswith(l, "exec-cgroup-context-io-device-limit-"))) {
17,508✔
710
                        _cleanup_free_ char *type = NULL, *path = NULL, *limits = NULL;
×
711
                        CGroupIODeviceLimit *limit = NULL;
×
712
                        CGroupIOLimitType t;
×
713

714
                        r = extract_many_words(&val, "= ", 0, &type, &path, &limits);
×
715
                        if (r < 0)
×
716
                                return r;
717
                        if (r != 3)
×
718
                                return -EINVAL;
719

720
                        t = cgroup_io_limit_type_from_string(type);
×
721
                        if (t < 0)
×
722
                                return t;
723

724
                        LIST_FOREACH(device_limits, i, c->io_device_limits)
×
725
                                if (path_equal(path, i->path)) {
×
726
                                        limit = i;
727
                                        break;
728
                                }
729

730
                        if (!limit) {
×
731
                                limit = new0(CGroupIODeviceLimit, 1);
×
732
                                if (!limit)
×
733
                                        return log_oom_debug();
×
734

735
                                limit->path = TAKE_PTR(path);
×
736
                                for (CGroupIOLimitType i = 0; i < _CGROUP_IO_LIMIT_TYPE_MAX; i++)
×
737
                                        limit->limits[i] = cgroup_io_limit_defaults[i];
×
738

739
                                LIST_PREPEND(device_limits, c->io_device_limits, limit);
×
740
                        }
741

742
                        r = safe_atou64(limits, &limit->limits[t]);
×
743
                        if (r < 0)
×
744
                                return r;
745
                } else if ((val = startswith(l, "exec-cgroup-context-ip-address-allow="))) {
17,508✔
746
                        struct in_addr_prefix a;
×
747

748
                        r = in_addr_prefix_from_string_auto(val, &a.family, &a.address, &a.prefixlen);
×
749
                        if (r < 0)
×
750
                                return r;
×
751

752
                        r = in_addr_prefix_add(&c->ip_address_allow, &a);
×
753
                        if (r < 0)
×
754
                                return r;
755
                } else if ((val = startswith(l, "exec-cgroup-context-ip-address-deny="))) {
17,508✔
756
                        struct in_addr_prefix a;
1,372✔
757

758
                        r = in_addr_prefix_from_string_auto(val, &a.family, &a.address, &a.prefixlen);
1,372✔
759
                        if (r < 0)
1,372✔
760
                                return r;
×
761

762
                        r = in_addr_prefix_add(&c->ip_address_deny, &a);
1,372✔
763
                        if (r < 0)
1,372✔
764
                                return r;
765
                } else if ((val = startswith(l, "exec-cgroup-context-ip-address-allow-reduced="))) {
16,136✔
766
                        r = parse_boolean(val);
8,056✔
767
                        if (r < 0)
8,056✔
768
                                return r;
769
                        c->ip_address_allow_reduced = r;
8,056✔
770
                } else if ((val = startswith(l, "exec-cgroup-context-ip-address-deny-reduced="))) {
8,080✔
771
                        r = parse_boolean(val);
8,056✔
772
                        if (r < 0)
8,056✔
773
                                return r;
774
                        c->ip_address_deny_reduced = r;
8,056✔
775
                } else if ((val = startswith(l, "exec-cgroup-context-ip-ingress-filter-path="))) {
24✔
776
                        r = deserialize_strv(val, &c->ip_filters_ingress);
×
777
                        if (r < 0)
×
778
                                return r;
779
                } else if ((val = startswith(l, "exec-cgroup-context-ip-egress-filter-path="))) {
24✔
780
                        r = deserialize_strv(val, &c->ip_filters_egress);
×
781
                        if (r < 0)
×
782
                                return r;
783
                } else if ((val = startswith(l, "exec-cgroup-context-bpf-program="))) {
24✔
784
                        _cleanup_free_ char *type = NULL, *path = NULL;
×
785
                        uint32_t t;
×
786

787
                        r = extract_many_words(&val, " ", 0, &type, &path);
×
788
                        if (r < 0)
×
789
                                return r;
790
                        if (r != 2)
×
791
                                return -EINVAL;
792

793
                        r = safe_atou32(type, &t);
×
794
                        if (r < 0)
×
795
                                return r;
796

797
                        r = cgroup_context_add_bpf_foreign_program(c, t, path);
×
798
                        if (r < 0)
×
799
                                return r;
800
                } else if ((val = startswith(l, "exec-cgroup-context-socket-bind-allow="))) {
24✔
801
                        CGroupSocketBindItem *item;
×
802
                        uint16_t nr_ports, port_min;
×
803
                        int af, ip_protocol;
×
804

805
                        r = parse_socket_bind_item(val, &af, &ip_protocol, &nr_ports, &port_min);
×
806
                        if (r < 0)
×
807
                                return r;
×
808

809
                        item = new(CGroupSocketBindItem, 1);
×
810
                        if (!item)
×
811
                                return log_oom_debug();
×
812
                        *item = (CGroupSocketBindItem) {
×
813
                                .address_family = af,
814
                                .ip_protocol = ip_protocol,
815
                                .nr_ports = nr_ports,
816
                                .port_min = port_min,
817
                        };
818

819
                        LIST_PREPEND(socket_bind_items, c->socket_bind_allow, item);
×
820
                } else if ((val = startswith(l, "exec-cgroup-context-socket-bind-deny="))) {
24✔
821
                        CGroupSocketBindItem *item;
×
822
                        uint16_t nr_ports, port_min;
×
823
                        int af, ip_protocol;
×
824

825
                        r = parse_socket_bind_item(val, &af, &ip_protocol, &nr_ports, &port_min);
×
826
                        if (r < 0)
×
827
                                return r;
×
828

829
                        item = new(CGroupSocketBindItem, 1);
×
830
                        if (!item)
×
831
                                return log_oom_debug();
×
832
                        *item = (CGroupSocketBindItem) {
×
833
                                .address_family = af,
834
                                .ip_protocol = ip_protocol,
835
                                .nr_ports = nr_ports,
836
                                .port_min = port_min,
837
                        };
838

839
                        LIST_PREPEND(socket_bind_items, c->socket_bind_deny, item);
×
840
                } else if ((val = startswith(l, "exec-cgroup-context-restrict-network-interfaces="))) {
24✔
841
                        r = set_put_strdup(&c->restrict_network_interfaces, val);
15✔
842
                        if (r < 0)
15✔
843
                                return r;
844
                } else if ((val = startswith(l, "exec-cgroup-context-restrict-network-interfaces-is-allow-list="))) {
9✔
845
                        r = parse_boolean(val);
9✔
846
                        if (r < 0)
9✔
847
                                return r;
848
                        c->restrict_network_interfaces_is_allow_list = r;
9✔
849
                } else if ((val = startswith(l, "exec-cgroup-context-bind-iface="))) {
×
850
                        r = free_and_strdup(&c->bind_network_interface, val);
×
851
                        if (r < 0)
×
852
                                return r;
853
                } else
854
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
855
        }
856

857
        return 0;
10,009✔
858
}
859

860
static int exec_runtime_serialize(const ExecRuntime *rt, FILE *f, FDSet *fds) {
2,461✔
861
        int r;
2,461✔
862

863
        assert(f);
2,461✔
864
        assert(fds);
2,461✔
865

866
        if (!rt) {
2,461✔
867
                fputc('\n', f); /* End marker */
2,383✔
868
                return 0;
2,383✔
869
        }
870

871
        if (rt->shared) {
78✔
872
                r = serialize_item(f, "exec-runtime-id", rt->shared->id);
75✔
873
                if (r < 0)
75✔
874
                        return r;
875

876
                r = serialize_item(f, "exec-runtime-tmp-dir", rt->shared->tmp_dir);
75✔
877
                if (r < 0)
75✔
878
                        return r;
879

880
                r = serialize_item(f, "exec-runtime-var-tmp-dir", rt->shared->var_tmp_dir);
75✔
881
                if (r < 0)
75✔
882
                        return r;
883

884
                if (rt->shared->userns_storage_socket[0] >= 0 && rt->shared->userns_storage_socket[1] >= 0) {
75✔
885
                        r = serialize_fd_many(f, fds, "exec-runtime-userns-storage-socket", rt->shared->userns_storage_socket, 2);
×
886
                        if (r < 0)
×
887
                                return r;
888
                }
889

890
                if (rt->shared->netns_storage_socket[0] >= 0 && rt->shared->netns_storage_socket[1] >= 0) {
75✔
891
                        r = serialize_fd_many(f, fds, "exec-runtime-netns-storage-socket", rt->shared->netns_storage_socket, 2);
8✔
892
                        if (r < 0)
8✔
893
                                return r;
894
                }
895

896
                if (rt->shared->ipcns_storage_socket[0] >= 0 && rt->shared->ipcns_storage_socket[1] >= 0) {
75✔
897
                        r = serialize_fd_many(f, fds, "exec-runtime-ipcns-storage-socket", rt->shared->ipcns_storage_socket, 2);
2✔
898
                        if (r < 0)
2✔
899
                                return r;
900
                }
901
        }
902

903
        if (rt->dynamic_creds) {
78✔
904
                r = dynamic_user_serialize_one(rt->dynamic_creds->user, "exec-runtime-dynamic-creds-user", f, fds);
3✔
905
                if (r < 0)
3✔
906
                        return r;
907
        }
908

909
        if (rt->dynamic_creds && rt->dynamic_creds->group && rt->dynamic_creds->group == rt->dynamic_creds->user) {
78✔
910
                r = serialize_bool(f, "exec-runtime-dynamic-creds-group-copy", true);
2✔
911
                if (r < 0)
2✔
912
                        return r;
913
        } else if (rt->dynamic_creds) {
76✔
914
                r = dynamic_user_serialize_one(rt->dynamic_creds->group, "exec-runtime-dynamic-creds-group", f, fds);
1✔
915
                if (r < 0)
1✔
916
                        return r;
917
        }
918

919
        r = serialize_item(f, "exec-runtime-ephemeral-copy", rt->ephemeral_copy);
78✔
920
        if (r < 0)
78✔
921
                return r;
922

923
        if (rt->ephemeral_storage_socket[0] >= 0 && rt->ephemeral_storage_socket[1] >= 0) {
78✔
924
                r = serialize_fd_many(f, fds, "exec-runtime-ephemeral-storage-socket", rt->ephemeral_storage_socket, 2);
×
925
                if (r < 0)
×
926
                        return r;
927
        }
928

929
        fputc('\n', f); /* End marker */
78✔
930

931
        return 0;
78✔
932
}
933

934
static int exec_runtime_deserialize(ExecRuntime *rt, FILE *f, FDSet *fds) {
10,009✔
935
        int r;
10,009✔
936

937
        assert(rt);
10,009✔
938
        assert(rt->shared);
10,009✔
939
        assert(rt->dynamic_creds);
10,009✔
940
        assert(f);
10,009✔
941
        assert(fds);
10,009✔
942

943
        for (;;) {
11,261✔
944
                _cleanup_free_ char *l = NULL;
1,252✔
945
                const char *val;
11,261✔
946

947
                r = deserialize_read_line(f, &l);
11,261✔
948
                if (r < 0)
11,261✔
949
                        return r;
950
                if (r == 0) /* eof or end marker */
11,261✔
951
                        break;
952

953
                if ((val = startswith(l, "exec-runtime-id="))) {
1,252✔
954
                        r = free_and_strdup(&rt->shared->id, val);
375✔
955
                        if (r < 0)
375✔
956
                                return r;
957
                } else if ((val = startswith(l, "exec-runtime-tmp-dir="))) {
877✔
958
                        r = free_and_strdup(&rt->shared->tmp_dir, val);
351✔
959
                        if (r < 0)
351✔
960
                                return r;
961
                } else if ((val = startswith(l, "exec-runtime-var-tmp-dir="))) {
526✔
962
                        r = free_and_strdup(&rt->shared->var_tmp_dir, val);
351✔
963
                        if (r < 0)
351✔
964
                                return r;
965
                } else if ((val = startswith(l, "exec-runtime-userns-storage-socket="))) {
175✔
966

967
                        r = deserialize_fd_many(fds, val, 2, rt->shared->userns_storage_socket);
3✔
968
                        if (r < 0)
3✔
969
                                continue;
×
970

971
                } else if ((val = startswith(l, "exec-runtime-netns-storage-socket="))) {
172✔
972

973
                        r = deserialize_fd_many(fds, val, 2, rt->shared->netns_storage_socket);
72✔
974
                        if (r < 0)
72✔
975
                                continue;
×
976

977
                } else if ((val = startswith(l, "exec-runtime-ipcns-storage-socket="))) {
100✔
978

979
                        r = deserialize_fd_many(fds, val, 2, rt->shared->ipcns_storage_socket);
6✔
980
                        if (r < 0)
6✔
981
                                continue;
×
982

983
                } else if ((val = startswith(l, "exec-runtime-dynamic-creds-user=")))
94✔
984
                        dynamic_user_deserialize_one(/* m= */ NULL, val, fds, &rt->dynamic_creds->user);
47✔
985
                else if ((val = startswith(l, "exec-runtime-dynamic-creds-group=")))
47✔
986
                        dynamic_user_deserialize_one(/* m= */ NULL, val, fds, &rt->dynamic_creds->group);
×
987
                else if ((val = startswith(l, "exec-runtime-dynamic-creds-group-copy="))) {
47✔
988
                        r = parse_boolean(val);
47✔
989
                        if (r < 0)
47✔
990
                                return r;
991
                        if (!r)
47✔
992
                                continue; /* Nothing to do */
×
993

994
                        if (!rt->dynamic_creds->user)
47✔
995
                                return -EINVAL;
996

997
                        rt->dynamic_creds->group = dynamic_user_ref(rt->dynamic_creds->user);
47✔
998
                } else if ((val = startswith(l, "exec-runtime-ephemeral-copy="))) {
×
999
                        r = free_and_strdup(&rt->ephemeral_copy, val);
×
1000
                        if (r < 0)
×
1001
                                return r;
1002
                } else if ((val = startswith(l, "exec-runtime-ephemeral-storage-socket="))) {
×
1003

1004
                        r = deserialize_fd_many(fds, val, 2, rt->ephemeral_storage_socket);
×
1005
                        if (r < 0)
×
1006
                                continue;
×
1007
                } else
1008
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
1009
        }
1010

1011
        return 0;
10,009✔
1012
}
1013

1014
static bool exec_parameters_is_idle_pipe_set(const ExecParameters *p) {
2,461✔
1015
        assert(p);
2,461✔
1016

1017
        return p->idle_pipe &&
2,490✔
1018
                p->idle_pipe[0] >= 0 &&
29✔
1019
                p->idle_pipe[1] >= 0 &&
27✔
1020
                p->idle_pipe[2] >= 0 &&
2,488✔
1021
                p->idle_pipe[3] >= 0;
27✔
1022
}
1023

1024
static int exec_parameters_serialize(const ExecParameters *p, const ExecContext *c, FILE *f, FDSet *fds) {
2,461✔
1025
        int r;
2,461✔
1026

1027
        assert(f);
2,461✔
1028
        assert(fds);
2,461✔
1029

1030
        if (!p)
2,461✔
1031
                return 0;
1032

1033
        r = serialize_item(f, "exec-parameters-runtime-scope", runtime_scope_to_string(p->runtime_scope));
2,461✔
1034
        if (r < 0)
2,461✔
1035
                return r;
1036

1037
        r = serialize_strv(f, "exec-parameters-environment", p->environment);
2,461✔
1038
        if (r < 0)
2,461✔
1039
                return r;
1040

1041
        if (p->fds) {
2,461✔
1042
                if (p->n_socket_fds > 0) {
535✔
1043
                        r = serialize_item_format(f, "exec-parameters-n-socket-fds", "%zu", p->n_socket_fds);
534✔
1044
                        if (r < 0)
534✔
1045
                                return r;
1046
                }
1047

1048
                if (p->n_stashed_fds > 0) {
535✔
1049
                        r = serialize_item_format(f, "exec-parameters-n-stashed-fds", "%zu", p->n_stashed_fds);
4✔
1050
                        if (r < 0)
4✔
1051
                                return r;
1052
                }
1053

1054
                r = serialize_fd_many(f, fds, "exec-parameters-fds", p->fds, p->n_socket_fds + p->n_stashed_fds);
535✔
1055
                if (r < 0)
535✔
1056
                        return r;
1057

1058
                r = serialize_strv(f, "exec-parameters-fd-names", p->fd_names);
535✔
1059
                if (r < 0)
535✔
1060
                        return r;
1061
        }
1062

1063
        if (p->flags != 0) {
2,461✔
1064
                r = serialize_item_format(f, "exec-parameters-flags", "%u", (unsigned) p->flags);
2,461✔
1065
                if (r < 0)
2,461✔
1066
                        return r;
1067
        }
1068

1069
        r = serialize_bool_elide(f, "exec-parameters-selinux-context-net", p->selinux_context_net);
2,461✔
1070
        if (r < 0)
2,461✔
1071
                return r;
1072

1073
        r = serialize_item(f, "exec-parameters-cgroup-path", p->cgroup_path);
2,461✔
1074
        if (r < 0)
2,461✔
1075
                return r;
1076

1077
        r = serialize_item_format(f, "exec-parameters-cgroup-id", "%" PRIu64, p->cgroup_id);
2,461✔
1078
        if (r < 0)
2,461✔
1079
                return r;
1080

1081
        for (ExecDirectoryType dt = 0; dt < _EXEC_DIRECTORY_TYPE_MAX; dt++) {
14,766✔
1082
                _cleanup_free_ char *key = NULL;
12,305✔
1083

1084
                key = strjoin("exec-parameters-prefix-directories-", exec_directory_type_to_string(dt));
12,305✔
1085
                if (!key)
12,305✔
1086
                        return log_oom_debug();
×
1087

1088
                /* Always serialize, even an empty prefix, as this is a fixed array and we always expect
1089
                 * to have all elements (unless fuzzing is happening, hence the NULL check). */
1090
                r = serialize_item(f, key, strempty(p->prefix ? p->prefix[dt] : NULL));
12,305✔
1091
                if (r < 0)
12,305✔
1092
                        return r;
1093
        }
1094

1095
        r = serialize_item(f, "exec-parameters-received-credentials-directory", p->received_credentials_directory);
2,461✔
1096
        if (r < 0)
2,461✔
1097
                return r;
1098

1099
        r = serialize_item(f, "exec-parameters-received-encrypted-credentials-directory", p->received_encrypted_credentials_directory);
2,461✔
1100
        if (r < 0)
2,461✔
1101
                return r;
1102

1103
        r = serialize_item(f, "exec-parameters-confirm-spawn", p->confirm_spawn);
2,461✔
1104
        if (r < 0)
2,461✔
1105
                return r;
1106

1107
        r = serialize_bool_elide(f, "exec-parameters-shall-confirm-spawn", p->shall_confirm_spawn);
2,461✔
1108
        if (r < 0)
2,461✔
1109
                return r;
1110

1111
        if (p->watchdog_usec > 0) {
2,461✔
1112
                r = serialize_usec(f, "exec-parameters-watchdog-usec", p->watchdog_usec);
233✔
1113
                if (r < 0)
233✔
1114
                        return r;
1115
        }
1116

1117
        if (exec_parameters_is_idle_pipe_set(p)) {
2,461✔
1118
                r = serialize_fd_many(f, fds, "exec-parameters-idle-pipe", p->idle_pipe, 4);
27✔
1119
                if (r < 0)
27✔
1120
                        return r;
1121
        }
1122

1123
        r = serialize_fd(f, fds, "exec-parameters-stdin-fd", p->stdin_fd);
2,461✔
1124
        if (r < 0)
2,461✔
1125
                return r;
1126

1127
        r = serialize_fd(f, fds, "exec-parameters-stdout-fd", p->stdout_fd);
2,461✔
1128
        if (r < 0)
2,461✔
1129
                return r;
1130

1131
        r = serialize_fd(f, fds, "exec-parameters-stderr-fd", p->stderr_fd);
2,461✔
1132
        if (r < 0)
2,461✔
1133
                return r;
1134

1135
        r = serialize_fd(f, fds, "exec-parameters-root-directory-fd", p->root_directory_fd);
2,461✔
1136
        if (r < 0)
2,461✔
1137
                return r;
1138

1139
        r = serialize_fd(f, fds, "exec-parameters-exec-fd", p->exec_fd);
2,461✔
1140
        if (r < 0)
2,461✔
1141
                return r;
1142

1143
        r = serialize_fd(f, fds, "exec-parameters-handoff-timestamp-fd", p->handoff_timestamp_fd);
2,461✔
1144
        if (r < 0)
2,461✔
1145
                return r;
1146

1147
        r = serialize_fd(f, fds, "exec-parameters-pidref-transport-fd", p->pidref_transport_fd);
2,461✔
1148
        if (r < 0)
2,461✔
1149
                return r;
1150

1151
        if (c && exec_context_restrict_filesystems_set(c)) {
2,461✔
1152
                r = serialize_fd(f, fds, "exec-parameters-bpf-outer-map-fd", p->bpf_restrict_fs_map_fd);
×
1153
                if (r < 0)
×
1154
                        return r;
1155
        }
1156

1157
        r = serialize_item(f, "exec-parameters-notify-socket", p->notify_socket);
2,461✔
1158
        if (r < 0)
2,461✔
1159
                return r;
1160

1161
        LIST_FOREACH(open_files, file, p->open_files) {
2,461✔
1162
                _cleanup_free_ char *ofs = NULL;
×
1163

1164
                r = open_file_to_string(file, &ofs);
×
1165
                if (r < 0)
×
1166
                        return r;
1167

1168
                r = serialize_item(f, "exec-parameters-open-file", ofs);
×
1169
                if (r < 0)
×
1170
                        return r;
1171
        }
1172

1173
        r = serialize_item(f, "exec-parameters-fallback-smack-process-label", p->fallback_smack_process_label);
2,461✔
1174
        if (r < 0)
2,461✔
1175
                return r;
1176

1177
        r = serialize_fd(f, fds, "exec-parameters-user-lookup-fd", p->user_lookup_fd);
2,461✔
1178
        if (r < 0)
2,461✔
1179
                return r;
1180

1181
        r = serialize_strv(f, "exec-parameters-files-env", p->files_env);
2,461✔
1182
        if (r < 0)
2,461✔
1183
                return r;
1184

1185
        r = serialize_item(f, "exec-parameters-unit-id", p->unit_id);
2,461✔
1186
        if (r < 0)
2,461✔
1187
                return r;
1188

1189
        r = serialize_item(f, "exec-parameters-invocation-id-string", p->invocation_id_string);
2,461✔
1190
        if (r < 0)
2,461✔
1191
                return r;
1192

1193
        r = serialize_bool_elide(f, "exec-parameters-debug-invocation", p->debug_invocation);
2,461✔
1194
        if (r < 0)
2,461✔
1195
                return r;
1196

1197
        fputc('\n', f); /* End marker */
2,461✔
1198

1199
        return 0;
2,461✔
1200
}
1201

1202
static int exec_parameters_deserialize(ExecParameters *p, FILE *f, FDSet *fds) {
10,009✔
1203
        int r;
10,009✔
1204

1205
        assert(p);
10,009✔
1206
        assert(f);
10,009✔
1207
        assert(fds);
10,009✔
1208

1209
        unsigned nr_open = MAX(read_nr_open(), NR_OPEN_MINIMUM);
10,009✔
1210

1211
        for (;;) {
213,824✔
1212
                _cleanup_free_ char *l = NULL;
203,815✔
1213
                const char *val;
213,824✔
1214

1215
                r = deserialize_read_line(f, &l);
213,824✔
1216
                if (r < 0)
213,824✔
1217
                        return r;
1218
                if (r == 0) /* eof or end marker */
213,824✔
1219
                        break;
1220

1221
                if ((val = startswith(l, "exec-parameters-runtime-scope="))) {
203,815✔
1222
                        p->runtime_scope = runtime_scope_from_string(val);
10,009✔
1223
                        if (p->runtime_scope < 0)
10,009✔
1224
                                return p->runtime_scope;
1225
                } else if ((val = startswith(l, "exec-parameters-environment="))) {
193,806✔
1226
                        r = deserialize_strv(val, &p->environment);
42,689✔
1227
                        if (r < 0)
42,689✔
1228
                                return r;
1229
                } else if ((val = startswith(l, "exec-parameters-n-socket-fds="))) {
151,117✔
1230
                        if (p->fds)
1,746✔
1231
                                return -EINVAL; /* Already received */
1232

1233
                        r = safe_atozu(val, &p->n_socket_fds);
1,746✔
1234
                        if (r < 0)
1,746✔
1235
                                return r;
1236

1237
                        if (p->n_socket_fds > nr_open)
1,746✔
1238
                                return -EINVAL; /* too many, someone is playing games with us */
1239
                } else if ((val = startswith(l, "exec-parameters-n-stashed-fds="))) {
149,371✔
1240
                        if (p->fds)
110✔
1241
                                return -EINVAL; /* Already received */
1242

1243
                        r = safe_atozu(val, &p->n_stashed_fds);
110✔
1244
                        if (r < 0)
110✔
1245
                                return r;
1246

1247
                        if (p->n_stashed_fds > nr_open)
110✔
1248
                                return -EINVAL; /* too many, someone is playing games with us */
1249
                } else if ((val = startswith(l, "exec-parameters-fds="))) {
149,261✔
1250
                        if (p->n_socket_fds + p->n_stashed_fds == 0)
1,751✔
1251
                                return log_warning_errno(
×
1252
                                                SYNTHETIC_ERRNO(EINVAL),
1253
                                                "Got exec-parameters-fds= without "
1254
                                                "prior exec-parameters-n-socket-fds= or exec-parameters-n-stashed-fds=");
1255
                        if (p->n_socket_fds + p->n_stashed_fds > nr_open)
1,751✔
1256
                                return -EINVAL; /* too many, someone is playing games with us */
1257

1258
                        if (p->fds)
1,751✔
1259
                                return -EINVAL; /* duplicated */
1260

1261
                        p->fds = new(int, p->n_socket_fds + p->n_stashed_fds);
1,751✔
1262
                        if (!p->fds)
1,751✔
1263
                                return log_oom_debug();
×
1264

1265
                        /* Ensure we don't leave any FD uninitialized on error, it makes the fuzzer sad */
1266
                        FOREACH_ARRAY(i, p->fds, p->n_socket_fds + p->n_stashed_fds)
5,435✔
1267
                                *i = -EBADF;
3,684✔
1268

1269
                        r = deserialize_fd_many(fds, val, p->n_socket_fds + p->n_stashed_fds, p->fds);
1,751✔
1270
                        if (r < 0)
1,751✔
1271
                                continue;
×
1272

1273
                } else if ((val = startswith(l, "exec-parameters-fd-names="))) {
147,510✔
1274
                        r = deserialize_strv(val, &p->fd_names);
3,684✔
1275
                        if (r < 0)
3,684✔
1276
                                return r;
1277
                } else if ((val = startswith(l, "exec-parameters-flags="))) {
143,826✔
1278
                        unsigned flags;
10,009✔
1279

1280
                        r = safe_atou(val, &flags);
10,009✔
1281
                        if (r < 0)
10,009✔
1282
                                return r;
×
1283
                        p->flags = flags;
10,009✔
1284
                } else if ((val = startswith(l, "exec-parameters-selinux-context-net="))) {
133,817✔
1285
                        r = parse_boolean(val);
×
1286
                        if (r < 0)
×
1287
                                return r;
1288

1289
                        p->selinux_context_net = r;
×
1290
                } else if ((val = startswith(l, "exec-parameters-cgroup-path="))) {
133,817✔
1291
                        r = free_and_strdup(&p->cgroup_path, val);
10,009✔
1292
                        if (r < 0)
10,009✔
1293
                                return r;
1294
                } else if ((val = startswith(l, "exec-parameters-cgroup-id="))) {
123,808✔
1295
                        r = safe_atou64(val, &p->cgroup_id);
10,009✔
1296
                        if (r < 0)
10,009✔
1297
                                return r;
1298
                } else if ((val = startswith(l, "exec-parameters-prefix-directories-"))) {
113,799✔
1299
                        _cleanup_free_ char *type = NULL, *prefix = NULL;
50,045✔
1300
                        ExecDirectoryType dt;
50,045✔
1301

1302
                        r = extract_many_words(&val, "= ", 0, &type, &prefix);
50,045✔
1303
                        if (r < 0)
50,045✔
1304
                                return r;
1305
                        if (r == 0)
50,045✔
1306
                                return -EINVAL;
1307

1308
                        dt = exec_directory_type_from_string(type);
50,045✔
1309
                        if (dt < 0)
50,045✔
1310
                                return -EINVAL;
1311

1312
                        if (!p->prefix) {
50,045✔
1313
                                p->prefix = new0(char*, _EXEC_DIRECTORY_TYPE_MAX+1);
10,009✔
1314
                                if (!p->prefix)
10,009✔
1315
                                        return log_oom_debug();
×
1316
                        }
1317

1318
                        if (isempty(prefix))
50,045✔
1319
                                p->prefix[dt] = mfree(p->prefix[dt]);
×
1320
                        else
1321
                                free_and_replace(p->prefix[dt], prefix);
50,045✔
1322
                } else if ((val = startswith(l, "exec-parameters-received-credentials-directory="))) {
63,754✔
1323
                        r = free_and_strdup(&p->received_credentials_directory, val);
9,313✔
1324
                        if (r < 0)
9,313✔
1325
                                return r;
1326
                } else if ((val = startswith(l, "exec-parameters-received-encrypted-credentials-directory="))) {
54,441✔
1327
                        r = free_and_strdup(&p->received_encrypted_credentials_directory, val);
×
1328
                        if (r < 0)
×
1329
                                return r;
1330
                } else if ((val = startswith(l, "exec-parameters-confirm-spawn="))) {
54,441✔
1331
                        r = free_and_strdup(&p->confirm_spawn, val);
×
1332
                        if (r < 0)
×
1333
                                return r;
1334
                } else if ((val = startswith(l, "exec-parameters-shall-confirm-spawn="))) {
54,441✔
1335
                        r = parse_boolean(val);
×
1336
                        if (r < 0)
×
1337
                                return r;
1338

1339
                        p->shall_confirm_spawn = r;
×
1340
                } else if ((val = startswith(l, "exec-parameters-watchdog-usec="))) {
54,441✔
1341
                        r = deserialize_usec(val, &p->watchdog_usec);
1,484✔
1342
                        if (r < 0)
1,484✔
1343
                                return r;
1344
                } else if ((val = startswith(l, "exec-parameters-idle-pipe="))) {
52,957✔
1345
                        if (p->idle_pipe)
85✔
1346
                                return -EINVAL; /* duplicated */
1347

1348
                        p->idle_pipe = new(int, 4);
85✔
1349
                        if (!p->idle_pipe)
85✔
1350
                                return log_oom_debug();
×
1351

1352
                        p->idle_pipe[0] = p->idle_pipe[1] = p->idle_pipe[2] = p->idle_pipe[3] = -EBADF;
85✔
1353

1354
                        r = deserialize_fd_many(fds, val, 4, p->idle_pipe);
85✔
1355
                        if (r < 0)
85✔
1356
                                continue;
×
1357

1358
                } else if ((val = startswith(l, "exec-parameters-stdin-fd="))) {
52,872✔
1359
                        int fd;
553✔
1360

1361
                        fd = deserialize_fd(fds, val);
553✔
1362
                        if (fd < 0)
553✔
1363
                                continue;
×
1364

1365
                        close_and_replace(p->stdin_fd, fd);
553✔
1366

1367
                } else if ((val = startswith(l, "exec-parameters-stdout-fd="))) {
52,319✔
1368
                        int fd;
553✔
1369

1370
                        fd = deserialize_fd(fds, val);
553✔
1371
                        if (fd < 0)
553✔
1372
                                continue;
×
1373

1374
                        close_and_replace(p->stdout_fd, fd);
553✔
1375

1376
                } else if ((val = startswith(l, "exec-parameters-stderr-fd="))) {
51,766✔
1377
                        int fd;
553✔
1378

1379
                        fd = deserialize_fd(fds, val);
553✔
1380
                        if (fd < 0)
553✔
1381
                                continue;
×
1382

1383
                        close_and_replace(p->stderr_fd, fd);
553✔
1384

1385
                } else if ((val = startswith(l, "exec-parameters-root-directory-fd="))) {
51,213✔
1386
                        int fd;
2✔
1387

1388
                        fd = deserialize_fd(fds, val);
2✔
1389
                        if (fd < 0)
2✔
1390
                                continue;
×
1391

1392
                        close_and_replace(p->root_directory_fd, fd);
2✔
1393

1394
                } else if ((val = startswith(l, "exec-parameters-exec-fd="))) {
51,211✔
1395
                        int fd;
428✔
1396

1397
                        fd = deserialize_fd(fds, val);
428✔
1398
                        if (fd < 0)
428✔
1399
                                continue;
×
1400

1401
                        close_and_replace(p->exec_fd, fd);
428✔
1402
                } else if ((val = startswith(l, "exec-parameters-handoff-timestamp-fd="))) {
50,783✔
1403
                        int fd;
10,009✔
1404

1405
                        fd = deserialize_fd(fds, val);
10,009✔
1406
                        if (fd < 0)
10,009✔
1407
                                continue;
×
1408

1409
                        close_and_replace(p->handoff_timestamp_fd, fd);
10,009✔
1410
                } else if ((val = startswith(l, "exec-parameters-pidref-transport-fd="))) {
40,774✔
1411
                        int fd;
8,850✔
1412

1413
                        fd = deserialize_fd(fds, val);
8,850✔
1414
                        if (fd < 0)
8,850✔
1415
                                continue;
×
1416

1417
                        close_and_replace(p->pidref_transport_fd, fd);
8,850✔
1418
                } else if ((val = startswith(l, "exec-parameters-bpf-outer-map-fd="))) {
31,924✔
1419
                        int fd;
×
1420

1421
                        fd = deserialize_fd(fds, val);
×
1422
                        if (fd < 0)
×
1423
                                continue;
×
1424

1425
                        close_and_replace(p->bpf_restrict_fs_map_fd, fd);
×
1426
                } else if ((val = startswith(l, "exec-parameters-notify-socket="))) {
31,924✔
1427
                        r = free_and_strdup(&p->notify_socket, val);
1,888✔
1428
                        if (r < 0)
1,888✔
1429
                                return r;
1430
                } else if ((val = startswith(l, "exec-parameters-open-file="))) {
30,036✔
1431
                        OpenFile *of;
5✔
1432

1433
                        r = open_file_parse(val, &of);
5✔
1434
                        if (r < 0)
5✔
1435
                                return r;
×
1436

1437
                        LIST_APPEND(open_files, p->open_files, of);
5✔
1438
                } else if ((val = startswith(l, "exec-parameters-fallback-smack-process-label="))) {
30,031✔
1439
                        r = free_and_strdup(&p->fallback_smack_process_label, val);
×
1440
                        if (r < 0)
×
1441
                                return r;
1442
                } else if ((val = startswith(l, "exec-parameters-user-lookup-fd="))) {
30,031✔
1443
                        int fd;
10,009✔
1444

1445
                        fd = deserialize_fd(fds, val);
10,009✔
1446
                        if (fd < 0)
10,009✔
1447
                                continue;
×
1448

1449
                        close_and_replace(p->user_lookup_fd, fd);
10,009✔
1450
                } else if ((val = startswith(l, "exec-parameters-files-env="))) {
20,022✔
1451
                        r = deserialize_strv(val, &p->files_env);
2✔
1452
                        if (r < 0)
2✔
1453
                                return r;
1454
                } else if ((val = startswith(l, "exec-parameters-unit-id="))) {
20,020✔
1455
                        r = free_and_strdup(&p->unit_id, val);
10,009✔
1456
                        if (r < 0)
10,009✔
1457
                                return r;
1458
                } else if ((val = startswith(l, "exec-parameters-invocation-id-string="))) {
10,011✔
1459
                        if (strlen(val) > SD_ID128_STRING_MAX - 1)
10,009✔
1460
                                return -EINVAL;
1461

1462
                        r = sd_id128_from_string(val, &p->invocation_id);
10,009✔
1463
                        if (r < 0)
10,009✔
1464
                                return r;
1465

1466
                        sd_id128_to_string(p->invocation_id, p->invocation_id_string);
10,009✔
1467
                } else if ((val = startswith(l, "exec-parameters-debug-invocation="))) {
2✔
1468
                        r = parse_boolean(val);
2✔
1469
                        if (r < 0)
2✔
1470
                                return r;
1471

1472
                        p->debug_invocation = r;
2✔
1473
                } else
1474
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
1475
        }
1476

1477
        /* Bail out if we got exec-parameters-n-{socket/stashed}-fds= but no corresponding
1478
         * exec-parameters-fds= */
1479
        if (p->n_socket_fds + p->n_stashed_fds > 0 && !p->fds)
10,009✔
1480
                return -EINVAL;
×
1481

1482
        return 0;
1483
}
1484

1485
static int serialize_mount_options(const MountOptions *mount_options, char **s) {
24✔
1486
        assert(s);
24✔
1487

1488
        if (!mount_options)
24✔
1489
                return 0;
1490

1491
        for (PartitionDesignator i = 0; i < _PARTITION_DESIGNATOR_MAX; i++) {
84✔
1492
                _cleanup_free_ char *escaped = NULL;
7✔
1493

1494
                if (isempty(mount_options->options[i]))
78✔
1495
                        continue;
71✔
1496

1497
                escaped = shell_escape(mount_options->options[i], ":");
7✔
1498
                if (!escaped)
7✔
1499
                        return log_oom_debug();
×
1500

1501
                if (!strextend(s,
7✔
1502
                               " ",
1503
                               partition_designator_to_string(i),
1504
                               ":",
1505
                               escaped))
1506
                        return log_oom_debug();
×
1507
        }
1508

1509
        return 0;
1510
}
1511

1512
static int deserialize_mount_options(const char *s, MountOptions **ret_mount_options) {
55✔
1513
        _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
55✔
1514
        int r;
55✔
1515

1516
        assert(ret_mount_options);
55✔
1517

1518
        for (;;) {
63✔
1519
                _cleanup_free_ char *word = NULL, *mount_options = NULL, *partition = NULL;
8✔
1520
                PartitionDesignator partition_designator;
63✔
1521
                const char *p;
63✔
1522

1523
                r = extract_first_word(&s, &word, NULL, 0);
63✔
1524
                if (r < 0)
63✔
1525
                        return r;
1526
                if (r == 0)
63✔
1527
                        break;
1528

1529
                p = word;
8✔
1530
                r = extract_many_words(&p, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &partition, &mount_options);
8✔
1531
                if (r < 0)
8✔
1532
                        return r;
1533
                if (r == 0)
8✔
1534
                        continue;
×
1535
                if (r != 2) {
8✔
1536
                        log_warning("Failed to parse mount options entry '%s', ignoring.", word);
×
1537
                        continue;
×
1538
                }
1539

1540
                partition_designator = partition_designator_from_string(partition);
8✔
1541
                if (partition_designator < 0) {
8✔
1542
                        log_warning_errno(partition_designator, "Unknown partition designator '%s' in exec-context-root-image-options= entry, ignoring.", partition);
×
1543
                        continue;
×
1544
                }
1545

1546
                r = mount_options_set_and_consume(&options, partition_designator, TAKE_PTR(mount_options));
8✔
1547
                if (r < 0)
8✔
1548
                        return r;
1549
        }
1550

1551
        *ret_mount_options = TAKE_PTR(options);
55✔
1552

1553
        return 0;
55✔
1554
}
1555

1556
static int exec_context_serialize(const ExecContext *c, FILE *f) {
2,461✔
1557
        int r;
2,461✔
1558

1559
        assert(f);
2,461✔
1560

1561
        if (!c)
2,461✔
1562
                return 0;
2,461✔
1563

1564
        r = serialize_strv(f, "exec-context-environment", c->environment);
2,461✔
1565
        if (r < 0)
2,461✔
1566
                return r;
1567

1568
        r = serialize_strv(f, "exec-context-environment-files", c->environment_files);
2,461✔
1569
        if (r < 0)
2,461✔
1570
                return r;
1571

1572
        r = serialize_strv(f, "exec-context-pass-environment", c->pass_environment);
2,461✔
1573
        if (r < 0)
2,461✔
1574
                return r;
1575

1576
        r = serialize_strv(f, "exec-context-unset-environment", c->unset_environment);
2,461✔
1577
        if (r < 0)
2,461✔
1578
                return r;
1579

1580
        r = serialize_item_escaped(f, "exec-context-working-directory", c->working_directory);
2,461✔
1581
        if (r < 0)
2,461✔
1582
                return r;
1583

1584
        r = serialize_bool_elide(f, "exec-context-working-directory-missing-ok", c->working_directory_missing_ok);
2,461✔
1585
        if (r < 0)
2,461✔
1586
                return r;
1587

1588
        r = serialize_bool_elide(f, "exec-context-working-directory-home", c->working_directory_home);
2,461✔
1589
        if (r < 0)
2,461✔
1590
                return r;
1591

1592
        r = serialize_item_escaped(f, "exec-context-root-directory", c->root_directory);
2,461✔
1593
        if (r < 0)
2,461✔
1594
                return r;
1595

1596
        r = serialize_item_escaped(f, "exec-context-root-image", c->root_image);
2,461✔
1597
        if (r < 0)
2,461✔
1598
                return r;
1599

1600
        if (c->root_image_options) {
2,461✔
1601
                _cleanup_free_ char *options = NULL;
2✔
1602

1603
                r = serialize_mount_options(c->root_image_options, &options);
2✔
1604
                if (r < 0)
2✔
1605
                        return r;
1606

1607
                r = serialize_item(f, "exec-context-root-image-options", options);
2✔
1608
                if (r < 0)
2✔
1609
                        return r;
1610
        }
1611

1612
        r = serialize_item(f, "exec-context-root-verity", c->root_verity);
2,461✔
1613
        if (r < 0)
2,461✔
1614
                return r;
1615

1616
        r = serialize_item(f, "exec-context-root-hash-path", c->root_hash_path);
2,461✔
1617
        if (r < 0)
2,461✔
1618
                return r;
1619

1620
        r = serialize_item(f, "exec-context-root-hash-sig-path", c->root_hash_sig_path);
2,461✔
1621
        if (r < 0)
2,461✔
1622
                return r;
1623

1624
        r = serialize_item_hexmem(f, "exec-context-root-hash", c->root_hash.iov_base, c->root_hash.iov_len);
2,461✔
1625
        if (r < 0)
2,461✔
1626
                return r;
1627

1628
        r = serialize_item_base64mem(f, "exec-context-root-hash-sig", c->root_hash_sig.iov_base, c->root_hash_sig.iov_len);
2,461✔
1629
        if (r < 0)
2,461✔
1630
                return r;
1631

1632
        r = serialize_bool_elide(f, "exec-context-root-ephemeral", c->root_ephemeral);
2,461✔
1633
        if (r < 0)
2,461✔
1634
                return r;
1635

1636
        r = serialize_item_format(f, "exec-context-umask", "%04o", c->umask);
2,461✔
1637
        if (r < 0)
2,461✔
1638
                return r;
1639

1640
        r = serialize_bool_elide(f, "exec-context-non-blocking", c->non_blocking);
2,461✔
1641
        if (r < 0)
2,461✔
1642
                return r;
1643

1644
        r = serialize_item_tristate(f, "exec-context-private-mounts", c->private_mounts);
2,461✔
1645
        if (r < 0)
28✔
1646
                return r;
1647

1648
        r = serialize_item_tristate(f, "exec-context-mount-api-vfs", c->mount_apivfs);
2,461✔
1649
        if (r < 0)
30✔
1650
                return r;
1651

1652
        r = serialize_item_tristate(f, "exec-context-bind-log-sockets", c->bind_log_sockets);
2,461✔
1653
        if (r < 0)
28✔
1654
                return r;
1655

1656
        r = serialize_item_tristate(f, "exec-context-memory-ksm", c->memory_ksm);
2,461✔
1657
        if (r < 0)
×
1658
                return r;
1659

1660
        r = serialize_item(f, "exec-context-memory-thp", memory_thp_to_string(c->memory_thp));
2,461✔
1661
        if (r < 0)
2,461✔
1662
                return r;
1663

1664
        r = serialize_item(f, "exec-context-private-tmp", private_tmp_to_string(c->private_tmp));
2,461✔
1665
        if (r < 0)
2,461✔
1666
                return r;
1667

1668
        /* This must be set in unit_patch_contexts() before executing a command. */
1669
        assert(c->private_var_tmp >= 0 && c->private_var_tmp < _PRIVATE_TMP_MAX);
2,461✔
1670
        r = serialize_item(f, "exec-context-private-var-tmp", private_tmp_to_string(c->private_var_tmp));
2,461✔
1671
        if (r < 0)
2,461✔
1672
                return r;
1673

1674
        r = serialize_bool_elide(f, "exec-context-private-devices", c->private_devices);
2,461✔
1675
        if (r < 0)
2,461✔
1676
                return r;
1677

1678
        r = serialize_bool_elide(f, "exec-context-protect-kernel-tunables", c->protect_kernel_tunables);
2,461✔
1679
        if (r < 0)
2,461✔
1680
                return r;
1681

1682
        r = serialize_bool_elide(f, "exec-context-protect-kernel-modules", c->protect_kernel_modules);
2,461✔
1683
        if (r < 0)
2,461✔
1684
                return r;
1685

1686
        r = serialize_bool_elide(f, "exec-context-protect-kernel-logs", c->protect_kernel_logs);
2,461✔
1687
        if (r < 0)
2,461✔
1688
                return r;
1689

1690
        r = serialize_bool_elide(f, "exec-context-protect-clock", c->protect_clock);
2,461✔
1691
        if (r < 0)
2,461✔
1692
                return r;
1693

1694
        r = serialize_item(f, "exec-context-protect-control-groups", protect_control_groups_to_string(c->protect_control_groups));
2,461✔
1695
        if (r < 0)
2,461✔
1696
                return r;
1697

1698
        r = serialize_bool_elide(f, "exec-context-private-network", c->private_network);
2,461✔
1699
        if (r < 0)
2,461✔
1700
                return r;
1701

1702
        r = serialize_item(f, "exec-context-private-users", private_users_to_string(c->private_users));
2,461✔
1703
        if (r < 0)
2,461✔
1704
                return r;
1705

1706
        r = serialize_bool_elide(f, "exec-context-private-ipc", c->private_ipc);
2,461✔
1707
        if (r < 0)
2,461✔
1708
                return r;
1709

1710
        r = serialize_item(f, "exec-context-private-pids", private_pids_to_string(c->private_pids));
2,461✔
1711
        if (r < 0)
2,461✔
1712
                return r;
1713

1714
        r = serialize_bool_elide(f, "exec-context-remove-ipc", c->remove_ipc);
2,461✔
1715
        if (r < 0)
2,461✔
1716
                return r;
1717

1718
        r = serialize_item(f, "exec-context-protect-home", protect_home_to_string(c->protect_home));
2,461✔
1719
        if (r < 0)
2,461✔
1720
                return r;
1721

1722
        r = serialize_item(f, "exec-context-protect-system", protect_system_to_string(c->protect_system));
2,461✔
1723
        if (r < 0)
2,461✔
1724
                return r;
1725

1726
        r = serialize_bool_elide(f, "exec-context-same-pgrp", c->same_pgrp);
2,461✔
1727
        if (r < 0)
2,461✔
1728
                return r;
1729

1730
        r = serialize_bool(f, "exec-context-ignore-sigpipe", c->ignore_sigpipe);
2,461✔
1731
        if (r < 0)
2,461✔
1732
                return r;
1733

1734
        r = serialize_bool_elide(f, "exec-context-memory-deny-write-execute", c->memory_deny_write_execute);
2,461✔
1735
        if (r < 0)
2,461✔
1736
                return r;
1737

1738
        r = serialize_bool_elide(f, "exec-context-restrict-realtime", c->restrict_realtime);
2,461✔
1739
        if (r < 0)
2,461✔
1740
                return r;
1741

1742
        r = serialize_bool_elide(f, "exec-context-restrict-suid-sgid", c->restrict_suid_sgid);
2,461✔
1743
        if (r < 0)
2,461✔
1744
                return r;
1745

1746
        r = serialize_item(f, "exec-context-keyring-mode", exec_keyring_mode_to_string(c->keyring_mode));
2,461✔
1747
        if (r < 0)
2,461✔
1748
                return r;
1749

1750
        r = serialize_item(f, "exec-context-protect-hostname", protect_hostname_to_string(c->protect_hostname));
2,461✔
1751
        if (r < 0)
2,461✔
1752
                return r;
1753

1754
        r = serialize_item(f, "exec-context-private-hostname", c->private_hostname);
2,461✔
1755
        if (r < 0)
2,461✔
1756
                return r;
1757

1758
        r = serialize_item(f, "exec-context-protect-proc", protect_proc_to_string(c->protect_proc));
2,461✔
1759
        if (r < 0)
2,461✔
1760
                return r;
1761

1762
        r = serialize_item(f, "exec-context-proc-subset", proc_subset_to_string(c->proc_subset));
2,461✔
1763
        if (r < 0)
2,461✔
1764
                return r;
1765

1766
        r = serialize_item(f, "exec-context-private-bpf", private_bpf_to_string(c->private_bpf));
2,461✔
1767
        if (r < 0)
2,461✔
1768
                return r;
1769

1770
        if (c->bpf_delegate_commands != 0) {
2,461✔
1771
                r = serialize_item_format(f, "exec-context-bpf-delegate-commands", "0x%"PRIx64, c->bpf_delegate_commands);
×
1772
                if (r < 0)
×
1773
                        return r;
1774
        }
1775

1776
        if (c->bpf_delegate_maps != 0) {
2,461✔
1777
                r = serialize_item_format(f, "exec-context-bpf-delegate-maps", "0x%"PRIx64, c->bpf_delegate_maps);
×
1778
                if (r < 0)
×
1779
                        return r;
1780
        }
1781

1782
        if (c->bpf_delegate_programs != 0) {
2,461✔
1783
                r = serialize_item_format(f, "exec-context-bpf-delegate-programs", "0x%"PRIx64, c->bpf_delegate_programs);
×
1784
                if (r < 0)
×
1785
                        return r;
1786
        }
1787

1788
        if (c->bpf_delegate_attachments != 0) {
2,461✔
1789
                r = serialize_item_format(f, "exec-context-bpf-delegate-attachments", "0x%"PRIx64, c->bpf_delegate_attachments);
×
1790
                if (r < 0)
×
1791
                        return r;
1792
        }
1793

1794
        r = serialize_item(f, "exec-context-runtime-directory-preserve-mode", exec_preserve_mode_to_string(c->runtime_directory_preserve_mode));
2,461✔
1795
        if (r < 0)
2,461✔
1796
                return r;
1797

1798
        for (ExecDirectoryType dt = 0; dt < _EXEC_DIRECTORY_TYPE_MAX; dt++) {
14,766✔
1799
                _cleanup_free_ char *key = NULL, *value = NULL;
12,305✔
1800

1801
                key = strjoin("exec-context-directories-", exec_directory_type_to_string(dt));
12,305✔
1802
                if (!key)
12,305✔
1803
                        return log_oom_debug();
×
1804

1805
                if (asprintf(&value, "%04o", c->directories[dt].mode) < 0)
12,305✔
1806
                        return log_oom_debug();
×
1807

1808
                FOREACH_ARRAY(i, c->directories[dt].items, c->directories[dt].n_items) {
12,754✔
1809
                        _cleanup_free_ char *path_escaped = NULL;
449✔
1810

1811
                        path_escaped = shell_escape(i->path, ":" WHITESPACE);
449✔
1812
                        if (!path_escaped)
449✔
1813
                                return log_oom_debug();
×
1814

1815
                        if (!strextend(&value, " ", path_escaped))
449✔
1816
                                return log_oom_debug();
×
1817

1818
                        if (!strextend(&value, ":", yes_no(FLAGS_SET(i->flags, EXEC_DIRECTORY_ONLY_CREATE))))
893✔
1819
                                return log_oom_debug();
×
1820

1821
                        if (!strextend(&value, ":", yes_no(FLAGS_SET(i->flags, EXEC_DIRECTORY_READ_ONLY))))
896✔
1822
                                return log_oom_debug();
×
1823

1824
                        STRV_FOREACH(d, i->symlinks) {
455✔
1825
                                _cleanup_free_ char *link_escaped = NULL;
6✔
1826

1827
                                link_escaped = shell_escape(*d, ":" WHITESPACE);
6✔
1828
                                if (!link_escaped)
6✔
1829
                                        return log_oom_debug();
×
1830

1831
                                if (!strextend(&value, ":", link_escaped))
6✔
1832
                                        return log_oom_debug();
×
1833
                        }
1834
                }
1835

1836
                r = serialize_item(f, key, value);
12,305✔
1837
                if (r < 0)
12,305✔
1838
                        return r;
1839

1840
                if (c->directories[dt].exec_quota.quota_enforce) {
12,305✔
1841
                        _cleanup_free_ char *key_quota = NULL;
×
1842
                        key_quota = strjoin("exec-context-quota-directories-", exec_directory_type_to_string(dt));
×
1843
                        if (!key_quota)
×
1844
                                return log_oom_debug();
×
1845

1846
                        r = serialize_item_format(f, key_quota, "%" PRIu64 " %" PRIu32, c->directories[dt].exec_quota.quota_absolute,
×
1847
                                                                                        c->directories[dt].exec_quota.quota_scale);
×
1848
                        if (r < 0)
×
1849
                                return r;
1850

1851
                } else if (c->directories[dt].exec_quota.quota_accounting) {
12,305✔
1852
                        _cleanup_free_ char *key_quota = NULL;
×
1853
                        key_quota = strjoin("exec-context-quota-accounting-directories-", exec_directory_type_to_string(dt));
×
1854
                        if (!key_quota)
×
1855
                                return log_oom_debug();
×
1856

1857
                        r = serialize_bool(f, key_quota, c->directories[dt].exec_quota.quota_accounting);
×
1858
                        if (r < 0)
×
1859
                                return r;
1860
                }
1861
        }
1862

1863
        r = serialize_usec(f, "exec-context-timeout-clean-usec", c->timeout_clean_usec);
2,461✔
1864
        if (r < 0)
2,461✔
1865
                return r;
1866

1867
        if (c->nice_set) {
2,461✔
1868
                r = serialize_item_format(f, "exec-context-nice", "%i", c->nice);
3✔
1869
                if (r < 0)
3✔
1870
                        return r;
1871
        }
1872

1873
        if (c->oom_score_adjust_set) {
2,461✔
1874
                r = serialize_item_format(f, "exec-context-oom-score-adjust", "%i", c->oom_score_adjust);
631✔
1875
                if (r < 0)
631✔
1876
                        return r;
1877
        }
1878

1879
        if (c->coredump_filter_set) {
2,461✔
1880
                r = serialize_item_format(f, "exec-context-coredump-filter", "%"PRIx64, c->coredump_filter);
×
1881
                if (r < 0)
×
1882
                        return r;
1883
        }
1884

1885
        for (unsigned i = 0; i < RLIM_NLIMITS; i++) {
41,837✔
1886
                _cleanup_free_ char *key = NULL, *limit = NULL;
4,916✔
1887

1888
                if (!c->rlimit[i])
39,376✔
1889
                        continue;
34,460✔
1890

1891
                key = strjoin("exec-context-limit-", rlimit_to_string(i));
4,916✔
1892
                if (!key)
4,916✔
1893
                        return log_oom_debug();
×
1894

1895
                r = rlimit_format(c->rlimit[i], &limit);
4,916✔
1896
                if (r < 0)
4,916✔
1897
                        return r;
1898

1899
                r = serialize_item(f, key, limit);
4,916✔
1900
                if (r < 0)
4,916✔
1901
                        return r;
1902
        }
1903

1904
        if (c->ioprio_is_set) {
2,461✔
1905
                r = serialize_item_format(f, "exec-context-ioprio", "%d", c->ioprio);
6✔
1906
                if (r < 0)
6✔
1907
                        return r;
1908
        }
1909

1910
        if (c->cpu_sched_set) {
2,461✔
1911
                _cleanup_free_ char *policy_str = NULL;
×
1912

1913
                r = sched_policy_to_string_alloc(c->cpu_sched_policy, &policy_str);
×
1914
                if (r < 0)
×
1915
                        return r;
1916

1917
                r = serialize_item(f, "exec-context-cpu-scheduling-policy", policy_str);
×
1918
                if (r < 0)
×
1919
                        return r;
1920

1921
                r = serialize_item_format(f, "exec-context-cpu-scheduling-priority", "%i", c->cpu_sched_priority);
×
1922
                if (r < 0)
×
1923
                        return r;
1924

1925
                r = serialize_bool_elide(f, "exec-context-cpu-scheduling-reset-on-fork", c->cpu_sched_reset_on_fork);
×
1926
                if (r < 0)
×
1927
                        return r;
1928
        }
1929

1930
        if (c->cpu_set.set) {
2,461✔
1931
                _cleanup_free_ char *affinity = NULL;
×
1932

1933
                affinity = cpu_set_to_range_string(&c->cpu_set);
×
1934
                if (!affinity)
×
1935
                        return log_oom_debug();
×
1936

1937
                r = serialize_item(f, "exec-context-cpu-affinity", affinity);
×
1938
                if (r < 0)
×
1939
                        return r;
1940
        }
1941

1942
        if (mpol_is_valid(numa_policy_get_type(&c->numa_policy))) {
2,461✔
1943
                _cleanup_free_ char *nodes = NULL;
×
1944

1945
                nodes = cpu_set_to_range_string(&c->numa_policy.nodes);
×
1946
                if (!nodes)
×
1947
                        return log_oom_debug();
×
1948

1949
                if (nodes) {
×
1950
                        r = serialize_item(f, "exec-context-numa-mask", nodes);
×
1951
                        if (r < 0)
×
1952
                                return r;
1953
                }
1954

1955
                r = serialize_item_format(f, "exec-context-numa-policy", "%d", c->numa_policy.type);
×
1956
                if (r < 0)
×
1957
                        return r;
1958
        }
1959

1960
        r = serialize_bool_elide(f, "exec-context-cpu-affinity-from-numa", c->cpu_affinity_from_numa);
2,461✔
1961
        if (r < 0)
2,461✔
1962
                return r;
1963

1964
        if (c->timer_slack_nsec != NSEC_INFINITY) {
2,461✔
1965
                r = serialize_item_format(f, "exec-context-timer-slack-nsec", NSEC_FMT, c->timer_slack_nsec);
×
1966
                if (r < 0)
×
1967
                        return r;
1968
        }
1969

1970
        r = serialize_bool_elide(f, "exec-context-root-directory-as-fd", c->root_directory_as_fd);
2,461✔
1971
        if (r < 0)
2,461✔
1972
                return r;
1973

1974
        r = serialize_item(f, "exec-context-std-input", exec_input_to_string(c->std_input));
2,461✔
1975
        if (r < 0)
2,461✔
1976
                return r;
1977

1978
        r = serialize_item(f, "exec-context-std-output", exec_output_to_string(c->std_output));
2,461✔
1979
        if (r < 0)
2,461✔
1980
                return r;
1981

1982
        r = serialize_item(f, "exec-context-std-error", exec_output_to_string(c->std_error));
2,461✔
1983
        if (r < 0)
2,461✔
1984
                return r;
1985

1986
        r = serialize_bool_elide(f, "exec-context-stdio-as-fds", c->stdio_as_fds);
2,461✔
1987
        if (r < 0)
2,461✔
1988
                return r;
1989

1990
        switch (c->std_input) {
2,461✔
1991

1992
        case EXEC_INPUT_NAMED_FD:
×
1993
                r = serialize_item(f, "exec-context-std-input-fd-name", c->stdio_fdname[STDIN_FILENO]);
×
1994
                break;
1995

1996
        case EXEC_INPUT_FILE:
×
1997
                r = serialize_item_escaped(f, "exec-context-std-input-file", c->stdio_file[STDIN_FILENO]);
×
1998
                break;
1999

2000
        case EXEC_INPUT_DATA:
×
2001
                r = serialize_item_base64mem(f, "exec-context-std-input-data", c->stdin_data, c->stdin_data_size);
×
2002
                break;
2003

2004
        default:
2005
                r = 0;
2006
        }
2007
        if (r < 0)
×
2008
                return r;
2009

2010
        switch (c->std_output) {
2,461✔
2011

2012
        case EXEC_OUTPUT_NAMED_FD:
×
2013
                r = serialize_item(f, "exec-context-std-output-fd-name", c->stdio_fdname[STDOUT_FILENO]);
×
2014
                break;
2015

2016
        case EXEC_OUTPUT_FILE:
2✔
2017
        case EXEC_OUTPUT_FILE_APPEND:
2018
        case EXEC_OUTPUT_FILE_TRUNCATE:
2019
                r = serialize_item_escaped(f, "exec-context-std-output-file", c->stdio_file[STDOUT_FILENO]);
2✔
2020
                break;
2021

2022
        default:
2023
                r = 0;
2024
        }
2025
        if (r < 0)
2✔
2026
                return r;
2027

2028

2029
        switch (c->std_error) {
2,461✔
2030

2031
        case EXEC_OUTPUT_NAMED_FD:
×
2032
                r = serialize_item(f, "exec-context-std-error-fd-name", c->stdio_fdname[STDERR_FILENO]);
×
2033
                break;
2034

2035
        case EXEC_OUTPUT_FILE:
×
2036
        case EXEC_OUTPUT_FILE_APPEND:
2037
        case EXEC_OUTPUT_FILE_TRUNCATE:
2038
                r = serialize_item_escaped(f, "exec-context-std-error-file", c->stdio_file[STDERR_FILENO]);
×
2039
                break;
2040

2041
        default:
2042
                r = 0;
2043
        }
2044
        if (r < 0)
×
2045
                return r;
2046

2047
        r = serialize_item(f, "exec-context-tty-path", c->tty_path);
2,461✔
2048
        if (r < 0)
2,461✔
2049
                return r;
2050

2051
        r = serialize_bool_elide(f, "exec-context-tty-reset", c->tty_reset);
2,461✔
2052
        if (r < 0)
2,461✔
2053
                return r;
2054

2055
        r = serialize_bool_elide(f, "exec-context-tty-vhangup", c->tty_vhangup);
2,461✔
2056
        if (r < 0)
2,461✔
2057
                return r;
2058

2059
        r = serialize_bool_elide(f, "exec-context-tty-vt-disallocate", c->tty_vt_disallocate);
2,461✔
2060
        if (r < 0)
2,461✔
2061
                return r;
2062

2063
        r = serialize_item_format(f, "exec-context-tty-rows", "%u", c->tty_rows);
2,461✔
2064
        if (r < 0)
2,461✔
2065
                return r;
2066

2067
        r = serialize_item_format(f, "exec-context-tty-columns", "%u", c->tty_cols);
2,461✔
2068
        if (r < 0)
2,461✔
2069
                return r;
2070

2071
        r = serialize_item_format(f, "exec-context-syslog-priority", "%i", c->syslog_priority);
2,461✔
2072
        if (r < 0)
2,461✔
2073
                return r;
2074

2075
        r = serialize_bool(f, "exec-context-syslog-level-prefix", c->syslog_level_prefix);
2,461✔
2076
        if (r < 0)
2,461✔
2077
                return r;
2078

2079
        r = serialize_item(f, "exec-context-syslog-identifier", c->syslog_identifier);
2,461✔
2080
        if (r < 0)
2,461✔
2081
                return r;
2082

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

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

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

2101
        r = serialize_string_set(f, "exec-context-log-filter-allowed-patterns", c->log_filter_allowed_patterns);
2,461✔
2102
        if (r < 0)
2,461✔
2103
                return r;
2104

2105
        r = serialize_string_set(f, "exec-context-log-filter-denied-patterns", c->log_filter_denied_patterns);
2,461✔
2106
        if (r < 0)
2,461✔
2107
                return r;
2108

2109
        FOREACH_ARRAY(field, c->log_extra_fields, c->n_log_extra_fields) {
2,796✔
2110
                r = serialize_item(f, "exec-context-log-extra-fields", field->iov_base);
335✔
2111
                if (r < 0)
335✔
2112
                        return r;
2113
        }
2114

2115
        r = serialize_item(f, "exec-context-log-namespace", c->log_namespace);
2,461✔
2116
        if (r < 0)
2,461✔
2117
                return r;
2118

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

2125
        if (c->capability_bounding_set != CAP_MASK_UNSET) {
2,461✔
2126
                r = serialize_item_format(f, "exec-context-capability-bounding-set", "%" PRIu64, c->capability_bounding_set);
2,461✔
2127
                if (r < 0)
2,461✔
2128
                        return r;
2129
        }
2130

2131
        if (c->capability_ambient_set != 0) {
2,461✔
2132
                r = serialize_item_format(f, "exec-context-capability-ambient-set", "%" PRIu64, c->capability_ambient_set);
69✔
2133
                if (r < 0)
69✔
2134
                        return r;
2135
        }
2136

2137
        if (c->user) {
2,461✔
2138
                r = serialize_item(f, "exec-context-user", c->user);
200✔
2139
                if (r < 0)
200✔
2140
                        return r;
2141
        }
2142

2143
        r = serialize_item(f, "exec-context-group", c->group);
2,461✔
2144
        if (r < 0)
2,461✔
2145
                return r;
2146

2147
        r = serialize_bool_elide(f, "exec-context-dynamic-user", c->dynamic_user);
2,461✔
2148
        if (r < 0)
2,461✔
2149
                return r;
2150

2151
        r = serialize_strv(f, "exec-context-supplementary-groups", c->supplementary_groups);
2,461✔
2152
        if (r < 0)
2,461✔
2153
                return r;
2154

2155
        r = serialize_item_tristate(f, "exec-context-set-login-environment", c->set_login_environment);
2,461✔
2156
        if (r < 0)
×
2157
                return r;
2158

2159
        r = serialize_item(f, "exec-context-pam-name", c->pam_name);
2,461✔
2160
        if (r < 0)
2,461✔
2161
                return r;
2162

2163
        r = serialize_strv(f, "exec-context-read-write-paths", c->read_write_paths);
2,461✔
2164
        if (r < 0)
2,461✔
2165
                return r;
2166

2167
        r = serialize_strv(f, "exec-context-read-only-paths", c->read_only_paths);
2,461✔
2168
        if (r < 0)
2,461✔
2169
                return r;
2170

2171
        r = serialize_strv(f, "exec-context-inaccessible-paths", c->inaccessible_paths);
2,461✔
2172
        if (r < 0)
2,461✔
2173
                return r;
2174

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

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

2183
        r = serialize_strv(f, "exec-context-exec-search-path", c->exec_search_path);
2,461✔
2184
        if (r < 0)
2,461✔
2185
                return r;
2186

2187
        r = serialize_item_format(f, "exec-context-mount-propagation-flag", "%lu", c->mount_propagation_flag);
2,461✔
2188
        if (r < 0)
2,461✔
2189
                return r;
2190

2191
        FOREACH_ARRAY(mount, c->bind_mounts, c->n_bind_mounts) {
2,560✔
2192
                _cleanup_free_ char *src_escaped = NULL, *dst_escaped = NULL;
99✔
2193

2194
                src_escaped = shell_escape(mount->source, ":" WHITESPACE);
99✔
2195
                if (!src_escaped)
99✔
2196
                        return log_oom_debug();
×
2197

2198
                dst_escaped = shell_escape(mount->destination, ":" WHITESPACE);
99✔
2199
                if (!dst_escaped)
99✔
2200
                        return log_oom_debug();
×
2201

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

2213
        FOREACH_ARRAY(tmpfs, c->temporary_filesystems, c->n_temporary_filesystems) {
2,482✔
2214
                _cleanup_free_ char *escaped = NULL;
21✔
2215

2216
                if (!isempty(tmpfs->options)) {
21✔
2217
                        escaped = shell_escape(tmpfs->options, ":");
×
2218
                        if (!escaped)
×
2219
                                return log_oom_debug();
×
2220
                }
2221

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

2230
        r = serialize_item(f, "exec-context-utmp-id", c->utmp_id);
2,461✔
2231
        if (r < 0)
2,461✔
2232
                return r;
2233

2234
        r = serialize_item(f, "exec-context-utmp-mode", exec_utmp_mode_to_string(c->utmp_mode));
2,461✔
2235
        if (r < 0)
2,461✔
2236
                return r;
2237

2238
        r = serialize_bool_elide(f, "exec-context-no-new-privileges", c->no_new_privileges);
2,461✔
2239
        if (r < 0)
2,461✔
2240
                return r;
2241

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

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

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

2269
        if (c->personality != PERSONALITY_INVALID) {
2,461✔
2270
                r = serialize_item(f, "exec-context-personality", personality_to_string(c->personality));
×
2271
                if (r < 0)
×
2272
                        return r;
2273
        }
2274

2275
        r = serialize_bool_elide(f, "exec-context-lock-personality", c->lock_personality);
2,461✔
2276
        if (r < 0)
2,461✔
2277
                return r;
2278

2279
#if HAVE_SECCOMP
2280
        if (!hashmap_isempty(c->syscall_filter)) {
2,461✔
2281
                void *errno_num, *id;
260✔
2282
                HASHMAP_FOREACH_KEY(errno_num, id, c->syscall_filter) {
99,908✔
2283
                        r = serialize_item_format(f, "exec-context-syscall-filter", "%d %d", PTR_TO_INT(id) - 1, PTR_TO_INT(errno_num));
99,648✔
2284
                        if (r < 0)
99,648✔
2285
                                return r;
×
2286
                }
2287
        }
2288

2289
        if (!set_isempty(c->syscall_archs)) {
2,461✔
2290
                void *id;
258✔
2291
                SET_FOREACH(id, c->syscall_archs) {
516✔
2292
                        r = serialize_item_format(f, "exec-context-syscall-archs", "%u", PTR_TO_UINT(id) - 1);
258✔
2293
                        if (r < 0)
258✔
2294
                                return r;
×
2295
                }
2296
        }
2297

2298
        if (c->syscall_errno > 0) {
2,461✔
2299
                r = serialize_item_format(f, "exec-context-syscall-errno", "%d", c->syscall_errno);
2,461✔
2300
                if (r < 0)
2,461✔
2301
                        return r;
2302
        }
2303

2304
        r = serialize_bool_elide(f, "exec-context-syscall-allow-list", c->syscall_allow_list);
2,461✔
2305
        if (r < 0)
2,461✔
2306
                return r;
2307

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

2317
        r = serialize_bool_elide(f, "exec-context-syscall-log-allow-list", c->syscall_log_allow_list);
2,461✔
2318
        if (r < 0)
2,461✔
2319
                return r;
2320
#endif
2321

2322
        if (c->restrict_namespaces != NAMESPACE_FLAGS_INITIAL) {
2,461✔
2323
                r = serialize_item_format(f, "exec-context-restrict-namespaces", "%lu", c->restrict_namespaces);
206✔
2324
                if (r < 0)
206✔
2325
                        return r;
2326
        }
2327

2328
        if (c->delegate_namespaces != NAMESPACE_FLAGS_INITIAL) {
2,461✔
2329
                r = serialize_item_format(f, "exec-context-delegate-namespaces", "%lu", c->delegate_namespaces);
37✔
2330
                if (r < 0)
37✔
2331
                        return r;
2332
        }
2333

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

2344
        r = serialize_bool_elide(f, "exec-context-restrict-filesystems-allow-list", c->restrict_filesystems_allow_list);
2,461✔
2345
        if (r < 0)
2,461✔
2346
                return r;
2347
#endif
2348

2349
        if (!set_isempty(c->address_families)) {
2,461✔
2350
                void *afp;
256✔
2351

2352
                SET_FOREACH(afp, c->address_families) {
1,254✔
2353
                        int af = PTR_TO_INT(afp);
998✔
2354

2355
                        if (af <= 0 || af >= af_max())
998✔
2356
                                continue;
×
2357

2358
                        r = serialize_item_format(f, "exec-context-address-families", "%d", af);
998✔
2359
                        if (r < 0)
998✔
2360
                                return r;
×
2361
                }
2362
        }
2363

2364
        r = serialize_bool_elide(f, "exec-context-address-families-allow-list", c->address_families_allow_list);
2,461✔
2365
        if (r < 0)
2,461✔
2366
                return r;
2367

2368
        r = serialize_item(f, "exec-context-user-namespace-path", c->user_namespace_path);
2,461✔
2369
        if (r < 0)
2,461✔
2370
                return r;
2371

2372
        r = serialize_item(f, "exec-context-network-namespace-path", c->network_namespace_path);
2,461✔
2373
        if (r < 0)
2,461✔
2374
                return r;
2375

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

2380
        FOREACH_ARRAY(mount, c->mount_images, c->n_mount_images) {
2,463✔
2381
                _cleanup_free_ char *s = NULL, *source_escaped = NULL, *dest_escaped = NULL;
2✔
2382

2383
                source_escaped = shell_escape(mount->source, WHITESPACE);
2✔
2384
                if (!source_escaped)
2✔
2385
                        return log_oom_debug();
×
2386

2387
                dest_escaped = shell_escape(mount->destination, WHITESPACE);
2✔
2388
                if (!dest_escaped)
2✔
2389
                        return log_oom_debug();
×
2390

2391
                s = strjoin(mount->ignore_enoent ? "-" : "",
4✔
2392
                            source_escaped,
2393
                            " ",
2394
                            dest_escaped);
2395
                if (!s)
2✔
2396
                        return log_oom_debug();
×
2397

2398
                r = serialize_mount_options(mount->mount_options, &s);
2✔
2399
                if (r < 0)
2✔
2400
                        return r;
2401

2402
                r = serialize_item(f, "exec-context-mount-image", s);
2✔
2403
                if (r < 0)
2✔
2404
                        return r;
2405
        }
2406

2407
        FOREACH_ARRAY(mount, c->extension_images, c->n_extension_images) {
2,481✔
2408
                _cleanup_free_ char *s = NULL, *source_escaped = NULL;
20✔
2409

2410
                source_escaped = shell_escape(mount->source, ":" WHITESPACE);
20✔
2411
                if (!source_escaped)
20✔
2412
                        return log_oom_debug();
×
2413

2414
                s = strjoin(mount->ignore_enoent ? "-" : "",
40✔
2415
                            source_escaped);
2416
                if (!s)
20✔
2417
                        return log_oom_debug();
×
2418

2419
                r = serialize_mount_options(mount->mount_options, &s);
20✔
2420
                if (r < 0)
20✔
2421
                        return r;
2422

2423
                r = serialize_item(f, "exec-context-extension-image", s);
20✔
2424
                if (r < 0)
20✔
2425
                        return r;
2426
        }
2427

2428
        r = serialize_strv(f, "exec-context-extension-directories", c->extension_directories);
2,461✔
2429
        if (r < 0)
2,461✔
2430
                return r;
2431

2432
        ExecSetCredential *sc;
2,461✔
2433
        HASHMAP_FOREACH(sc, c->set_credentials) {
2,467✔
2434
                _cleanup_free_ char *data = NULL;
6✔
2435

2436
                if (base64mem(sc->data, sc->size, &data) < 0)
6✔
2437
                        return log_oom_debug();
×
2438

2439
                r = serialize_item_format(f, "exec-context-set-credentials", "%s %s %s", sc->id, data, yes_no(sc->encrypted));
12✔
2440
                if (r < 0)
6✔
2441
                        return r;
2442
        }
2443

2444
        ExecLoadCredential *lc;
2,461✔
2445
        HASHMAP_FOREACH(lc, c->load_credentials) {
2,472✔
2446
                r = serialize_item_format(f, "exec-context-load-credentials", "%s %s %s", lc->id, lc->path, yes_no(lc->encrypted));
21✔
2447
                if (r < 0)
11✔
2448
                        return r;
×
2449
        }
2450

2451
        ExecImportCredential *ic;
2,461✔
2452
        ORDERED_SET_FOREACH(ic, c->import_credentials) {
3,410✔
2453
                r = serialize_item_format(f, "exec-context-import-credentials", "%s%s%s",
1,848✔
2454
                                          ic->glob,
2455
                                          ic->rename ? " " : "",
2456
                                          strempty(ic->rename));
949✔
2457
                if (r < 0)
949✔
2458
                        return r;
×
2459
        }
2460

2461
        r = serialize_image_policy(f, "exec-context-root-image-policy", c->root_image_policy);
2,461✔
2462
        if (r < 0)
2,461✔
2463
                return r;
2464

2465
        r = serialize_image_policy(f, "exec-context-mount-image-policy", c->mount_image_policy);
2,461✔
2466
        if (r < 0)
2,461✔
2467
                return r;
2468

2469
        r = serialize_image_policy(f, "exec-context-extension-image-policy", c->extension_image_policy);
2,461✔
2470
        if (r < 0)
2,461✔
2471
                return r;
2472

2473
        fputc('\n', f); /* End marker */
2,461✔
2474

2475
        return 0;
2476
}
2477

2478
static int exec_context_deserialize(ExecContext *c, FILE *f) {
10,009✔
2479
        int r;
10,009✔
2480

2481
        assert(f);
10,009✔
2482

2483
        if (!c)
10,009✔
2484
                return 0;
2485

2486
        for (;;) {
969,745✔
2487
                _cleanup_free_ char *l = NULL;
959,736✔
2488
                const char *val;
969,745✔
2489

2490
                r = deserialize_read_line(f, &l);
969,745✔
2491
                if (r < 0)
969,745✔
2492
                        return r;
2493
                if (r == 0) /* eof or end marker */
969,745✔
2494
                        break;
2495

2496
                if ((val = startswith(l, "exec-context-environment="))) {
959,736✔
2497
                        r = deserialize_strv(val, &c->environment);
3,824✔
2498
                        if (r < 0)
3,824✔
2499
                                return r;
2500
                } else if ((val = startswith(l, "exec-context-environment-files="))) {
955,912✔
2501
                        r = deserialize_strv(val, &c->environment_files);
343✔
2502
                        if (r < 0)
343✔
2503
                                return r;
2504
                } else if ((val = startswith(l, "exec-context-pass-environment="))) {
955,569✔
2505
                        r = deserialize_strv(val, &c->pass_environment);
314✔
2506
                        if (r < 0)
314✔
2507
                                return r;
2508
                } else if ((val = startswith(l, "exec-context-unset-environment="))) {
955,255✔
2509
                        r = deserialize_strv(val, &c->unset_environment);
970✔
2510
                        if (r < 0)
970✔
2511
                                return r;
2512
                } else if ((val = startswith(l, "exec-context-working-directory="))) {
954,285✔
2513
                        ssize_t k;
762✔
2514
                        char *p;
762✔
2515

2516
                        k = cunescape(val, 0, &p);
762✔
2517
                        if (k < 0)
762✔
2518
                                return k;
×
2519
                        free_and_replace(c->working_directory, p);
762✔
2520
                } else if ((val = startswith(l, "exec-context-root-directory="))) {
953,523✔
2521
                        ssize_t k;
7✔
2522
                        char *p;
7✔
2523

2524
                        k = cunescape(val, 0, &p);
7✔
2525
                        if (k < 0)
7✔
2526
                                return k;
×
2527
                        free_and_replace(c->root_directory, p);
7✔
2528
                } else if ((val = startswith(l, "exec-context-root-image="))) {
953,516✔
2529
                        ssize_t k;
11✔
2530
                        char *p;
11✔
2531

2532
                        k = cunescape(val, 0, &p);
11✔
2533
                        if (k < 0)
11✔
2534
                                return k;
×
2535
                        free_and_replace(c->root_image, p);
11✔
2536
                } else if ((val = startswith(l, "exec-context-root-image-options="))) {
953,505✔
2537
                        _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
×
2538

2539
                        r = deserialize_mount_options(val, &options);
1✔
2540
                        if (r < 0)
1✔
2541
                                return r;
×
2542

2543
                        free_and_replace_full(c->root_image_options, options, mount_options_free_all);
1✔
2544
                } else if ((val = startswith(l, "exec-context-root-verity="))) {
953,504✔
2545
                        r = free_and_strdup(&c->root_verity, val);
×
2546
                        if (r < 0)
×
2547
                                return r;
2548
                } else if ((val = startswith(l, "exec-context-root-hash-path="))) {
953,504✔
2549
                        r = free_and_strdup(&c->root_hash_path, val);
×
2550
                        if (r < 0)
×
2551
                                return r;
2552
                } else if ((val = startswith(l, "exec-context-root-hash-sig-path="))) {
953,504✔
2553
                        r = free_and_strdup(&c->root_hash_sig_path, val);
×
2554
                        if (r < 0)
×
2555
                                return r;
2556
                } else if ((val = startswith(l, "exec-context-root-hash="))) {
953,504✔
2557
                        iovec_done(&c->root_hash);
4✔
2558
                        r = unhexmem(val, &c->root_hash.iov_base, &c->root_hash.iov_len);
4✔
2559
                        if (r < 0)
4✔
2560
                                return r;
2561
                } else if ((val = startswith(l, "exec-context-root-hash-sig="))) {
953,500✔
2562
                        iovec_done(&c->root_hash_sig);
×
2563
                        r = unbase64mem(val, &c->root_hash_sig.iov_base, &c->root_hash_sig.iov_len);
×
2564
                        if (r < 0)
×
2565
                                return r;
2566
                } else if ((val = startswith(l, "exec-context-root-ephemeral="))) {
953,500✔
2567
                        r = parse_boolean(val);
×
2568
                        if (r < 0)
×
2569
                                return r;
2570
                        c->root_ephemeral = r;
×
2571
                } else if ((val = startswith(l, "exec-context-umask="))) {
953,500✔
2572
                        r = parse_mode(val, &c->umask);
10,009✔
2573
                        if (r < 0)
10,009✔
2574
                                return r;
2575
                } else if ((val = startswith(l, "exec-context-private-non-blocking="))) {
943,491✔
2576
                        r = parse_boolean(val);
×
2577
                        if (r < 0)
×
2578
                                return r;
2579
                        c->non_blocking = r;
×
2580
                } else if ((val = startswith(l, "exec-context-private-mounts="))) {
943,491✔
2581
                        r = safe_atoi(val, &c->private_mounts);
139✔
2582
                        if (r < 0)
139✔
2583
                                return r;
2584
                } else if ((val = startswith(l, "exec-context-mount-api-vfs="))) {
943,352✔
2585
                        r = safe_atoi(val, &c->mount_apivfs);
29✔
2586
                        if (r < 0)
29✔
2587
                                return r;
2588
                } else if ((val = startswith(l, "exec-context-bind-log-sockets="))) {
943,323✔
2589
                        r = safe_atoi(val, &c->bind_log_sockets);
2✔
2590
                        if (r < 0)
2✔
2591
                                return r;
2592
                } else if ((val = startswith(l, "exec-context-memory-ksm="))) {
943,321✔
2593
                        r = safe_atoi(val, &c->memory_ksm);
×
2594
                        if (r < 0)
×
2595
                                return r;
2596
                } else if ((val = startswith(l, "exec-context-memory-thp="))) {
943,321✔
2597
                        c->memory_thp = memory_thp_from_string(val);
10,009✔
2598
                        if (c->memory_thp < 0)
10,009✔
2599
                                return c->memory_thp;
2600
                } else if ((val = startswith(l, "exec-context-private-tmp="))) {
933,312✔
2601
                        c->private_tmp = private_tmp_from_string(val);
10,009✔
2602
                        if (c->private_tmp < 0)
10,009✔
2603
                                return c->private_tmp;
2604
                } else if ((val = startswith(l, "exec-context-private-var-tmp="))) {
923,303✔
2605
                        c->private_var_tmp = private_tmp_from_string(val);
10,009✔
2606
                        if (c->private_var_tmp < 0)
10,009✔
2607
                                return c->private_var_tmp;
2608
                } else if ((val = startswith(l, "exec-context-private-devices="))) {
913,294✔
2609
                        r = parse_boolean(val);
494✔
2610
                        if (r < 0)
494✔
2611
                                return r;
2612
                        c->private_devices = r;
494✔
2613
                } else if ((val = startswith(l, "exec-context-protect-kernel-tunables="))) {
912,800✔
2614
                        r = parse_boolean(val);
312✔
2615
                        if (r < 0)
312✔
2616
                                return r;
2617
                        c->protect_kernel_tunables = r;
312✔
2618
                } else if ((val = startswith(l, "exec-context-protect-kernel-modules="))) {
912,488✔
2619
                        r = parse_boolean(val);
1,106✔
2620
                        if (r < 0)
1,106✔
2621
                                return r;
2622
                        c->protect_kernel_modules = r;
1,106✔
2623
                } else if ((val = startswith(l, "exec-context-protect-kernel-logs="))) {
911,382✔
2624
                        r = parse_boolean(val);
1,106✔
2625
                        if (r < 0)
1,106✔
2626
                                return r;
2627
                        c->protect_kernel_logs = r;
1,106✔
2628
                } else if ((val = startswith(l, "exec-context-protect-clock="))) {
910,276✔
2629
                        r = parse_boolean(val);
900✔
2630
                        if (r < 0)
900✔
2631
                                return r;
2632
                        c->protect_clock = r;
900✔
2633
                } else if ((val = startswith(l, "exec-context-protect-control-groups="))) {
909,376✔
2634
                        r = protect_control_groups_from_string(val);
10,009✔
2635
                        if (r < 0)
10,009✔
2636
                                return r;
2637
                        c->protect_control_groups = r;
10,009✔
2638
                } else if ((val = startswith(l, "exec-context-private-network="))) {
899,367✔
2639
                        r = parse_boolean(val);
71✔
2640
                        if (r < 0)
71✔
2641
                                return r;
2642
                        c->private_network = r;
71✔
2643
                } else if ((val = startswith(l, "exec-context-private-users="))) {
899,296✔
2644
                        c->private_users = private_users_from_string(val);
10,009✔
2645
                        if (c->private_users < 0)
10,009✔
2646
                                return -EINVAL;
2647
                } else if ((val = startswith(l, "exec-context-private-ipc="))) {
889,287✔
2648
                        r = parse_boolean(val);
6✔
2649
                        if (r < 0)
6✔
2650
                                return r;
2651
                        c->private_ipc = r;
6✔
2652
                } else if ((val = startswith(l, "exec-context-private-pids="))) {
889,281✔
2653
                        c->private_pids = private_pids_from_string(val);
10,009✔
2654
                        if (c->private_pids < 0)
10,009✔
2655
                                return -EINVAL;
2656
                } else if ((val = startswith(l, "exec-context-remove-ipc="))) {
879,272✔
2657
                        r = parse_boolean(val);
56✔
2658
                        if (r < 0)
56✔
2659
                                return r;
2660
                        c->remove_ipc = r;
56✔
2661
                } else if ((val = startswith(l, "exec-context-protect-home="))) {
879,216✔
2662
                        c->protect_home = protect_home_from_string(val);
10,009✔
2663
                        if (c->protect_home < 0)
10,009✔
2664
                                return -EINVAL;
2665
                } else if ((val = startswith(l, "exec-context-protect-system="))) {
869,207✔
2666
                        c->protect_system = protect_system_from_string(val);
10,009✔
2667
                        if (c->protect_system < 0)
10,009✔
2668
                                return -EINVAL;
2669
                } else if ((val = startswith(l, "exec-context-same-pgrp="))) {
859,198✔
2670
                        r = parse_boolean(val);
836✔
2671
                        if (r < 0)
836✔
2672
                                return r;
2673
                        c->same_pgrp = r;
836✔
2674
                } else if ((val = startswith(l, "exec-context-non-blocking="))) {
858,362✔
2675
                        r = parse_boolean(val);
×
2676
                        if (r < 0)
×
2677
                                return r;
2678
                        c->non_blocking = r;
×
2679
                } else if ((val = startswith(l, "exec-context-ignore-sigpipe="))) {
858,362✔
2680
                        r = parse_boolean(val);
10,009✔
2681
                        if (r < 0)
10,009✔
2682
                                return r;
2683
                        c->ignore_sigpipe = r;
10,009✔
2684
                } else if ((val = startswith(l, "exec-context-memory-deny-write-execute="))) {
848,353✔
2685
                        r = parse_boolean(val);
1,470✔
2686
                        if (r < 0)
1,470✔
2687
                                return r;
2688
                        c->memory_deny_write_execute = r;
1,470✔
2689
                } else if ((val = startswith(l, "exec-context-restrict-realtime="))) {
846,883✔
2690
                        r = parse_boolean(val);
1,472✔
2691
                        if (r < 0)
1,472✔
2692
                                return r;
2693
                        c->restrict_realtime = r;
1,472✔
2694
                } else if ((val = startswith(l, "exec-context-restrict-suid-sgid="))) {
845,411✔
2695
                        r = parse_boolean(val);
1,373✔
2696
                        if (r < 0)
1,373✔
2697
                                return r;
2698
                        c->restrict_suid_sgid = r;
1,373✔
2699
                } else if ((val = startswith(l, "exec-context-keyring-mode="))) {
844,038✔
2700
                        c->keyring_mode = exec_keyring_mode_from_string(val);
10,009✔
2701
                        if (c->keyring_mode < 0)
10,009✔
2702
                                return -EINVAL;
2703
                } else if ((val = startswith(l, "exec-context-protect-hostname="))) {
834,029✔
2704
                        c->protect_hostname = protect_hostname_from_string(val);
10,009✔
2705
                        if (c->protect_hostname < 0)
10,009✔
2706
                                return -EINVAL;
2707
                } else if ((val = startswith(l, "exec-context-private-hostname="))) {
824,020✔
2708
                        r = free_and_strdup(&c->private_hostname, val);
5✔
2709
                        if (r < 0)
5✔
2710
                                return r;
2711
                } else if ((val = startswith(l, "exec-context-protect-proc="))) {
824,015✔
2712
                        c->protect_proc = protect_proc_from_string(val);
10,009✔
2713
                        if (c->protect_proc < 0)
10,009✔
2714
                                return -EINVAL;
2715
                } else if ((val = startswith(l, "exec-context-proc-subset="))) {
814,006✔
2716
                        c->proc_subset = proc_subset_from_string(val);
10,009✔
2717
                        if (c->proc_subset < 0)
10,009✔
2718
                                return -EINVAL;
2719
                } else if ((val = startswith(l, "exec-context-private-bpf="))) {
803,997✔
2720
                        c->private_bpf = private_bpf_from_string(val);
10,009✔
2721
                        if (c->private_bpf < 0)
10,009✔
2722
                                return -EINVAL;
2723
                } else if ((val = startswith(l, "exec-context-bpf-delegate-commands="))) {
793,988✔
2724
                        r = safe_atoux64(val, &c->bpf_delegate_commands);
2✔
2725
                        if (r < 0)
2✔
2726
                                return r;
2727
                } else if ((val = startswith(l, "exec-context-bpf-delegate-maps="))) {
793,986✔
2728
                        r = safe_atoux64(val, &c->bpf_delegate_maps);
1✔
2729
                        if (r < 0)
1✔
2730
                                return r;
2731
                } else if ((val = startswith(l, "exec-context-bpf-delegate-programs="))) {
793,985✔
2732
                        r = safe_atoux64(val, &c->bpf_delegate_programs);
1✔
2733
                        if (r < 0)
1✔
2734
                                return r;
2735
                } else if ((val = startswith(l, "exec-context-bpf-delegate-attachments="))) {
793,984✔
2736
                        r = safe_atoux64(val, &c->bpf_delegate_attachments);
1✔
2737
                        if (r < 0)
1✔
2738
                                return r;
2739
                } else if ((val = startswith(l, "exec-context-runtime-directory-preserve-mode="))) {
793,983✔
2740
                        c->runtime_directory_preserve_mode = exec_preserve_mode_from_string(val);
10,009✔
2741
                        if (c->runtime_directory_preserve_mode < 0)
10,009✔
2742
                                return -EINVAL;
2743
                } else if ((val = startswith(l, "exec-context-directories-"))) {
783,974✔
2744
                        _cleanup_free_ char *type = NULL, *mode = NULL;
×
2745
                        ExecDirectoryType dt;
50,045✔
2746

2747
                        r = extract_many_words(&val, "= ", 0, &type, &mode);
50,045✔
2748
                        if (r < 0)
50,045✔
2749
                                return r;
2750
                        if (r == 0 || !mode)
50,045✔
2751
                                return -EINVAL;
2752

2753
                        dt = exec_directory_type_from_string(type);
50,045✔
2754
                        if (dt < 0)
50,045✔
2755
                                return dt;
2756

2757
                        r = parse_mode(mode, &c->directories[dt].mode);
50,045✔
2758
                        if (r < 0)
50,045✔
2759
                                return r;
2760

2761
                        for (;;) {
53,001✔
2762
                                _cleanup_free_ char *tuple = NULL, *path = NULL, *only_create = NULL, *read_only = NULL;
52,894✔
2763
                                ExecDirectoryFlags exec_directory_flags = 0;
53,001✔
2764
                                const char *p;
53,001✔
2765

2766
                                /* Use EXTRACT_UNESCAPE_RELAX here, as we unescape the colons in subsequent calls */
2767
                                r = extract_first_word(&val, &tuple, WHITESPACE, EXTRACT_UNESCAPE_SEPARATORS|EXTRACT_UNESCAPE_RELAX);
53,001✔
2768
                                if (r < 0)
53,001✔
2769
                                        return r;
2770
                                if (r == 0)
53,001✔
2771
                                        break;
2772

2773
                                p = tuple;
2,956✔
2774
                                r = extract_many_words(&p, ":", EXTRACT_UNESCAPE_SEPARATORS, &path, &only_create, &read_only);
2,956✔
2775
                                if (r < 0)
2,956✔
2776
                                        return r;
2777
                                if (r < 2)
2,956✔
2778
                                        continue;
×
2779

2780
                                r = parse_boolean(only_create);
2,956✔
2781
                                if (r < 0)
2,956✔
2782
                                        return r;
2783
                                if (r > 0)
2,956✔
2784
                                        exec_directory_flags |= EXEC_DIRECTORY_ONLY_CREATE;
5✔
2785

2786
                                r = parse_boolean(read_only);
2,956✔
2787
                                if (r < 0)
2,956✔
2788
                                        return r;
2789
                                if (r > 0)
2,956✔
2790
                                        exec_directory_flags |= EXEC_DIRECTORY_READ_ONLY;
50✔
2791

2792
                                r = exec_directory_add(&c->directories[dt], path, /* symlink= */ NULL, exec_directory_flags);
2,956✔
2793
                                if (r < 0)
2,956✔
2794
                                        return r;
2795

2796
                                if (isempty(p))
2,956✔
2797
                                        continue;
2,849✔
2798

2799
                                for (;;) {
385✔
2800
                                        _cleanup_free_ char *link = NULL;
246✔
2801

2802
                                        r = extract_first_word(&p, &link, ":", EXTRACT_UNESCAPE_SEPARATORS);
246✔
2803
                                        if (r < 0)
246✔
2804
                                                return r;
2805
                                        if (r == 0)
246✔
2806
                                                break;
2807

2808
                                        r = strv_consume(&c->directories[dt].items[c->directories[dt].n_items - 1].symlinks, TAKE_PTR(link));
139✔
2809
                                        if (r < 0)
139✔
2810
                                                return r;
2811
                                }
2812
                        }
2813
                } else if ((val = startswith(l, "exec-context-quota-accounting-directories-"))) {
733,929✔
2814
                        _cleanup_free_ char *type = NULL, *quota_accounting = NULL;
×
2815
                        ExecDirectoryType dt;
×
2816

2817
                        r = split_pair(val, "=", &type, &quota_accounting);
×
2818
                        if (r < 0)
×
2819
                                return r;
2820

2821
                        dt = exec_directory_type_from_string(type);
×
2822
                        if (dt < 0)
×
2823
                                return dt;
2824

2825
                        r = parse_boolean(quota_accounting);
×
2826
                        if (r < 0)
×
2827
                                return r;
2828

2829
                        c->directories[dt].exec_quota.quota_accounting = r;
×
2830
                } else if ((val = startswith(l, "exec-context-quota-directories-"))) {
733,929✔
2831
                        _cleanup_free_ char *type = NULL, *quota_info = NULL, *quota_absolute = NULL, *quota_scale = NULL;
×
2832
                        ExecDirectoryType dt;
×
2833

2834
                        r = split_pair(val, "=", &type, &quota_info);
×
2835
                        if (r < 0)
×
2836
                                return r;
2837

2838
                        r = split_pair(quota_info, " ", &quota_absolute, &quota_scale);
×
2839
                        if (r < 0)
×
2840
                                return r;
2841

2842
                        dt = exec_directory_type_from_string(type);
×
2843
                        if (dt < 0)
×
2844
                                return dt;
2845

2846
                        r = safe_atou64(quota_absolute, &c->directories[dt].exec_quota.quota_absolute);
×
2847
                        if (r < 0)
×
2848
                               return r;
2849

2850
                        r = safe_atou32(quota_scale, &c->directories[dt].exec_quota.quota_scale);
×
2851
                        if (r < 0)
×
2852
                               return r;
2853

2854
                        c->directories[dt].exec_quota.quota_enforce = true;
×
2855
                } else if ((val = startswith(l, "exec-context-timeout-clean-usec="))) {
733,929✔
2856
                        r = deserialize_usec(val, &c->timeout_clean_usec);
×
2857
                        if (r < 0)
×
2858
                                return r;
2859
                } else if ((val = startswith(l, "exec-context-nice="))) {
733,929✔
2860
                        r = safe_atoi(val, &c->nice);
19✔
2861
                        if (r < 0)
19✔
2862
                                return r;
2863
                        c->nice_set = true;
19✔
2864
                } else if ((val = startswith(l, "exec-context-working-directory-missing-ok="))) {
733,910✔
2865
                        r = parse_boolean(val);
701✔
2866
                        if (r < 0)
701✔
2867
                                return r;
2868
                        c->working_directory_missing_ok = r;
701✔
2869
                } else if ((val = startswith(l, "exec-context-working-directory-home="))) {
733,209✔
2870
                        r = parse_boolean(val);
179✔
2871
                        if (r < 0)
179✔
2872
                                return r;
2873
                        c->working_directory_home = r;
179✔
2874
                } else if ((val = startswith(l, "exec-context-oom-score-adjust="))) {
733,030✔
2875
                        r = safe_atoi(val, &c->oom_score_adjust);
1,086✔
2876
                        if (r < 0)
1,086✔
2877
                                return r;
2878
                        c->oom_score_adjust_set = true;
1,086✔
2879
                } else if ((val = startswith(l, "exec-context-coredump-filter="))) {
731,944✔
2880
                        r = safe_atoux64(val, &c->coredump_filter);
2✔
2881
                        if (r < 0)
2✔
2882
                                return r;
2883
                        c->coredump_filter_set = true;
2✔
2884
                } else if ((val = startswith(l, "exec-context-limit-"))) {
731,942✔
2885
                        _cleanup_free_ struct rlimit *rlimit = NULL;
×
2886
                        _cleanup_free_ char *limit = NULL;
20,013✔
2887
                        int type;
20,013✔
2888

2889
                        r = extract_first_word(&val, &limit, "=", 0);
20,013✔
2890
                        if (r < 0)
20,013✔
2891
                                return r;
2892
                        if (r == 0 || !val)
20,013✔
2893
                                return -EINVAL;
2894

2895
                        type = rlimit_from_string(limit);
20,013✔
2896
                        if (type < 0)
20,013✔
2897
                                return -EINVAL;
2898

2899
                        if (!c->rlimit[type]) {
20,013✔
2900
                                rlimit = new0(struct rlimit, 1);
20,013✔
2901
                                if (!rlimit)
20,013✔
2902
                                        return log_oom_debug();
×
2903

2904
                                r = rlimit_parse(type, val, rlimit);
20,013✔
2905
                                if (r < 0)
20,013✔
2906
                                        return r;
2907

2908
                                c->rlimit[type] = TAKE_PTR(rlimit);
20,013✔
2909
                        } else {
2910
                                r = rlimit_parse(type, val, c->rlimit[type]);
×
2911
                                if (r < 0)
×
2912
                                        return r;
2913
                        }
2914
                } else if ((val = startswith(l, "exec-context-ioprio="))) {
711,929✔
2915
                        r = safe_atoi(val, &c->ioprio);
12✔
2916
                        if (r < 0)
12✔
2917
                                return r;
2918
                        c->ioprio_is_set = true;
12✔
2919
                } else if ((val = startswith(l, "exec-context-cpu-scheduling-policy="))) {
711,917✔
2920
                        c->cpu_sched_policy = sched_policy_from_string(val);
×
2921
                        if (c->cpu_sched_policy < 0)
×
2922
                                return -EINVAL;
2923
                        c->cpu_sched_set = true;
×
2924
                } else if ((val = startswith(l, "exec-context-cpu-scheduling-priority="))) {
711,917✔
2925
                        r = safe_atoi(val, &c->cpu_sched_priority);
×
2926
                        if (r < 0)
×
2927
                                return r;
2928
                        c->cpu_sched_set = true;
×
2929
                } else if ((val = startswith(l, "exec-context-cpu-scheduling-reset-on-fork="))) {
711,917✔
2930
                        r = parse_boolean(val);
×
2931
                        if (r < 0)
×
2932
                                return r;
2933
                        c->cpu_sched_reset_on_fork = r;
×
2934
                        c->cpu_sched_set = true;
×
2935
                } else if ((val = startswith(l, "exec-context-cpu-affinity="))) {
711,917✔
2936
                        if (c->cpu_set.set)
×
2937
                                return -EINVAL; /* duplicated */
2938

2939
                        r = parse_cpu_set(val, &c->cpu_set);
×
2940
                        if (r < 0)
×
2941
                                return r;
2942
                } else if ((val = startswith(l, "exec-context-numa-mask="))) {
711,917✔
2943
                        if (c->numa_policy.nodes.set)
19✔
2944
                                return -EINVAL; /* duplicated */
2945

2946
                        r = parse_cpu_set(val, &c->numa_policy.nodes);
19✔
2947
                        if (r < 0)
19✔
2948
                                return r;
2949
                } else if ((val = startswith(l, "exec-context-numa-policy="))) {
711,898✔
2950
                        r = safe_atoi(val, &c->numa_policy.type);
19✔
2951
                        if (r < 0)
19✔
2952
                                return r;
2953
                } else if ((val = startswith(l, "exec-context-cpu-affinity-from-numa="))) {
711,879✔
2954
                        r = parse_boolean(val);
2✔
2955
                        if (r < 0)
2✔
2956
                                return r;
2957
                        c->cpu_affinity_from_numa = r;
2✔
2958
                } else if ((val = startswith(l, "exec-context-timer-slack-nsec="))) {
711,877✔
2959
                        r = deserialize_usec(val, (usec_t *)&c->timer_slack_nsec);
×
2960
                        if (r < 0)
×
2961
                                return r;
2962
                } else if ((val = startswith(l, "exec-context-root-directory-as-fd="))) {
711,877✔
2963
                        r = parse_boolean(val);
2✔
2964
                        if (r < 0)
2✔
2965
                                return r;
2966
                        c->root_directory_as_fd = r;
2✔
2967
                } else if ((val = startswith(l, "exec-context-std-input="))) {
711,875✔
2968
                        c->std_input = exec_input_from_string(val);
10,009✔
2969
                        if (c->std_input < 0)
10,009✔
2970
                                return c->std_input;
2971
                } else if ((val = startswith(l, "exec-context-std-output="))) {
701,866✔
2972
                        c->std_output = exec_output_from_string(val);
10,009✔
2973
                        if (c->std_output < 0)
10,009✔
2974
                                return c->std_output;
2975
                } else if ((val = startswith(l, "exec-context-std-error="))) {
691,857✔
2976
                        c->std_error = exec_output_from_string(val);
10,009✔
2977
                        if (c->std_error < 0)
10,009✔
2978
                                return c->std_error;
2979
                } else if ((val = startswith(l, "exec-context-stdio-as-fds="))) {
681,848✔
2980
                        r = parse_boolean(val);
553✔
2981
                        if (r < 0)
553✔
2982
                                return r;
2983
                        c->stdio_as_fds = r;
553✔
2984
                } else if ((val = startswith(l, "exec-context-std-input-data="))) {
681,295✔
2985
                        if (c->stdin_data)
1✔
2986
                                return -EINVAL; /* duplicated */
2987

2988
                        r = unbase64mem(val, &c->stdin_data, &c->stdin_data_size);
1✔
2989
                        if (r < 0)
1✔
2990
                                return r;
2991
                } else if ((val = startswith(l, "exec-context-std-input-fd-name="))) {
681,294✔
2992
                        r = free_and_strdup(&c->stdio_fdname[STDIN_FILENO], val);
×
2993
                        if (r < 0)
×
2994
                                return r;
2995
                } else if ((val = startswith(l, "exec-context-std-output-fd-name="))) {
681,294✔
2996
                        r = free_and_strdup(&c->stdio_fdname[STDOUT_FILENO], val);
×
2997
                        if (r < 0)
×
2998
                                return r;
2999
                } else if ((val = startswith(l, "exec-context-std-error-fd-name="))) {
681,294✔
3000
                        r = free_and_strdup(&c->stdio_fdname[STDERR_FILENO], val);
×
3001
                        if (r < 0)
×
3002
                                return r;
3003
                } else if ((val = startswith(l, "exec-context-std-input-file="))) {
681,294✔
3004
                        ssize_t k;
×
3005
                        char *p;
×
3006

3007
                        k = cunescape(val, 0, &p);
×
3008
                        if (k < 0)
×
3009
                                return k;
×
3010

3011
                        free_and_replace(c->stdio_file[STDIN_FILENO], p);
×
3012

3013
                } else if ((val = startswith(l, "exec-context-std-output-file="))) {
681,294✔
3014
                        ssize_t k;
53✔
3015
                        char *p;
53✔
3016

3017
                        k = cunescape(val, 0, &p);
53✔
3018
                        if (k < 0)
53✔
3019
                                return k;
×
3020

3021
                        free_and_replace(c->stdio_file[STDOUT_FILENO], p);
53✔
3022

3023
                } else if ((val = startswith(l, "exec-context-std-error-file="))) {
681,241✔
3024
                        ssize_t k;
49✔
3025
                        char *p;
49✔
3026

3027
                        k = cunescape(val, 0, &p);
49✔
3028
                        if (k < 0)
49✔
3029
                                return k;
×
3030

3031
                        free_and_replace(c->stdio_file[STDERR_FILENO], p);
49✔
3032

3033
                } else if ((val = startswith(l, "exec-context-tty-path="))) {
681,192✔
3034
                        r = free_and_strdup(&c->tty_path, val);
108✔
3035
                        if (r < 0)
108✔
3036
                                return r;
3037
                } else if ((val = startswith(l, "exec-context-tty-reset="))) {
681,084✔
3038
                        r = parse_boolean(val);
192✔
3039
                        if (r < 0)
192✔
3040
                                return r;
3041
                        c->tty_reset = r;
192✔
3042
                } else if ((val = startswith(l, "exec-context-tty-vhangup="))) {
680,892✔
3043
                        r = parse_boolean(val);
83✔
3044
                        if (r < 0)
83✔
3045
                                return r;
3046
                        c->tty_vhangup = r;
83✔
3047
                } else if ((val = startswith(l, "exec-context-tty-vt-disallocate="))) {
680,809✔
3048
                        r = parse_boolean(val);
46✔
3049
                        if (r < 0)
46✔
3050
                                return r;
3051
                        c->tty_vt_disallocate = r;
46✔
3052
                } else if ((val = startswith(l, "exec-context-tty-rows="))) {
680,763✔
3053
                        r = safe_atou(val, &c->tty_rows);
10,009✔
3054
                        if (r < 0)
10,009✔
3055
                                return r;
3056
                } else if ((val = startswith(l, "exec-context-tty-columns="))) {
670,754✔
3057
                        r = safe_atou(val, &c->tty_cols);
10,009✔
3058
                        if (r < 0)
10,009✔
3059
                                return r;
3060
                } else if ((val = startswith(l, "exec-context-syslog-priority="))) {
660,745✔
3061
                        r = safe_atoi(val, &c->syslog_priority);
10,009✔
3062
                        if (r < 0)
10,009✔
3063
                                return r;
3064
                } else if ((val = startswith(l, "exec-context-syslog-level-prefix="))) {
650,736✔
3065
                        r = parse_boolean(val);
10,009✔
3066
                        if (r < 0)
10,009✔
3067
                                return r;
3068
                        c->syslog_level_prefix = r;
10,009✔
3069
                } else if ((val = startswith(l, "exec-context-syslog-identifier="))) {
640,727✔
3070
                        r = free_and_strdup(&c->syslog_identifier, val);
×
3071
                        if (r < 0)
×
3072
                                return r;
3073
                } else if ((val = startswith(l, "exec-context-log-level-max="))) {
640,727✔
3074
                        /* See comment in serialization. */
3075
                        r = safe_atoi(val, &c->log_level_max);
10,009✔
3076
                        if (r < 0)
10,009✔
3077
                                return r;
3078
                } else if ((val = startswith(l, "exec-context-log-ratelimit-interval-usec="))) {
630,718✔
3079
                        r = deserialize_usec(val, &c->log_ratelimit.interval);
×
3080
                        if (r < 0)
×
3081
                                return r;
3082
                } else if ((val = startswith(l, "exec-context-log-ratelimit-burst="))) {
630,718✔
3083
                        r = safe_atou(val, &c->log_ratelimit.burst);
×
3084
                        if (r < 0)
×
3085
                                return r;
3086
                } else if ((val = startswith(l, "exec-context-log-filter-allowed-patterns="))) {
630,718✔
3087
                        r = set_put_strdup(&c->log_filter_allowed_patterns, val);
20✔
3088
                        if (r < 0)
20✔
3089
                                return r;
3090
                } else if ((val = startswith(l, "exec-context-log-filter-denied-patterns="))) {
630,698✔
3091
                        r = set_put_strdup(&c->log_filter_denied_patterns, val);
13✔
3092
                        if (r < 0)
13✔
3093
                                return r;
3094
                } else if ((val = startswith(l, "exec-context-log-extra-fields="))) {
630,685✔
3095
                        if (!GREEDY_REALLOC(c->log_extra_fields, c->n_log_extra_fields + 1))
706✔
3096
                                return log_oom_debug();
×
3097

3098
                        c->log_extra_fields[c->n_log_extra_fields++].iov_base = strdup(val);
706✔
3099
                        if (!c->log_extra_fields[c->n_log_extra_fields-1].iov_base)
706✔
3100
                                return log_oom_debug();
×
3101
                } else if ((val = startswith(l, "exec-context-log-namespace="))) {
629,979✔
3102
                        r = free_and_strdup(&c->log_namespace, val);
2✔
3103
                        if (r < 0)
2✔
3104
                                return r;
3105
                } else if ((val = startswith(l, "exec-context-secure-bits="))) {
629,977✔
3106
                        r = safe_atoi(val, &c->secure_bits);
×
3107
                        if (r < 0)
×
3108
                                return r;
3109
                } else if ((val = startswith(l, "exec-context-capability-bounding-set="))) {
629,977✔
3110
                        r = safe_atou64(val, &c->capability_bounding_set);
10,009✔
3111
                        if (r < 0)
10,009✔
3112
                                return r;
3113
                } else if ((val = startswith(l, "exec-context-capability-ambient-set="))) {
619,968✔
3114
                        r = safe_atou64(val, &c->capability_ambient_set);
654✔
3115
                        if (r < 0)
654✔
3116
                                return r;
3117
                } else if ((val = startswith(l, "exec-context-user="))) {
619,314✔
3118
                        r = free_and_strdup(&c->user, val);
2,079✔
3119
                        if (r < 0)
2,079✔
3120
                                return r;
3121
                } else if ((val = startswith(l, "exec-context-group="))) {
617,235✔
3122
                        r = free_and_strdup(&c->group, val);
60✔
3123
                        if (r < 0)
60✔
3124
                                return r;
3125
                } else if ((val = startswith(l, "exec-context-dynamic-user="))) {
617,175✔
3126
                        r = parse_boolean(val);
47✔
3127
                        if (r < 0)
47✔
3128
                                return r;
3129
                        c->dynamic_user = r;
47✔
3130
                } else if ((val = startswith(l, "exec-context-supplementary-groups="))) {
617,128✔
3131
                        r = deserialize_strv(val, &c->supplementary_groups);
12✔
3132
                        if (r < 0)
12✔
3133
                                return r;
3134
                } else if ((val = startswith(l, "exec-context-set-login-environment="))) {
617,116✔
3135
                        r = safe_atoi(val, &c->set_login_environment);
×
3136
                        if (r < 0)
×
3137
                                return r;
3138
                } else if ((val = startswith(l, "exec-context-pam-name="))) {
617,116✔
3139
                        r = free_and_strdup(&c->pam_name, val);
511✔
3140
                        if (r < 0)
511✔
3141
                                return r;
3142
                } else if ((val = startswith(l, "exec-context-read-write-paths="))) {
616,605✔
3143
                        r = deserialize_strv(val, &c->read_write_paths);
808✔
3144
                        if (r < 0)
808✔
3145
                                return r;
3146
                } else if ((val = startswith(l, "exec-context-read-only-paths="))) {
615,797✔
3147
                        r = deserialize_strv(val, &c->read_only_paths);
2✔
3148
                        if (r < 0)
2✔
3149
                                return r;
3150
                } else if ((val = startswith(l, "exec-context-inaccessible-paths="))) {
615,795✔
3151
                        r = deserialize_strv(val, &c->inaccessible_paths);
5✔
3152
                        if (r < 0)
5✔
3153
                                return r;
3154
                } else if ((val = startswith(l, "exec-context-exec-paths="))) {
615,790✔
3155
                        r = deserialize_strv(val, &c->exec_paths);
1✔
3156
                        if (r < 0)
1✔
3157
                                return r;
3158
                } else if ((val = startswith(l, "exec-context-no-exec-paths="))) {
615,789✔
3159
                        r = deserialize_strv(val, &c->no_exec_paths);
1✔
3160
                        if (r < 0)
1✔
3161
                                return r;
3162
                } else if ((val = startswith(l, "exec-context-exec-search-path="))) {
615,788✔
3163
                        r = deserialize_strv(val, &c->exec_search_path);
×
3164
                        if (r < 0)
×
3165
                                return r;
3166
                } else if ((val = startswith(l, "exec-context-mount-propagation-flag="))) {
615,788✔
3167
                        r = safe_atolu(val, &c->mount_propagation_flag);
10,009✔
3168
                        if (r < 0)
10,009✔
3169
                                return r;
3170
                } else if ((val = startswith(l, "exec-context-bind-read-only-path="))) {
605,779✔
3171
                        _cleanup_free_ char *source = NULL, *destination = NULL;
7✔
3172
                        bool rbind = true, ignore_enoent = false;
7✔
3173
                        char *s = NULL, *d = NULL;
7✔
3174

3175
                        r = extract_first_word(&val,
7✔
3176
                                               &source,
3177
                                               ":" WHITESPACE,
3178
                                               EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3179
                        if (r < 0)
7✔
3180
                                return r;
3181
                        if (r == 0)
7✔
3182
                                return -EINVAL;
3183

3184
                        s = source;
7✔
3185
                        if (s[0] == '-') {
7✔
3186
                                ignore_enoent = true;
1✔
3187
                                s++;
1✔
3188
                        }
3189

3190
                        if (val && val[-1] == ':') {
7✔
3191
                                r = extract_first_word(&val,
7✔
3192
                                                       &destination,
3193
                                                       ":" WHITESPACE,
3194
                                                       EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3195
                                if (r < 0)
7✔
3196
                                        return r;
3197
                                if (r == 0)
7✔
3198
                                        continue;
×
3199

3200
                                d = destination;
7✔
3201

3202
                                if (val && val[-1] == ':') {
7✔
3203
                                        _cleanup_free_ char *options = NULL;
7✔
3204

3205
                                        r = extract_first_word(&val, &options, NULL, EXTRACT_UNQUOTE);
7✔
3206
                                        if (r < 0)
7✔
3207
                                                return -r;
×
3208

3209
                                        if (isempty(options) || streq(options, "rbind"))
15✔
3210
                                                rbind = true;
3211
                                        else if (streq(options, "norbind"))
1✔
3212
                                                rbind = false;
3213
                                        else
3214
                                                continue;
×
3215
                                }
3216
                        } else
3217
                                d = s;
3218

3219
                        r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts,
14✔
3220
                                        &(BindMount) {
7✔
3221
                                                .source = s,
3222
                                                .destination = d,
3223
                                                .read_only = true,
3224
                                                .recursive = rbind,
3225
                                                .ignore_enoent = ignore_enoent,
3226
                                        });
3227
                        if (r < 0)
7✔
3228
                                return log_oom_debug();
×
3229
                } else if ((val = startswith(l, "exec-context-bind-path="))) {
605,772✔
3230
                        _cleanup_free_ char *source = NULL, *destination = NULL;
20✔
3231
                        bool rbind = true, ignore_enoent = false;
20✔
3232
                        char *s = NULL, *d = NULL;
20✔
3233

3234
                        r = extract_first_word(&val,
20✔
3235
                                               &source,
3236
                                               ":" WHITESPACE,
3237
                                               EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3238
                        if (r < 0)
20✔
3239
                                return r;
3240
                        if (r == 0)
20✔
3241
                                return -EINVAL;
3242

3243
                        s = source;
20✔
3244
                        if (s[0] == '-') {
20✔
3245
                                ignore_enoent = true;
1✔
3246
                                s++;
1✔
3247
                        }
3248

3249
                        if (val && val[-1] == ':') {
20✔
3250
                                r = extract_first_word(&val,
20✔
3251
                                                       &destination,
3252
                                                       ":" WHITESPACE,
3253
                                                       EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3254
                                if (r < 0)
20✔
3255
                                        return r;
3256
                                if (r == 0)
20✔
3257
                                        continue;
×
3258

3259
                                d = destination;
20✔
3260

3261
                                if (val && val[-1] == ':') {
20✔
3262
                                        _cleanup_free_ char *options = NULL;
20✔
3263

3264
                                        r = extract_first_word(&val, &options, NULL, EXTRACT_UNQUOTE);
20✔
3265
                                        if (r < 0)
20✔
3266
                                                return -r;
×
3267

3268
                                        if (isempty(options) || streq(options, "rbind"))
43✔
3269
                                                rbind = true;
3270
                                        else if (streq(options, "norbind"))
3✔
3271
                                                rbind = false;
3272
                                        else
3273
                                                continue;
×
3274
                                }
3275
                        } else
3276
                                d = s;
3277

3278
                        r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts,
40✔
3279
                                        &(BindMount) {
20✔
3280
                                                .source = s,
3281
                                                .destination = d,
3282
                                                .read_only = false,
3283
                                                .recursive = rbind,
3284
                                                .ignore_enoent = ignore_enoent,
3285
                                        });
3286
                        if (r < 0)
20✔
3287
                                return log_oom_debug();
×
3288
                } else if ((val = startswith(l, "exec-context-temporary-filesystems="))) {
605,752✔
3289
                        _cleanup_free_ char *path = NULL, *options = NULL;
61✔
3290

3291
                        r = extract_many_words(&val, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &path, &options);
61✔
3292
                        if (r < 0)
61✔
3293
                                return r;
3294
                        if (r < 1)
61✔
3295
                                continue;
×
3296

3297
                        r = temporary_filesystem_add(&c->temporary_filesystems, &c->n_temporary_filesystems, path, options);
61✔
3298
                        if (r < 0)
61✔
3299
                                return log_oom_debug();
×
3300
                } else if ((val = startswith(l, "exec-context-utmp-id="))) {
605,691✔
3301
                        r = free_and_strdup(&c->utmp_id, val);
90✔
3302
                        if (r < 0)
90✔
3303
                                return r;
3304
                } else if ((val = startswith(l, "exec-context-utmp-mode="))) {
605,601✔
3305
                        c->utmp_mode = exec_utmp_mode_from_string(val);
10,009✔
3306
                        if (c->utmp_mode < 0)
10,009✔
3307
                                return c->utmp_mode;
3308
                } else if ((val = startswith(l, "exec-context-no-new-privileges="))) {
595,592✔
3309
                        r = parse_boolean(val);
1,402✔
3310
                        if (r < 0)
1,402✔
3311
                                return r;
3312
                        c->no_new_privileges = r;
1,402✔
3313
                } else if ((val = startswith(l, "exec-context-selinux-context="))) {
594,190✔
3314
                        if (val[0] == '-') {
×
3315
                                c->selinux_context_ignore = true;
×
3316
                                val++;
×
3317
                        } else
3318
                                c->selinux_context_ignore = false;
×
3319

3320
                        r = free_and_strdup(&c->selinux_context, val);
×
3321
                        if (r < 0)
×
3322
                                return r;
3323
                } else if ((val = startswith(l, "exec-context-apparmor-profile="))) {
594,190✔
3324
                        if (val[0] == '-') {
×
3325
                                c->apparmor_profile_ignore = true;
×
3326
                                val++;
×
3327
                        } else
3328
                                c->apparmor_profile_ignore = false;
×
3329

3330
                        r = free_and_strdup(&c->apparmor_profile, val);
×
3331
                        if (r < 0)
×
3332
                                return r;
3333
                } else if ((val = startswith(l, "exec-context-smack-process-label="))) {
594,190✔
3334
                        if (val[0] == '-') {
×
3335
                                c->smack_process_label_ignore = true;
×
3336
                                val++;
×
3337
                        } else
3338
                                c->smack_process_label_ignore = false;
×
3339

3340
                        r = free_and_strdup(&c->smack_process_label, val);
×
3341
                        if (r < 0)
×
3342
                                return r;
3343
                } else if ((val = startswith(l, "exec-context-personality="))) {
594,190✔
3344
                        c->personality = personality_from_string(val);
×
3345
                        if (c->personality == PERSONALITY_INVALID)
×
3346
                                return -EINVAL;
3347
                } else if ((val = startswith(l, "exec-context-lock-personality="))) {
594,190✔
3348
                        r = parse_boolean(val);
1,475✔
3349
                        if (r < 0)
1,475✔
3350
                                return r;
3351
                        c->lock_personality = r;
1,475✔
3352
#if HAVE_SECCOMP
3353
                } else if ((val = startswith(l, "exec-context-syscall-filter="))) {
592,715✔
3354
                        _cleanup_free_ char *s_id = NULL, *s_errno_num = NULL;
567,092✔
3355
                        int id, errno_num;
567,092✔
3356

3357
                        r = extract_many_words(&val, NULL, 0, &s_id, &s_errno_num);
567,092✔
3358
                        if (r < 0)
567,092✔
3359
                                return r;
3360
                        if (r != 2)
567,092✔
3361
                                continue;
×
3362

3363
                        r = safe_atoi(s_id, &id);
567,092✔
3364
                        if (r < 0)
567,092✔
3365
                                return r;
3366

3367
                        r = safe_atoi(s_errno_num, &errno_num);
567,092✔
3368
                        if (r < 0)
567,092✔
3369
                                return r;
3370

3371
                        r = hashmap_ensure_put(&c->syscall_filter, NULL, INT_TO_PTR(id + 1), INT_TO_PTR(errno_num));
567,092✔
3372
                        if (r < 0)
567,092✔
3373
                                return r;
3374
                } else if ((val = startswith(l, "exec-context-syscall-archs="))) {
25,623✔
3375
                        unsigned id;
1,476✔
3376

3377
                        r = safe_atou(val, &id);
1,476✔
3378
                        if (r < 0)
1,476✔
3379
                                return r;
×
3380

3381
                        r = set_ensure_put(&c->syscall_archs, NULL, UINT_TO_PTR(id + 1));
1,476✔
3382
                        if (r < 0)
1,476✔
3383
                                return r;
3384
                } else if ((val = startswith(l, "exec-context-syscall-errno="))) {
24,147✔
3385
                        r = safe_atoi(val, &c->syscall_errno);
10,009✔
3386
                        if (r < 0)
10,009✔
3387
                                return r;
3388
                } else if ((val = startswith(l, "exec-context-syscall-allow-list="))) {
14,138✔
3389
                        r = parse_boolean(val);
1,451✔
3390
                        if (r < 0)
1,451✔
3391
                                return r;
3392
                        c->syscall_allow_list = r;
1,451✔
3393
                } else if ((val = startswith(l, "exec-context-syscall-log="))) {
12,687✔
3394
                        _cleanup_free_ char *s_id = NULL, *s_errno_num = NULL;
×
3395
                        int id, errno_num;
×
3396

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

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

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

3411
                        r = hashmap_ensure_put(&c->syscall_log, NULL, INT_TO_PTR(id + 1), INT_TO_PTR(errno_num));
×
3412
                        if (r < 0)
×
3413
                                return r;
3414
                } else if ((val = startswith(l, "exec-context-syscall-log-allow-list="))) {
12,687✔
3415
                        r = parse_boolean(val);
×
3416
                        if (r < 0)
×
3417
                                return r;
3418
                        c->syscall_log_allow_list = r;
×
3419
#endif
3420
                } else if ((val = startswith(l, "exec-context-restrict-namespaces="))) {
12,687✔
3421
                        r = safe_atolu(val, &c->restrict_namespaces);
1,221✔
3422
                        if (r < 0)
1,221✔
3423
                                return r;
3424
                } else if ((val = startswith(l, "exec-context-delegate-namespaces="))) {
11,466✔
3425
                        r = safe_atolu(val, &c->delegate_namespaces);
21✔
3426
                        if (r < 0)
21✔
3427
                                return r;
3428
                } else if ((val = startswith(l, "exec-context-restrict-filesystems="))) {
11,445✔
3429
                        r = set_put_strdup(&c->restrict_filesystems, val);
×
3430
                        if (r < 0)
×
3431
                                return r;
3432
                } else if ((val = startswith(l, "exec-context-restrict-filesystems-allow-list="))) {
11,445✔
3433
                        r = parse_boolean(val);
×
3434
                        if (r < 0)
×
3435
                                return r;
3436
                        c->restrict_filesystems_allow_list = r;
×
3437
                } else if ((val = startswith(l, "exec-context-address-families="))) {
11,445✔
3438
                        int af;
5,792✔
3439

3440
                        r = safe_atoi(val, &af);
5,792✔
3441
                        if (r < 0)
5,792✔
3442
                                return r;
×
3443

3444
                        r = set_ensure_put(&c->address_families, NULL, INT_TO_PTR(af));
5,792✔
3445
                        if (r < 0)
5,792✔
3446
                                return r;
3447
                } else if ((val = startswith(l, "exec-context-address-families-allow-list="))) {
5,653✔
3448
                        r = parse_boolean(val);
1,470✔
3449
                        if (r < 0)
1,470✔
3450
                                return r;
3451
                        c->address_families_allow_list = r;
1,470✔
3452
                } else if ((val = startswith(l, "exec-context-network-namespace-path="))) {
4,183✔
3453
                        r = free_and_strdup(&c->network_namespace_path, val);
1✔
3454
                        if (r < 0)
1✔
3455
                                return r;
3456
                } else if ((val = startswith(l, "exec-context-user-namespace-path="))) {
4,182✔
3457
                        r = free_and_strdup(&c->user_namespace_path, val);
3✔
3458
                        if (r < 0)
3✔
3459
                                return r;
3460
                } else if ((val = startswith(l, "exec-context-ipc-namespace-path="))) {
4,179✔
3461
                        r = free_and_strdup(&c->ipc_namespace_path, val);
×
3462
                        if (r < 0)
×
3463
                                return r;
3464
                } else if ((val = startswith(l, "exec-context-mount-image="))) {
4,179✔
3465
                        _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
×
3466
                        _cleanup_free_ char *source = NULL, *destination = NULL;
40✔
3467
                        bool permissive = false;
40✔
3468
                        char *s;
40✔
3469

3470
                        r = extract_many_words(&val,
40✔
3471
                                               NULL,
3472
                                               EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS,
3473
                                               &source,
3474
                                               &destination);
3475
                        if (r < 0)
40✔
3476
                                return r;
3477
                        if (r == 0)
40✔
3478
                                return -EINVAL;
3479

3480
                        s = source;
40✔
3481
                        if (s[0] == '-') {
40✔
3482
                                permissive = true;
×
3483
                                s++;
×
3484
                        }
3485

3486
                        if (isempty(destination))
40✔
3487
                                continue;
×
3488

3489
                        r = deserialize_mount_options(val, &options);
40✔
3490
                        if (r < 0)
40✔
3491
                                return r;
3492

3493
                        r = mount_image_add(&c->mount_images, &c->n_mount_images,
80✔
3494
                                        &(MountImage) {
40✔
3495
                                                .source = s,
3496
                                                .destination = destination,
3497
                                                .mount_options = options,
3498
                                                .ignore_enoent = permissive,
3499
                                                .type = MOUNT_IMAGE_DISCRETE,
3500
                                        });
3501
                        if (r < 0)
40✔
3502
                                return log_oom_debug();
×
3503
                } else if ((val = startswith(l, "exec-context-extension-image="))) {
4,139✔
3504
                        _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
×
3505
                        _cleanup_free_ char *source = NULL;
14✔
3506
                        bool permissive = false;
14✔
3507
                        char *s;
14✔
3508

3509
                        r = extract_first_word(&val,
14✔
3510
                                               &source,
3511
                                               NULL,
3512
                                               EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS);
3513
                        if (r < 0)
14✔
3514
                                return r;
3515
                        if (r == 0)
14✔
3516
                                return -EINVAL;
3517

3518
                        s = source;
14✔
3519
                        if (s[0] == '-') {
14✔
3520
                                permissive = true;
3✔
3521
                                s++;
3✔
3522
                        }
3523

3524
                        r = deserialize_mount_options(val, &options);
14✔
3525
                        if (r < 0)
14✔
3526
                                return r;
3527

3528
                        r = mount_image_add(&c->extension_images, &c->n_extension_images,
28✔
3529
                                        &(MountImage) {
14✔
3530
                                                .source = s,
3531
                                                .mount_options = options,
3532
                                                .ignore_enoent = permissive,
3533
                                                .type = MOUNT_IMAGE_EXTENSION,
3534
                                        });
3535
                        if (r < 0)
14✔
3536
                                return log_oom_debug();
×
3537
                } else if ((val = startswith(l, "exec-context-extension-directories="))) {
4,125✔
3538
                        r = deserialize_strv(val, &c->extension_directories);
8✔
3539
                        if (r < 0)
8✔
3540
                                return r;
3541
                } else if ((val = startswith(l, "exec-context-set-credentials="))) {
4,117✔
3542
                        _cleanup_free_ char *id = NULL, *data = NULL, *encrypted = NULL;
×
3543

3544
                        r = extract_many_words(&val, " ", EXTRACT_DONT_COALESCE_SEPARATORS, &id, &data, &encrypted);
93✔
3545
                        if (r < 0)
93✔
3546
                                return r;
3547
                        if (r != 3)
93✔
3548
                                return -EINVAL;
3549

3550
                        r = parse_boolean(encrypted);
93✔
3551
                        if (r < 0)
93✔
3552
                                return r;
3553
                        bool e = r;
93✔
3554

3555
                        _cleanup_free_ void *d = NULL;
93✔
3556
                        size_t size;
93✔
3557

3558
                        r = unbase64mem_full(data, SIZE_MAX, /* secure= */ true, &d, &size);
93✔
3559
                        if (r < 0)
93✔
3560
                                return r;
3561

3562
                        r = exec_context_put_set_credential(c, id, TAKE_PTR(d), size, e);
93✔
3563
                        if (r < 0)
93✔
3564
                                return r;
3565
                } else if ((val = startswith(l, "exec-context-load-credentials="))) {
4,024✔
3566
                        _cleanup_free_ char *id = NULL, *path = NULL, *encrypted = NULL;
34✔
3567

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

3574
                        r = parse_boolean(encrypted);
34✔
3575
                        if (r < 0)
34✔
3576
                                return r;
3577

3578
                        r = exec_context_put_load_credential(c, id, path, r > 0);
34✔
3579
                        if (r < 0)
34✔
3580
                                return r;
3581
                } else if ((val = startswith(l, "exec-context-import-credentials="))) {
3,990✔
3582
                        _cleanup_free_ char *glob = NULL, *rename = NULL;
3,984✔
3583

3584
                        r = extract_many_words(&val, " ", EXTRACT_DONT_COALESCE_SEPARATORS, &glob, &rename);
3,984✔
3585
                        if (r < 0)
3,984✔
3586
                                return r;
3587
                        if (r == 0)
3,984✔
3588
                                return -EINVAL;
3589

3590
                        r = exec_context_put_import_credential(c, glob, rename);
3,984✔
3591
                        if (r < 0)
3,984✔
3592
                                return r;
3593
                } else if ((val = startswith(l, "exec-context-root-image-policy="))) {
6✔
3594
                        if (c->root_image_policy)
4✔
3595
                                return -EINVAL; /* duplicated */
3596

3597
                        r = image_policy_from_string(val, /* graceful= */ false, &c->root_image_policy);
4✔
3598
                        if (r < 0)
4✔
3599
                                return r;
3600
                } else if ((val = startswith(l, "exec-context-mount-image-policy="))) {
2✔
3601
                        if (c->mount_image_policy)
×
3602
                                return -EINVAL; /* duplicated */
3603

3604
                        r = image_policy_from_string(val, /* graceful= */ false, &c->mount_image_policy);
×
3605
                        if (r < 0)
×
3606
                                return r;
3607
                } else if ((val = startswith(l, "exec-context-extension-image-policy="))) {
2✔
3608
                        if (c->extension_image_policy)
2✔
3609
                                return -EINVAL; /* duplicated */
3610

3611
                        r = image_policy_from_string(val, /* graceful= */ false, &c->extension_image_policy);
2✔
3612
                        if (r < 0)
2✔
3613
                                return r;
3614
                } else
3615
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
3616
        }
3617

3618
        return 0;
10,009✔
3619
}
3620

3621
static int exec_command_serialize(const ExecCommand *c, FILE *f) {
2,461✔
3622
        int r;
2,461✔
3623

3624
        assert(c);
2,461✔
3625
        assert(f);
2,461✔
3626

3627
        r = serialize_item(f, "exec-command-path", c->path);
2,461✔
3628
        if (r < 0)
2,461✔
3629
                return r;
3630

3631
        r = serialize_strv(f, "exec-command-argv", c->argv);
2,461✔
3632
        if (r < 0)
2,461✔
3633
                return r;
3634

3635
        r = serialize_item_format(f, "exec-command-flags", "%d", (int) c->flags);
2,461✔
3636
        if (r < 0)
2,461✔
3637
                return r;
3638

3639
        fputc('\n', f); /* End marker */
2,461✔
3640

3641
        return 0;
2,461✔
3642
}
3643

3644
static int exec_command_deserialize(ExecCommand *c, FILE *f) {
10,009✔
3645
        int r;
10,009✔
3646

3647
        assert(c);
10,009✔
3648
        assert(f);
10,009✔
3649

3650
        for (;;) {
108,403✔
3651
                _cleanup_free_ char *l = NULL;
49,197✔
3652
                const char *val;
59,206✔
3653

3654
                r = deserialize_read_line(f, &l);
59,206✔
3655
                if (r < 0)
59,206✔
3656
                        return r;
3657
                if (r == 0) /* eof or end marker */
59,206✔
3658
                        break;
3659

3660
                if ((val = startswith(l, "exec-command-path="))) {
49,197✔
3661
                        r = free_and_strdup(&c->path, val);
10,009✔
3662
                        if (r < 0)
10,009✔
3663
                                return r;
3664
                } else if ((val = startswith(l, "exec-command-argv="))) {
39,188✔
3665
                        r = deserialize_strv(val, &c->argv);
29,179✔
3666
                        if (r < 0)
29,179✔
3667
                                return r;
3668
                } else if ((val = startswith(l, "exec-command-flags="))) {
10,009✔
3669
                        r = safe_atoi(val, &c->flags);
10,009✔
3670
                        if (r < 0)
10,009✔
3671
                                return r;
3672
                } else
3673
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
3674

3675
        }
3676

3677
        return 0;
10,009✔
3678
}
3679

3680
int exec_serialize_invocation(
2,461✔
3681
                FILE *f,
3682
                FDSet *fds,
3683
                const ExecContext *ctx,
3684
                const ExecCommand *cmd,
3685
                const ExecParameters *p,
3686
                const ExecRuntime *rt,
3687
                const CGroupContext *cg) {
3688

3689
        int r;
2,461✔
3690

3691
        assert(f);
2,461✔
3692
        assert(fds);
2,461✔
3693

3694
        r = exec_context_serialize(ctx, f);
2,461✔
3695
        if (r < 0)
2,461✔
3696
                return log_debug_errno(r, "Failed to serialize context: %m");
×
3697

3698
        r = exec_command_serialize(cmd, f);
2,461✔
3699
        if (r < 0)
2,461✔
3700
                return log_debug_errno(r, "Failed to serialize command: %m");
×
3701

3702
        r = exec_parameters_serialize(p, ctx, f, fds);
2,461✔
3703
        if (r < 0)
2,461✔
3704
                return log_debug_errno(r, "Failed to serialize parameters: %m");
×
3705

3706
        r = exec_runtime_serialize(rt, f, fds);
2,461✔
3707
        if (r < 0)
2,461✔
3708
                return log_debug_errno(r, "Failed to serialize runtime: %m");
×
3709

3710
        r = exec_cgroup_context_serialize(cg, f);
2,461✔
3711
        if (r < 0)
2,461✔
3712
                return log_debug_errno(r, "Failed to serialize cgroup context: %m");
×
3713

3714
        return 0;
3715
}
3716

3717
int exec_deserialize_invocation(
10,009✔
3718
                FILE *f,
3719
                FDSet *fds,
3720
                ExecContext *ctx,
3721
                ExecCommand *cmd,
3722
                ExecParameters *p,
3723
                ExecRuntime *rt,
3724
                CGroupContext *cg) {
3725

3726
        int r;
10,009✔
3727

3728
        assert(f);
10,009✔
3729
        assert(fds);
10,009✔
3730

3731
        r = exec_context_deserialize(ctx, f);
10,009✔
3732
        if (r < 0)
10,009✔
3733
                return log_debug_errno(r, "Failed to deserialize context: %m");
×
3734

3735
        r = exec_command_deserialize(cmd, f);
10,009✔
3736
        if (r < 0)
10,009✔
3737
                return log_debug_errno(r, "Failed to deserialize command: %m");
×
3738

3739
        r = exec_parameters_deserialize(p, f, fds);
10,009✔
3740
        if (r < 0)
10,009✔
3741
                return log_debug_errno(r, "Failed to deserialize parameters: %m");
×
3742

3743
        r = exec_runtime_deserialize(rt, f, fds);
10,009✔
3744
        if (r < 0)
10,009✔
3745
                return log_debug_errno(r, "Failed to deserialize runtime: %m");
×
3746

3747
        r = exec_cgroup_context_deserialize(cg, f);
10,009✔
3748
        if (r < 0)
10,009✔
3749
                return log_debug_errno(r, "Failed to deserialize cgroup context: %m");
×
3750

3751
        return 0;
3752
}
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