summaryrefslogtreecommitdiff
path: root/src/unit.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-07-21 05:00:29 +0200
committerLennart Poettering <lennart@poettering.net>2010-07-21 05:00:29 +0200
commita7f241db3f1ae96ab2708092e1b31d2feb989947 (patch)
treed48588845b8d22658eb7a46bee49d58ec528716d /src/unit.c
parent672c48cc065251ddbdc3926221e8a7718241cccd (diff)
unit: deduce following unit value dynamically instead of statically, to avoid dangling pointers
Diffstat (limited to 'src/unit.c')
-rw-r--r--src/unit.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/unit.c b/src/unit.c
index 50f3b8fabd..840c1d1fc4 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -589,6 +589,7 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) {
timestamp3[FORMAT_TIMESTAMP_MAX],
timestamp4[FORMAT_TIMESTAMP_MAX],
timespan[FORMAT_TIMESPAN_MAX];
+ Unit *following;
assert(u);
assert(u->meta.type >= 0);
@@ -625,8 +626,8 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) {
SET_FOREACH(t, u->meta.names, i)
fprintf(f, "%s\tName: %s\n", prefix, t);
- if (u->meta.following)
- fprintf(f, "%s\tFollowing: %s\n", prefix, u->meta.following->meta.id);
+ if ((following = unit_following(u)))
+ fprintf(f, "%s\tFollowing: %s\n", prefix, following->meta.id);
if (u->meta.fragment_path)
fprintf(f, "%s\tFragment Path: %s\n", prefix, u->meta.fragment_path);
@@ -2081,6 +2082,15 @@ void unit_reset_maintenance(Unit *u) {
UNIT_VTABLE(u)->reset_maintenance(u);
}
+Unit *unit_following(Unit *u) {
+ assert(u);
+
+ if (UNIT_VTABLE(u)->following)
+ return UNIT_VTABLE(u)->following(u);
+
+ return NULL;
+}
+
static const char* const unit_type_table[_UNIT_TYPE_MAX] = {
[UNIT_SERVICE] = "service",
[UNIT_TIMER] = "timer",