1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-11 09:18:07 +03:00

core: add serialization/deserialization for ExecContext

This commit is contained in:
Luca Boccassi 2023-09-01 00:31:26 +01:00
parent c3166b25e2
commit 5699a1689b
6 changed files with 2169 additions and 9 deletions

2141
src/core/execute-serialize.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,15 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include "execute.h"
/* These functions serialize/deserialize for invocation purposes (i.e.: serialized object is passed to a
* child process) rather than to save state across reload/reexec. */
int exec_serialize_invocation(FILE *f,
FDSet *fds,
const ExecContext *ctx);
int exec_deserialize_invocation(FILE *f,
FDSet *fds,
ExecContext *ctx);

View File

@ -183,7 +183,7 @@ int manager_serialize(
if (u->id != t)
continue;
r = unit_serialize(u, f, fds, switching_root);
r = unit_serialize_state(u, f, fds, switching_root);
if (r < 0)
return r;
}
@ -210,7 +210,7 @@ static int manager_deserialize_one_unit(Manager *m, const char *name, FILE *f, F
return log_notice_errno(r, "Failed to load unit \"%s\", skipping deserialization: %m", name);
}
r = unit_deserialize(u, f, fds);
r = unit_deserialize_state(u, f, fds);
if (r < 0) {
if (r == -ENOMEM)
return r;
@ -239,7 +239,7 @@ static int manager_deserialize_units(Manager *m, FILE *f, FDSet *fds) {
if (r == -ENOMEM)
return r;
if (r < 0) {
r = unit_deserialize_skip(f);
r = unit_deserialize_state_skip(f);
if (r < 0)
return r;
}

View File

@ -36,6 +36,7 @@ libcore_sources = files(
'emergency-action.c',
'exec-credential.c',
'execute.c',
'execute-serialize.c',
'generator-setup.c',
'ima-setup.c',
'import-creds.c',

View File

@ -90,7 +90,7 @@ static const char *const io_accounting_metric_field_last[_CGROUP_IO_ACCOUNTING_M
[CGROUP_IO_WRITE_OPERATIONS] = "io-accounting-write-operations-last",
};
int unit_serialize(Unit *u, FILE *f, FDSet *fds, bool switching_root) {
int unit_serialize_state(Unit *u, FILE *f, FDSet *fds, bool switching_root) {
int r;
assert(u);
@ -264,7 +264,7 @@ static int unit_deserialize_job(Unit *u, FILE *f) {
_deserialize_matched; \
})
int unit_deserialize(Unit *u, FILE *f, FDSet *fds) {
int unit_deserialize_state(Unit *u, FILE *f, FDSet *fds) {
int r;
assert(u);
@ -552,7 +552,7 @@ int unit_deserialize(Unit *u, FILE *f, FDSet *fds) {
return 0;
}
int unit_deserialize_skip(FILE *f) {
int unit_deserialize_state_skip(FILE *f) {
int r;
assert(f);

View File

@ -6,8 +6,11 @@
#include "unit.h"
#include "fdset.h"
int unit_serialize(Unit *u, FILE *f, FDSet *fds, bool serialize_jobs);
int unit_deserialize(Unit *u, FILE *f, FDSet *fds);
int unit_deserialize_skip(FILE *f);
/* These functions serialize state for our own usage, i.e.: across a reload/reexec, rather than for being
* passed to a child process. */
int unit_serialize_state(Unit *u, FILE *f, FDSet *fds, bool serialize_jobs);
int unit_deserialize_state(Unit *u, FILE *f, FDSet *fds);
int unit_deserialize_state_skip(FILE *f);
void unit_dump(Unit *u, FILE *f, const char *prefix);