]> err.no Git - systemd/commitdiff
unit: introduce unit_load_related_unit()
authorLennart Poettering <lennart@poettering.net>
Sat, 10 Apr 2010 02:48:33 +0000 (04:48 +0200)
committerLennart Poettering <lennart@poettering.net>
Sat, 10 Apr 2010 16:00:20 +0000 (18:00 +0200)
unit.c
unit.h

diff --git a/unit.c b/unit.c
index a8058500d1411070e0f20bef675b279b9ae263f8..6d6f56416d1bfb0c6976230546e3ef6855ba9c2f 100644 (file)
--- a/unit.c
+++ b/unit.c
@@ -1440,6 +1440,28 @@ CGroupBonding* unit_get_default_cgroup(Unit *u) {
         return cgroup_bonding_find_list(u->meta.cgroup_bondings, u->meta.manager->cgroup_controller);
 }
 
+int unit_load_related_unit(Unit *u, const char *type, Unit **_found) {
+        char *t;
+        int r;
+
+        assert(u);
+        assert(type);
+        assert(_found);
+
+        if (!(t = unit_name_change_suffix(unit_id(u), type)))
+                return -ENOMEM;
+
+        assert(!unit_has_name(u, t));
+
+        r = manager_load_unit(u->meta.manager, t, _found);
+        free(t);
+
+        if (r >= 0)
+                assert(*_found != u);
+
+        return r;
+}
+
 static const char* const unit_type_table[_UNIT_TYPE_MAX] = {
         [UNIT_SERVICE] = "service",
         [UNIT_TIMER] = "timer",
diff --git a/unit.h b/unit.h
index 9def661ce1f07fcb9120dc9a3d46f83ec80cabd5..bfd0907fc306da41de2bb23f26b63f60d23649e2 100644 (file)
--- a/unit.h
+++ b/unit.h
@@ -324,6 +324,8 @@ char *unit_name_escape_path(const char *path, const char *suffix);
 
 char *unit_dbus_path(Unit *u);
 
+int unit_load_related_unit(Unit *u, const char *type, Unit **_found);
+
 const char *unit_type_to_string(UnitType i);
 UnitType unit_type_from_string(const char *s);