summaryrefslogtreecommitdiff
path: root/src/core/unit.c
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2023-03-09 15:10:23 +0100
committerDaan De Meyer <daan.j.demeyer@gmail.com>2023-03-27 14:46:57 +0200
commit28135da3cdca53157bd878ae00b15d6e33ca4987 (patch)
tree6b88da16d427d0f0ccbda3b7a1153473a69d9e80 /src/core/unit.c
parente52a696a9af9e46e6e2be799a344bd9fb34dd3f4 (diff)
downloadsystemd-28135da3cdca53157bd878ae00b15d6e33ca4987.tar.gz
core: Introduce unit private exec runtime
Currently, exec runtimes can be shared between units (using JoinsNamespaceOf=). Let's introduce a concept of a private exec runtime that isn't shared with JoinsNamespaceOf=. The existing ExecRuntime struct is renamed to ExecRuntimeShared and becomes a private member of the new private ExecRuntime.
Diffstat (limited to 'src/core/unit.c')
-rw-r--r--src/core/unit.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/core/unit.c b/src/core/unit.c
index 25e2509f51..e569a82e1c 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -4268,7 +4268,7 @@ CGroupContext *unit_get_cgroup_context(Unit *u) {
return (CGroupContext*) ((uint8_t*) u + offset);
}
-ExecSharedRuntime *unit_get_exec_runtime(Unit *u) {
+ExecRuntime *unit_get_exec_runtime(Unit *u) {
size_t offset;
if (u->type < 0)
@@ -4278,7 +4278,7 @@ ExecSharedRuntime *unit_get_exec_runtime(Unit *u) {
if (offset <= 0)
return NULL;
- return *(ExecSharedRuntime**) ((uint8_t*) u + offset);
+ return *(ExecRuntime**) ((uint8_t*) u + offset);
}
static const char* unit_drop_in_dir(Unit *u, UnitWriteFlags flags) {
@@ -4791,7 +4791,8 @@ int unit_require_mounts_for(Unit *u, const char *path, UnitDependencyMask mask)
}
int unit_setup_exec_runtime(Unit *u) {
- ExecSharedRuntime **rt;
+ _cleanup_(exec_shared_runtime_unrefp) ExecSharedRuntime *esr = NULL;
+ ExecRuntime **rt;
size_t offset;
Unit *other;
int r;
@@ -4799,19 +4800,33 @@ int unit_setup_exec_runtime(Unit *u) {
offset = UNIT_VTABLE(u)->exec_runtime_offset;
assert(offset > 0);
- /* Check if there already is an ExecSharedRuntime for this unit? */
- rt = (ExecSharedRuntime**) ((uint8_t*) u + offset);
+ /* Check if there already is an ExecRuntime for this unit? */
+ rt = (ExecRuntime**) ((uint8_t*) u + offset);
if (*rt)
return 0;
/* Try to get it from somebody else */
UNIT_FOREACH_DEPENDENCY(other, u, UNIT_ATOM_JOINS_NAMESPACE_OF) {
- r = exec_shared_runtime_acquire(u->manager, NULL, other->id, false, rt);
- if (r == 1)
- return 1;
+ r = exec_shared_runtime_acquire(u->manager, NULL, other->id, false, &esr);
+ if (r < 0)
+ return r;
+ if (r > 0)
+ break;
+ }
+
+ if (!esr) {
+ r = exec_shared_runtime_acquire(u->manager, unit_get_exec_context(u), u->id, true, &esr);
+ if (r < 0)
+ return r;
}
- return exec_shared_runtime_acquire(u->manager, unit_get_exec_context(u), u->id, true, rt);
+ r = exec_runtime_make(esr, rt);
+ if (r < 0)
+ return r;
+
+ TAKE_PTR(esr);
+
+ return r;
}
int unit_setup_dynamic_creds(Unit *u) {