|
|
9ab0c5 |
From c6da3d5d824f7b125b3fd95a961eca98db7febf7 Mon Sep 17 00:00:00 2001
|
|
|
9ab0c5 |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
|
9ab0c5 |
Date: Tue, 13 Feb 2018 13:12:43 +0100
|
|
|
9ab0c5 |
Subject: [PATCH] pid1: include the source unit in UnitRef
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
No functional change.
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
The source unit manages the reference. It allocates the UnitRef structure and
|
|
|
9ab0c5 |
registers it in the target unit, and then the reference must be destroyed
|
|
|
9ab0c5 |
before the source unit is destroyed. Thus, is should be OK to include the
|
|
|
9ab0c5 |
pointer to the source unit, it should be live as long as the reference exists.
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
v2:
|
|
|
9ab0c5 |
- rename refs to refs_by_target
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
(cherry picked from commit 7f7d01ed5804afef220ebdb29f22d8177d0d3a5c)
|
|
|
9ab0c5 |
(cherry picked from commit ff80bfd94181327a5f8e0fbd70b9b7afe0c5545c)
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
Related: #1729228
|
|
|
9ab0c5 |
---
|
|
|
9ab0c5 |
src/core/busname.c | 2 +-
|
|
|
9ab0c5 |
src/core/dbus-manager.c | 2 +-
|
|
|
9ab0c5 |
src/core/dbus-unit.c | 2 +-
|
|
|
9ab0c5 |
src/core/load-fragment.c | 6 +++---
|
|
|
9ab0c5 |
src/core/service.c | 2 +-
|
|
|
9ab0c5 |
src/core/slice.c | 2 +-
|
|
|
9ab0c5 |
src/core/socket.c | 4 ++--
|
|
|
9ab0c5 |
src/core/unit.c | 35 ++++++++++++++++++-----------------
|
|
|
9ab0c5 |
src/core/unit.h | 12 ++++++------
|
|
|
9ab0c5 |
9 files changed, 34 insertions(+), 33 deletions(-)
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
diff --git a/src/core/busname.c b/src/core/busname.c
|
|
|
9ab0c5 |
index a5e659049d..97886f1e05 100644
|
|
|
9ab0c5 |
--- a/src/core/busname.c
|
|
|
9ab0c5 |
+++ b/src/core/busname.c
|
|
|
9ab0c5 |
@@ -175,7 +175,7 @@ static int busname_add_extras(BusName *n) {
|
|
|
9ab0c5 |
if (r < 0)
|
|
|
9ab0c5 |
return r;
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
- unit_ref_set(&n->service, x);
|
|
|
9ab0c5 |
+ unit_ref_set(&n->service, u, x);
|
|
|
9ab0c5 |
}
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
r = unit_add_two_dependencies(u, UNIT_BEFORE, UNIT_TRIGGERS, UNIT_DEREF(n->service), true);
|
|
|
9ab0c5 |
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
|
|
|
9ab0c5 |
index 1766163b33..8267d44e1a 100644
|
|
|
9ab0c5 |
--- a/src/core/dbus-manager.c
|
|
|
9ab0c5 |
+++ b/src/core/dbus-manager.c
|
|
|
9ab0c5 |
@@ -649,7 +649,7 @@ static int transient_unit_from_message(
|
|
|
9ab0c5 |
u->fragment_path ||
|
|
|
9ab0c5 |
u->source_path ||
|
|
|
9ab0c5 |
!strv_isempty(u->dropin_paths) ||
|
|
|
9ab0c5 |
- u->refs ||
|
|
|
9ab0c5 |
+ u->refs_by_target ||
|
|
|
9ab0c5 |
set_size(u->dependencies[UNIT_REFERENCED_BY]) > 0)
|
|
|
9ab0c5 |
return sd_bus_error_setf(error, BUS_ERROR_UNIT_EXISTS, "Unit %s already exists.", name);
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c
|
|
|
9ab0c5 |
index f0f75e01b0..77073308c8 100644
|
|
|
9ab0c5 |
--- a/src/core/dbus-unit.c
|
|
|
9ab0c5 |
+++ b/src/core/dbus-unit.c
|
|
|
9ab0c5 |
@@ -967,7 +967,7 @@ static int bus_unit_set_transient_property(
|
|
|
9ab0c5 |
return -EINVAL;
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
if (mode != UNIT_CHECK) {
|
|
|
9ab0c5 |
- unit_ref_set(&u->slice, slice);
|
|
|
9ab0c5 |
+ unit_ref_set(&u->slice, u, slice);
|
|
|
9ab0c5 |
unit_write_drop_in_private_format(u, mode, name, "Slice=%s\n", s);
|
|
|
9ab0c5 |
}
|
|
|
9ab0c5 |
}
|
|
|
9ab0c5 |
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
|
|
|
9ab0c5 |
index f3d0851fe2..1721fea8f3 100644
|
|
|
9ab0c5 |
--- a/src/core/load-fragment.c
|
|
|
9ab0c5 |
+++ b/src/core/load-fragment.c
|
|
|
9ab0c5 |
@@ -1836,7 +1836,7 @@ int config_parse_socket_service(
|
|
|
9ab0c5 |
return 0;
|
|
|
9ab0c5 |
}
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
- unit_ref_set(&s->service, x);
|
|
|
9ab0c5 |
+ unit_ref_set(&s->service, UNIT(s), x);
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
return 0;
|
|
|
9ab0c5 |
}
|
|
|
9ab0c5 |
@@ -2006,7 +2006,7 @@ int config_parse_busname_service(
|
|
|
9ab0c5 |
return 0;
|
|
|
9ab0c5 |
}
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
- unit_ref_set(&n->service, x);
|
|
|
9ab0c5 |
+ unit_ref_set(&n->service, UNIT(n), x);
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
return 0;
|
|
|
9ab0c5 |
}
|
|
|
9ab0c5 |
@@ -2933,7 +2933,7 @@ int config_parse_unit_slice(
|
|
|
9ab0c5 |
return 0;
|
|
|
9ab0c5 |
}
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
- unit_ref_set(&u->slice, slice);
|
|
|
9ab0c5 |
+ unit_ref_set(&u->slice, u, slice);
|
|
|
9ab0c5 |
return 0;
|
|
|
9ab0c5 |
}
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
diff --git a/src/core/service.c b/src/core/service.c
|
|
|
9ab0c5 |
index 69ec916f2d..eaa588863f 100644
|
|
|
9ab0c5 |
--- a/src/core/service.c
|
|
|
9ab0c5 |
+++ b/src/core/service.c
|
|
|
9ab0c5 |
@@ -3299,7 +3299,7 @@ int service_set_socket_fd(Service *s, int fd, Socket *sock, bool selinux_context
|
|
|
9ab0c5 |
s->socket_fd = fd;
|
|
|
9ab0c5 |
s->socket_fd_selinux_context_net = selinux_context_net;
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
- unit_ref_set(&s->accept_socket, UNIT(sock));
|
|
|
9ab0c5 |
+ unit_ref_set(&s->accept_socket, UNIT(s), UNIT(sock));
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
return unit_add_two_dependencies(UNIT(sock), UNIT_BEFORE, UNIT_TRIGGERS, UNIT(s), false);
|
|
|
9ab0c5 |
}
|
|
|
9ab0c5 |
diff --git a/src/core/slice.c b/src/core/slice.c
|
|
|
9ab0c5 |
index 1cce3e1217..0985a65286 100644
|
|
|
9ab0c5 |
--- a/src/core/slice.c
|
|
|
9ab0c5 |
+++ b/src/core/slice.c
|
|
|
9ab0c5 |
@@ -76,7 +76,7 @@ static int slice_add_parent_slice(Slice *s) {
|
|
|
9ab0c5 |
if (r < 0)
|
|
|
9ab0c5 |
return r;
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
- unit_ref_set(&UNIT(s)->slice, parent);
|
|
|
9ab0c5 |
+ unit_ref_set(&UNIT(s)->slice, UNIT(s), parent);
|
|
|
9ab0c5 |
return 0;
|
|
|
9ab0c5 |
}
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
diff --git a/src/core/socket.c b/src/core/socket.c
|
|
|
9ab0c5 |
index 3e4cdd467f..8489575de6 100644
|
|
|
9ab0c5 |
--- a/src/core/socket.c
|
|
|
9ab0c5 |
+++ b/src/core/socket.c
|
|
|
9ab0c5 |
@@ -208,7 +208,7 @@ int socket_instantiate_service(Socket *s) {
|
|
|
9ab0c5 |
return r;
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
u->no_gc = true;
|
|
|
9ab0c5 |
- unit_ref_set(&s->service, u);
|
|
|
9ab0c5 |
+ unit_ref_set(&s->service, UNIT(s), u);
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
return unit_add_two_dependencies(UNIT(s), UNIT_BEFORE, UNIT_TRIGGERS, u, false);
|
|
|
9ab0c5 |
}
|
|
|
9ab0c5 |
@@ -313,7 +313,7 @@ static int socket_add_extras(Socket *s) {
|
|
|
9ab0c5 |
if (r < 0)
|
|
|
9ab0c5 |
return r;
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
- unit_ref_set(&s->service, x);
|
|
|
9ab0c5 |
+ unit_ref_set(&s->service, u, x);
|
|
|
9ab0c5 |
}
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
r = unit_add_two_dependencies(u, UNIT_BEFORE, UNIT_TRIGGERS, UNIT_DEREF(s->service), true);
|
|
|
9ab0c5 |
diff --git a/src/core/unit.c b/src/core/unit.c
|
|
|
9ab0c5 |
index 1b8ec9a20e..5376ef862f 100644
|
|
|
9ab0c5 |
--- a/src/core/unit.c
|
|
|
9ab0c5 |
+++ b/src/core/unit.c
|
|
|
9ab0c5 |
@@ -315,7 +315,7 @@ bool unit_may_gc(Unit *u) {
|
|
|
9ab0c5 |
if (u->no_gc)
|
|
|
9ab0c5 |
return false;
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
- if (u->refs)
|
|
|
9ab0c5 |
+ if (u->refs_by_target)
|
|
|
9ab0c5 |
return false;
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
if (UNIT_VTABLE(u)->may_gc && !UNIT_VTABLE(u)->may_gc(u))
|
|
|
9ab0c5 |
@@ -553,9 +553,8 @@ void unit_free(Unit *u) {
|
|
|
9ab0c5 |
condition_free_list(u->asserts);
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
unit_ref_unset(&u->slice);
|
|
|
9ab0c5 |
-
|
|
|
9ab0c5 |
- while (u->refs)
|
|
|
9ab0c5 |
- unit_ref_unset(u->refs);
|
|
|
9ab0c5 |
+ while (u->refs_by_target)
|
|
|
9ab0c5 |
+ unit_ref_unset(u->refs_by_target);
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
free(u);
|
|
|
9ab0c5 |
}
|
|
|
9ab0c5 |
@@ -737,8 +736,8 @@ int unit_merge(Unit *u, Unit *other) {
|
|
|
9ab0c5 |
return r;
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
/* Redirect all references */
|
|
|
9ab0c5 |
- while (other->refs)
|
|
|
9ab0c5 |
- unit_ref_set(other->refs, u);
|
|
|
9ab0c5 |
+ while (other->refs_by_target)
|
|
|
9ab0c5 |
+ unit_ref_set(other->refs_by_target, other->refs_by_target->source, u);
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
/* Merge dependencies */
|
|
|
9ab0c5 |
for (d = 0; d < _UNIT_DEPENDENCY_MAX; d++)
|
|
|
9ab0c5 |
@@ -2493,7 +2492,7 @@ int unit_add_default_slice(Unit *u, CGroupContext *c) {
|
|
|
9ab0c5 |
if (r < 0)
|
|
|
9ab0c5 |
return r;
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
- unit_ref_set(&u->slice, slice);
|
|
|
9ab0c5 |
+ unit_ref_set(&u->slice, u, slice);
|
|
|
9ab0c5 |
return 0;
|
|
|
9ab0c5 |
}
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
@@ -3130,30 +3129,32 @@ int unit_get_unit_file_preset(Unit *u) {
|
|
|
9ab0c5 |
return u->unit_file_preset;
|
|
|
9ab0c5 |
}
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
-Unit* unit_ref_set(UnitRef *ref, Unit *u) {
|
|
|
9ab0c5 |
+Unit* unit_ref_set(UnitRef *ref, Unit *source, Unit *target) {
|
|
|
9ab0c5 |
assert(ref);
|
|
|
9ab0c5 |
- assert(u);
|
|
|
9ab0c5 |
+ assert(source);
|
|
|
9ab0c5 |
+ assert(target);
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
- if (ref->unit)
|
|
|
9ab0c5 |
+ if (ref->target)
|
|
|
9ab0c5 |
unit_ref_unset(ref);
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
- ref->unit = u;
|
|
|
9ab0c5 |
- LIST_PREPEND(refs, u->refs, ref);
|
|
|
9ab0c5 |
- return u;
|
|
|
9ab0c5 |
+ ref->source = source;
|
|
|
9ab0c5 |
+ ref->target = target;
|
|
|
9ab0c5 |
+ LIST_PREPEND(refs_by_target, target->refs_by_target, ref);
|
|
|
9ab0c5 |
+ return target;
|
|
|
9ab0c5 |
}
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
void unit_ref_unset(UnitRef *ref) {
|
|
|
9ab0c5 |
assert(ref);
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
- if (!ref->unit)
|
|
|
9ab0c5 |
+ if (!ref->target)
|
|
|
9ab0c5 |
return;
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
/* We are about to drop a reference to the unit, make sure the garbage collection has a look at it as it might
|
|
|
9ab0c5 |
* be unreferenced now. */
|
|
|
9ab0c5 |
- unit_add_to_gc_queue(ref->unit);
|
|
|
9ab0c5 |
+ unit_add_to_gc_queue(ref->target);
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
- LIST_REMOVE(refs, ref->unit->refs, ref);
|
|
|
9ab0c5 |
- ref->unit = NULL;
|
|
|
9ab0c5 |
+ LIST_REMOVE(refs_by_target, ref->target->refs_by_target, ref);
|
|
|
9ab0c5 |
+ ref->source = ref->target = NULL;
|
|
|
9ab0c5 |
}
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
int unit_patch_contexts(Unit *u) {
|
|
|
9ab0c5 |
diff --git a/src/core/unit.h b/src/core/unit.h
|
|
|
9ab0c5 |
index 3f411a1793..a6e21d60ce 100644
|
|
|
9ab0c5 |
--- a/src/core/unit.h
|
|
|
9ab0c5 |
+++ b/src/core/unit.h
|
|
|
9ab0c5 |
@@ -84,8 +84,8 @@ struct UnitRef {
|
|
|
9ab0c5 |
* that we can merge two units if necessary and correct all
|
|
|
9ab0c5 |
* references to them */
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
- Unit* unit;
|
|
|
9ab0c5 |
- LIST_FIELDS(UnitRef, refs);
|
|
|
9ab0c5 |
+ Unit *source, *target;
|
|
|
9ab0c5 |
+ LIST_FIELDS(UnitRef, refs_by_target);
|
|
|
9ab0c5 |
};
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
struct Unit {
|
|
|
9ab0c5 |
@@ -125,7 +125,7 @@ struct Unit {
|
|
|
9ab0c5 |
char *job_timeout_reboot_arg;
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
/* References to this */
|
|
|
9ab0c5 |
- LIST_HEAD(UnitRef, refs);
|
|
|
9ab0c5 |
+ LIST_HEAD(UnitRef, refs_by_target);
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
/* Conditions to check */
|
|
|
9ab0c5 |
LIST_HEAD(Condition, conditions);
|
|
|
9ab0c5 |
@@ -591,11 +591,11 @@ void unit_trigger_notify(Unit *u);
|
|
|
9ab0c5 |
UnitFileState unit_get_unit_file_state(Unit *u);
|
|
|
9ab0c5 |
int unit_get_unit_file_preset(Unit *u);
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
-Unit* unit_ref_set(UnitRef *ref, Unit *u);
|
|
|
9ab0c5 |
+Unit* unit_ref_set(UnitRef *ref, Unit *source, Unit *target);
|
|
|
9ab0c5 |
void unit_ref_unset(UnitRef *ref);
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
-#define UNIT_DEREF(ref) ((ref).unit)
|
|
|
9ab0c5 |
-#define UNIT_ISSET(ref) (!!(ref).unit)
|
|
|
9ab0c5 |
+#define UNIT_DEREF(ref) ((ref).target)
|
|
|
9ab0c5 |
+#define UNIT_ISSET(ref) (!!(ref).target)
|
|
|
9ab0c5 |
|
|
|
9ab0c5 |
int unit_patch_contexts(Unit *u);
|
|
|
9ab0c5 |
|